Skip to content

Force newlines for method arguments #7024

Answered by samsonasik
ruudk asked this question in Q&A
Discussion options

You must be logged in to vote

@ruudk you can create custom rector rule like this:

<?php

declare(strict_types=1);

namespace Utils\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

class NewLineFirstParamRector extends AbstractRector
{
    public function getRuleDefinition(): RuleDefinition
    {
        return new RuleDefinition('new line first param', []);
    }

    public function getNodeTypes(): array
    {
        return [ClassMethod::class];
    }

    public function refactor(Node $node): ?Node
    {
        $params = $node->params;

        // no params, keep as is
        if ($params

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@TomasVotruba
Comment options

Comment options

You must be logged in to vote
3 replies
@ruudk
Comment options

@ruudk
Comment options

@samsonasik
Comment options

Answer selected by samsonasik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants