Skip to content

Commit

Permalink
Align rector classes with rest of cakephp formatting standards
Browse files Browse the repository at this point in the history
All mechanical changes from the modification in `phpcs.xml` and running
`composer cs-fix`.
  • Loading branch information
markstory committed Sep 6, 2024
1 parent c2f65ec commit eb188cd
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 61 deletions.
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<rule ref="CakePHP"/>

<exclude-pattern>src/Rector</exclude-pattern>
<exclude-pattern>tests/test_apps</exclude-pattern>
<exclude-pattern>tests/TestCase/Rector</exclude-pattern>
</ruleset>
9 changes: 6 additions & 3 deletions src/Rector/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare (strict_types=1);
declare(strict_types=1);

namespace Cake\Upgrade\Rector\NodeAnalyzer;

Expand All @@ -20,7 +20,7 @@ final class FluentChainMethodCallNodeAnalyzer
/**
* @api doctrine
*/
public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
public function resolveRootMethodCall(MethodCall $methodCall): ?MethodCall
{
$callerNode = $methodCall->var;
while ($callerNode instanceof MethodCall && $callerNode->var instanceof MethodCall) {
Expand All @@ -29,17 +29,20 @@ public function resolveRootMethodCall(MethodCall $methodCall) : ?MethodCall
if ($callerNode instanceof MethodCall) {
return $callerNode;
}

return null;
}

/**
* @return \PhpParser\Node\Expr|\PhpParser\Node\Name
*/
public function resolveRootExpr(MethodCall $methodCall)
public function resolveRootExpr(MethodCall $methodCall): Expr|Name
{
$callerNode = $methodCall->var;
while ($callerNode instanceof MethodCall || $callerNode instanceof StaticCall) {
$callerNode = $callerNode instanceof StaticCall ? $callerNode->class : $callerNode->var;
}

return $callerNode;
}
}
4 changes: 2 additions & 2 deletions src/Rector/Rector/MethodCall/AddMethodCallArgsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class AddMethodCallArgsRector extends AbstractRector implements Configurab
public const ADD_METHOD_CALL_ARGS = 'add_method_call_args';

/**
* @var \Cake\Upgrade\Rector\ValueObject\AddMethodCallArgs[]
* @var array<\Cake\Upgrade\Rector\ValueObject\AddMethodCallArgs>
*/
private array $callsWithAddMethodCallArgs = [];

Expand Down Expand Up @@ -97,7 +97,7 @@ public function refactor(Node $node): ?Node
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
12 changes: 6 additions & 6 deletions src/Rector/Rector/MethodCall/ArrayToFluentCallRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Cake\Upgrade\Rector\Rector\MethodCall;

use Cake\Upgrade\Rector\ValueObject\ArrayItemsAndFluentClass;
use Cake\Upgrade\Rector\ValueObject\ArrayToFluentCall;
use Cake\Upgrade\Rector\ValueObject\FactoryMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Cake\Upgrade\Rector\ValueObject\ArrayItemsAndFluentClass;
use Cake\Upgrade\Rector\ValueObject\ArrayToFluentCall;
use Cake\Upgrade\Rector\ValueObject\FactoryMethod;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -31,12 +31,12 @@ final class ArrayToFluentCallRector extends AbstractRector implements Configurab
public const FACTORY_METHODS = 'factory_methods';

/**
* @var \Cake\Upgrade\Rector\ValueObject\ArrayToFluentCall[]
* @var array<\Cake\Upgrade\Rector\ValueObject\ArrayToFluentCall>
*/
private array $arraysToFluentCalls = [];

/**
* @var \Cake\Upgrade\Rector\ValueObject\FactoryMethod[]
* @var array<\Cake\Upgrade\Rector\ValueObject\FactoryMethod>
*/
private array $factoryMethods = [];

Expand Down Expand Up @@ -115,7 +115,7 @@ public function refactor(Node $node): ?Node
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Rector/Rector/MethodCall/ModalToGetSetRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace Cake\Upgrade\Rector\Rector\MethodCall;

use Cake\Upgrade\Rector\ValueObject\ModalToGetSet;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use Cake\Upgrade\Rector\ValueObject\ModalToGetSet;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -27,7 +27,7 @@ final class ModalToGetSetRector extends AbstractRector implements ConfigurableRe
public const UNPREFIXED_METHODS_TO_GET_SET = 'unprefixed_methods_to_get_set';

/**
* @var \Cake\Upgrade\Rector\ValueObject\ModalToGetSet[]
* @var array<\Cake\Upgrade\Rector\ValueObject\ModalToGetSet>
*/
private array $unprefixedMethodsToGetSet = [];

Expand Down Expand Up @@ -92,7 +92,7 @@ public function refactor(Node $node): ?Node
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,25 @@

namespace Cake\Upgrade\Rector\Rector\MethodCall;

use Cake\Upgrade\Rector\ValueObject\OptionsArrayToNamedParameters;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Cake\Upgrade\Rector\ValueObject\OptionsArrayToNamedParameters;
use PhpParser\Node\Arg;
use PhpParser\Node\Identifier;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

use function RectorPrefix202304\dump_node;

final class OptionsArrayToNamedParametersRector extends AbstractRector implements ConfigurableRectorInterface
{
public const OPTIONS_TO_NAMED_PARAMETERS = 'options_to_named_parameters';

/**
* @var \Cake\Upgrade\Rector\ValueObject\OptionsArrayToNamedParameters
*/
private $optionsToNamed = [];
private OptionsArrayToNamedParameters $optionsToNamed = [];

public function getRuleDefinition(): RuleDefinition
{
Expand Down Expand Up @@ -82,9 +79,10 @@ public function refactor(Node $node): ?Node
if (!$this->matchTypeAndMethodName($optionsToNamed, $node)) {
continue;
}
return $this->replaceMethodCall($optionsToNamed, $node);

return $this->replaceMethodCall($optionsToNamed, $node);
}

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Cake\Upgrade\Rector\Rector\MethodCall;

use Cake\Upgrade\Rector\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Cake\Upgrade\Rector\ValueObject\RemoveIntermediaryMethod;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use Cake\Upgrade\Rector\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer;
use Cake\Upgrade\Rector\ValueObject\RemoveIntermediaryMethod;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -28,7 +28,7 @@ final class RemoveIntermediaryMethodRector extends AbstractRector implements Con
public const REMOVE_INTERMEDIARY_METHOD = 'remove_intermediary_method';

/**
* @var \Cake\Upgrade\Rector\ValueObject\RemoveIntermediaryMethod[]
* @var array<\Cake\Upgrade\Rector\ValueObject\RemoveIntermediaryMethod>
*/
private array $removeIntermediaryMethod = [];

Expand Down Expand Up @@ -86,7 +86,7 @@ public function refactor(Node $node): ?Node
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
21 changes: 11 additions & 10 deletions src/Rector/Rector/MethodCall/RemoveMethodCallRector.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

declare (strict_types = 1);
declare(strict_types=1);

namespace Cake\Upgrade\Rector\Rector\MethodCall;

Expand All @@ -24,9 +23,9 @@ final class RemoveMethodCallRector extends AbstractRector implements Configurabl
public const REMOVE_METHOD_CALL_ARGS = 'remove_method_call_args';

/**
* @var \Cake\Upgrade\Rector\ValueObject\RemoveMethodCall[]
* @var array<\Cake\Upgrade\Rector\ValueObject\RemoveMethodCall>
*/
private $callsWithRemoveMethodCallArgs = [];
private array $callsWithRemoveMethodCallArgs = [];

public function getRuleDefinition(): RuleDefinition
{
Expand All @@ -36,24 +35,26 @@ public function getRuleDefinition(): RuleDefinition
$obj = new SomeClass();
$obj->methodCall1();
$obj->methodCall2();
CODE_SAMPLE, <<<'CODE_SAMPLE'
CODE_SAMPLE,
<<<'CODE_SAMPLE'
$obj = new SomeClass();
$obj->methodCall2();
CODE_SAMPLE, ['SomeClass', 'methodCall1']
)
CODE_SAMPLE,
['SomeClass', 'methodCall1']
),
]);
}

/**
* @return array<class-string<Node>>
* @return array<class-string<\PhpParser\Node>>
*/
public function getNodeTypes(): array
{
return [Expression::class];
}

/**
* @param Expression $node
* @param \PhpParser\Node\Stmt\Expression $node
*/
public function refactor(Node $node): ?int
{
Expand All @@ -77,7 +78,7 @@ public function refactor(Node $node): ?int
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace Cake\Upgrade\Rector\Rector\MethodCall;

use Cake\Upgrade\Rector\ValueObject\RenameMethodCallBasedOnParameter;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Identifier;
use Cake\Upgrade\Rector\ValueObject\RenameMethodCallBasedOnParameter;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
Expand All @@ -27,7 +27,7 @@ final class RenameMethodCallBasedOnParameterRector extends AbstractRector implem
public const CALLS_WITH_PARAM_RENAMES = 'calls_with_param_renames';

/**
* @var \Cake\Upgrade\Rector\ValueObject\RenameMethodCallBasedOnParameter[]
* @var array<\Cake\Upgrade\Rector\ValueObject\RenameMethodCallBasedOnParameter>
*/
private array $callsWithParamRenames = [];

Expand Down Expand Up @@ -92,7 +92,7 @@ public function refactor(Node $node): ?Node
}

/**
* @param mixed[] $configuration
* @param array<mixed> $configuration
*/
public function configure(array $configuration): void
{
Expand Down
5 changes: 2 additions & 3 deletions src/Rector/Rector/MethodCall/TableRegistryLocatorRector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace Cake\Upgrade\Rector\Rector\MethodCall;
Expand All @@ -23,7 +22,7 @@ public function getRuleDefinition(): RuleDefinition
<<<'CODE_SAMPLE'
TableRegistry::getTableLocator()->get('something');
CODE_SAMPLE
)
),
]);
}

Expand All @@ -34,7 +33,7 @@ public function getNodeTypes(): array

public function refactor(Node $node): ?Node
{
if(! $node instanceof StaticCall) {
if (! $node instanceof StaticCall) {
return null;
}

Expand Down
Loading

0 comments on commit eb188cd

Please sign in to comment.