From bc24bb12fff8831db12542ce84aafcc52c977a4f Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Fri, 21 Feb 2020 15:54:51 +0100 Subject: [PATCH] prevent getName() on StaticCall or MethodCall --- .github/workflows/test_with_doctrine.yaml | 2 +- .../ParsedFunctionLikeNodeCollector.php | 2 +- .../src/NodeNameResolver.php | 10 +++++++++ .../Rector/MethodCall/ModalToGetSetRector.php | 2 +- ...RenameMethodCallBasedOnParameterRector.php | 2 +- .../ForRepeatedCountToOwnVariableRector.php | 15 ++++++++++++- .../RemoveDelegatingParentCallRector.php | 5 +++-- .../RemoveDefaultArgumentValueRector.php | 2 +- .../Stmt/RemoveUnreachableStatementRector.php | 9 ++++++++ ...egistryGetManagerToEntityManagerRector.php | 2 +- .../src/AssertManipulator.php | 21 +++++++++++-------- .../src/Route/RouteInfoFactory.php | 4 ++-- ...VariableToVariableOnFunctionCallRector.php | 2 ++ .../FunctionLike/Php4ConstructorRector.php | 2 +- ...ticCallOnNonStaticToInstanceCallRector.php | 2 +- .../ExportToReflectionFunctionRector.php | 2 +- .../PhpSpecMocksToPHPUnitMocksRector.php | 2 +- .../PhpSpecPromisesToPHPUnitAssertRector.php | 2 +- .../SpecificAssertContainsRector.php | 4 +++- .../AssertCompareToSpecificMethodRector.php | 2 +- .../SpecificMethod/AssertRegExpRector.php | 2 +- .../MethodCall/RenameStaticMethodRector.php | 2 +- ...lightResponseWithSymfonyResponseRector.php | 3 ++- .../Rector/Class_/MakeCommandLazyRector.php | 2 +- .../src/Rector/Yaml/ParseFileRector.php | 2 +- .../Regex/RegexPatternArgumentManipulator.php | 2 +- .../ChainMethodCallManipulator.php | 2 +- .../Manipulator/IdentifierManipulator.php | 12 ++++++++++- .../Manipulator/MethodCallManipulator.php | 2 +- src/Rector/Argument/ArgumentRemoverRector.php | 2 +- .../ClassMethod/AddMethodParentCallRector.php | 2 +- .../StaticCall/StaticCallToFunctionRector.php | 2 +- 32 files changed, 90 insertions(+), 39 deletions(-) diff --git a/.github/workflows/test_with_doctrine.yaml b/.github/workflows/test_with_doctrine.yaml index 134107d65097..b512584a1732 100644 --- a/.github/workflows/test_with_doctrine.yaml +++ b/.github/workflows/test_with_doctrine.yaml @@ -32,4 +32,4 @@ jobs: # do not intall doctrine/orm phpstan, it conflicts with Retor's one composer install -d orm --no-dev - - run: bin/rector process orm/lib --config ci/config/rector-doctrine.yaml --autoload-file orm/vendor/autoload.php + - run: bin/rector process orm/lib --config ci/config/rector-doctrine.yaml --autoload-file orm/vendor/autoload.php --debug diff --git a/packages/node-collector/src/NodeCollector/ParsedFunctionLikeNodeCollector.php b/packages/node-collector/src/NodeCollector/ParsedFunctionLikeNodeCollector.php index 1ffa57678c4c..9438eceb3e2a 100644 --- a/packages/node-collector/src/NodeCollector/ParsedFunctionLikeNodeCollector.php +++ b/packages/node-collector/src/NodeCollector/ParsedFunctionLikeNodeCollector.php @@ -205,7 +205,7 @@ private function addCall(Node $node): void // one node can be of multiple-class types $classType = $this->resolveClassType($node); - $methodName = $this->nodeNameResolver->getName($node); + $methodName = $this->nodeNameResolver->getName($node->name); if ($classType instanceof MixedType) { // anonymous return; } diff --git a/packages/node-name-resolver/src/NodeNameResolver.php b/packages/node-name-resolver/src/NodeNameResolver.php index e45da0fc412f..a8b4abf9cb27 100644 --- a/packages/node-name-resolver/src/NodeNameResolver.php +++ b/packages/node-name-resolver/src/NodeNameResolver.php @@ -8,9 +8,11 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Trait_; +use Rector\Core\Exception\ShouldNotHappenException; use Rector\NodeNameResolver\Contract\NodeNameResolverInterface; use Rector\NodeNameResolver\Regex\RegexPatternDetector; @@ -85,6 +87,14 @@ public function isName(Node $node, string $name): bool public function getName(Node $node): ?string { + if ($node instanceof MethodCall || $node instanceof StaticCall) { + if ($node->name instanceof MethodCall || $node->name instanceof StaticCall) { + return null; + } + + throw new ShouldNotHappenException(sprintf('Pick more specific node than "%s"', get_class($node))); + } + foreach ($this->nodeNameResolvers as $nodeNameResolver) { if (! is_a($node, $nodeNameResolver->getNode(), true)) { continue; diff --git a/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php b/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php index 6e4da9ddc7fe..21acb7d105f0 100644 --- a/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php +++ b/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php @@ -103,7 +103,7 @@ private function matchTypeAndMethodName(MethodCall $methodCall): ?array continue; } - $currentMethodName = $this->getName($methodCall); + $currentMethodName = $this->getName($methodCall->name); if ($currentMethodName === null) { continue; } diff --git a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php index 88a6a8032a28..7cdf38666c96 100644 --- a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php +++ b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php @@ -106,7 +106,7 @@ private function matchTypeAndMethodName(MethodCall $methodCall): ?array continue; } - $currentMethodName = $this->getName($methodCall); + $currentMethodName = $this->getName($methodCall->name); if ($currentMethodName === null) { continue; } diff --git a/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php b/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php index 590002f7eac3..a92f5ac574ff 100644 --- a/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php +++ b/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php @@ -7,6 +7,8 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\For_; use PHPStan\Analyser\Scope; @@ -89,7 +91,8 @@ public function refactor(Node $node): ?Node } $countInCond = $node; - $valueName = $this->getName($node->args[0]->value); + + $valueName = $this->resolveValueName($node); $countedValueName = $this->createCountedValueName($valueName, $for->getAttribute(AttributeKey::SCOPE)); return new Variable($countedValueName); @@ -111,4 +114,14 @@ protected function createCountedValueName(?string $valueName, ?Scope $scope): st return parent::createCountedValueName($countedValueName, $scope); } + + private function resolveValueName(FuncCall $funcCall): ?string + { + $argumentValue = $funcCall->args[0]->value; + if ($argumentValue instanceof MethodCall || $argumentValue instanceof StaticCall) { + return $this->getName($argumentValue->name); + } + + return $this->getName($argumentValue); + } } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index 81a664bfda98..d016de8f7258 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -160,7 +160,7 @@ private function isParentCallMatching(ClassMethod $classMethod, ?StaticCall $sta return false; } - if (! $this->areNamesEqual($staticCall, $classMethod)) { + if (! $this->areNamesEqual($staticCall->name, $classMethod->name)) { return false; } @@ -222,7 +222,8 @@ private function isParentClassMethodVisibilityOrDefaultOverride( } /** @var string $methodName */ - $methodName = $this->getName($staticCall); + $methodName = $this->getName($staticCall->name); + $parentClassMethod = $this->functionLikeParsedNodesFinder->findMethod($methodName, $parentClassName); if ($parentClassMethod !== null && $parentClassMethod->isProtected() && $classMethod->isPublic()) { return true; diff --git a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php index e50e837ce254..f6f14a4a4997 100644 --- a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php +++ b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php @@ -133,7 +133,7 @@ private function shouldSkip(Node $node): bool private function resolveDefaultValuesFromCall(Node $node): array { /** @var string|null $nodeName */ - $nodeName = $this->getName($node); + $nodeName = $this->getName($node->name); if ($nodeName === null) { return []; } diff --git a/rules/dead-code/src/Rector/Stmt/RemoveUnreachableStatementRector.php b/rules/dead-code/src/Rector/Stmt/RemoveUnreachableStatementRector.php index 4f261ce9b00c..2383ad195693 100644 --- a/rules/dead-code/src/Rector/Stmt/RemoveUnreachableStatementRector.php +++ b/rules/dead-code/src/Rector/Stmt/RemoveUnreachableStatementRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; @@ -134,6 +135,14 @@ private function isAfterMarkTestSkippedMethodCall(Node $node): bool return false; } + if ($node->name instanceof MethodCall) { + return false; + } + + if ($node->name instanceof StaticCall) { + return false; + } + return $this->isName($node->name, 'markTestSkipped'); }); } diff --git a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php index b9407e0713a1..2bc2b2ee8b2a 100644 --- a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php +++ b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php @@ -147,7 +147,7 @@ private function resolveManagerRegistryCalledMethodNames(Class_ $class): array return null; } - $name = $this->getName($node); + $name = $this->getName($node->name); if ($name === null) { return null; } diff --git a/rules/nette-tester-to-phpunit/src/AssertManipulator.php b/rules/nette-tester-to-phpunit/src/AssertManipulator.php index 405c48afa8a7..76651513d0d4 100644 --- a/rules/nette-tester-to-phpunit/src/AssertManipulator.php +++ b/rules/nette-tester-to-phpunit/src/AssertManipulator.php @@ -117,17 +117,17 @@ public function __construct( */ public function processStaticCall(StaticCall $staticCall): Node { - if ($this->nodeNameResolver->isNames($staticCall, ['truthy', 'falsey'])) { + if ($this->nodeNameResolver->isNames($staticCall->name, ['truthy', 'falsey'])) { return $this->processTruthyOrFalseyCall($staticCall); } - if ($this->nodeNameResolver->isNames($staticCall, ['contains', 'notContains'])) { + if ($this->nodeNameResolver->isNames($staticCall->name, ['contains', 'notContains'])) { $this->processContainsCall($staticCall); - } elseif ($this->nodeNameResolver->isNames($staticCall, ['exception', 'throws'])) { + } elseif ($this->nodeNameResolver->isNames($staticCall->name, ['exception', 'throws'])) { $this->processExceptionCall($staticCall); - } elseif ($this->nodeNameResolver->isName($staticCall, 'type')) { + } elseif ($this->nodeNameResolver->isName($staticCall->name, 'type')) { $this->processTypeCall($staticCall); - } elseif ($this->nodeNameResolver->isName($staticCall, 'noError')) { + } elseif ($this->nodeNameResolver->isName($staticCall->name, 'noError')) { $this->processNoErrorCall($staticCall); } else { $this->renameAssertMethod($staticCall); @@ -153,11 +153,14 @@ private function processContainsCall(StaticCall $staticCall): void { if ($this->stringTypeAnalyzer->isStringOrUnionStringOnlyType($staticCall->args[1]->value)) { $name = $this->nodeNameResolver->isName( - $staticCall, + $staticCall->name, 'contains' ) ? 'assertStringContainsString' : 'assertStringNotContainsString'; } else { - $name = $this->nodeNameResolver->isName($staticCall, 'contains') ? 'assertContains' : 'assertNotContains'; + $name = $this->nodeNameResolver->isName( + $staticCall->name, + 'contains' + ) ? 'assertContains' : 'assertNotContains'; } $staticCall->name = new Identifier($name); @@ -240,7 +243,7 @@ private function processNoErrorCall(StaticCall $staticCall): void */ private function processTruthyOrFalseyCall(StaticCall $staticCall): Expr { - $method = $this->nodeNameResolver->isName($staticCall, 'truthy') ? 'assertTrue' : 'assertFalse'; + $method = $this->nodeNameResolver->isName($staticCall->name, 'truthy') ? 'assertTrue' : 'assertFalse'; if (! $this->sholdBeStaticCall($staticCall)) { $call = new MethodCall(new Variable('this'), $method); @@ -296,7 +299,7 @@ private function refactorExpectExceptionCode(StaticCall $staticCall): void private function renameAssertMethod(StaticCall $staticCall): void { foreach (self::ASSERT_METHODS_REMAP as $oldMethod => $newMethod) { - if (! $this->nodeNameResolver->isName($staticCall, $oldMethod)) { + if (! $this->nodeNameResolver->isName($staticCall->name, $oldMethod)) { continue; } diff --git a/rules/nette-to-symfony/src/Route/RouteInfoFactory.php b/rules/nette-to-symfony/src/Route/RouteInfoFactory.php index a5bf52dd5aec..7cd83783bff7 100644 --- a/rules/nette-to-symfony/src/Route/RouteInfoFactory.php +++ b/rules/nette-to-symfony/src/Route/RouteInfoFactory.php @@ -58,12 +58,12 @@ public function createFromNode(Node $node): ?RouteInfo return null; } - if (! $this->nodeNameResolver->isNames($node, ['get', 'head', 'post', 'put', 'patch', 'delete'])) { + if (! $this->nodeNameResolver->isNames($node->name, ['get', 'head', 'post', 'put', 'patch', 'delete'])) { return null; } /** @var string $methodName */ - $methodName = $this->nodeNameResolver->getName($node); + $methodName = $this->nodeNameResolver->getName($node->name); $uppercasedMethodName = strtoupper($methodName); $methods = []; diff --git a/rules/php-70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php b/rules/php-70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php index 7c5e8d9e328d..1ee9ee8d9226 100644 --- a/rules/php-70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php +++ b/rules/php-70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php @@ -170,6 +170,8 @@ private function getVariableNameFor(Expr $expr, Scope $scope): string { if ($expr instanceof New_ && $expr->class instanceof Name) { $name = $this->getShortName($expr->class); + } elseif ($expr instanceof MethodCall || $expr instanceof StaticCall) { + $name = $this->getName($expr->name); } else { $name = $this->getName($expr); } diff --git a/rules/php-70/src/Rector/FunctionLike/Php4ConstructorRector.php b/rules/php-70/src/Rector/FunctionLike/Php4ConstructorRector.php index 20fe285f11c4..1ca03ba4b204 100644 --- a/rules/php-70/src/Rector/FunctionLike/Php4ConstructorRector.php +++ b/rules/php-70/src/Rector/FunctionLike/Php4ConstructorRector.php @@ -196,7 +196,7 @@ private function processParentPhp4ConstructCall(Node $node): void } // it's not a parent PHP 4 constructor call - if (! $this->isName($node, $parentClassName)) { + if (! $this->isName($node->name, $parentClassName)) { return; } diff --git a/rules/php-70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php b/rules/php-70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php index d63a4dfa04a9..eb13def17dee 100644 --- a/rules/php-70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php +++ b/rules/php-70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php @@ -90,7 +90,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $methodName = $this->getName($node); + $methodName = $this->getName($node->name); $className = $this->resolveStaticCallClassName($node); if ($methodName === null || $className === null) { diff --git a/rules/php-74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php b/rules/php-74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php index f7954c59e5af..dce06516eb5b 100644 --- a/rules/php-74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php +++ b/rules/php-74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php @@ -59,7 +59,7 @@ public function refactor(Node $node): ?Node return null; } - if (! $this->isName($node, 'export')) { + if (! $this->isName($node->name, 'export')) { return null; } diff --git a/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php b/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php index f5999fb82573..9c4c77f64a52 100644 --- a/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php +++ b/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php @@ -107,7 +107,7 @@ private function processMethodCall(MethodCall $methodCall): ?MethodCall throw new ShouldNotHappenException(); } - $mockMethodName = $this->getName($methodCall->var); + $mockMethodName = $this->getName($methodCall->var->name); if ($mockMethodName === null) { throw new ShouldNotHappenException(); } diff --git a/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php b/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php index 50c96a57520d..5feee1c54178 100644 --- a/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php +++ b/rules/php-spec-to-phpunit/src/Rector/MethodCall/PhpSpecPromisesToPHPUnitAssertRector.php @@ -178,7 +178,7 @@ public function refactor(Node $node): ?Node return new Clone_($this->testedObjectPropertyFetch); } - $methodName = $this->getName($node); + $methodName = $this->getName($node->name); if ($methodName === null) { return null; } diff --git a/rules/phpunit/src/Rector/MethodCall/SpecificAssertContainsRector.php b/rules/phpunit/src/Rector/MethodCall/SpecificAssertContainsRector.php index 9f1a5d8fbccd..80b8566031c5 100644 --- a/rules/phpunit/src/Rector/MethodCall/SpecificAssertContainsRector.php +++ b/rules/phpunit/src/Rector/MethodCall/SpecificAssertContainsRector.php @@ -86,7 +86,9 @@ public function refactor(Node $node): ?Node return null; } - $node->name = new Identifier(self::OLD_METHODS_NAMES_TO_NEW_NAMES['string'][$this->getName($node)]); + $methodName = $this->getName($node->name); + + $node->name = new Identifier(self::OLD_METHODS_NAMES_TO_NEW_NAMES['string'][$methodName]); return $node; } diff --git a/rules/phpunit/src/Rector/SpecificMethod/AssertCompareToSpecificMethodRector.php b/rules/phpunit/src/Rector/SpecificMethod/AssertCompareToSpecificMethodRector.php index ecf1b08ccfa0..fd4373158074 100644 --- a/rules/phpunit/src/Rector/SpecificMethod/AssertCompareToSpecificMethodRector.php +++ b/rules/phpunit/src/Rector/SpecificMethod/AssertCompareToSpecificMethodRector.php @@ -109,7 +109,7 @@ private function processFuncCallArgumentValue(Node $node, FuncCall $funcCall, Ar private function renameMethod(Node $node, string $funcName): void { /** @var string $oldMethodName */ - $oldMethodName = $this->getName($node); + $oldMethodName = $this->getName($node->name); [$trueMethodName, $falseMethodName] = self::DEFAULT_OLD_TO_NEW_METHODS[$funcName]; diff --git a/rules/phpunit/src/Rector/SpecificMethod/AssertRegExpRector.php b/rules/phpunit/src/Rector/SpecificMethod/AssertRegExpRector.php index 29a5ae4e47e4..fee161d6ea29 100644 --- a/rules/phpunit/src/Rector/SpecificMethod/AssertRegExpRector.php +++ b/rules/phpunit/src/Rector/SpecificMethod/AssertRegExpRector.php @@ -62,7 +62,7 @@ public function refactor(Node $node): ?Node return null; } - $oldMethodName = $this->getName($node); + $oldMethodName = $this->getName($node->name); if ($oldMethodName === null) { return null; } diff --git a/rules/renaming/src/Rector/MethodCall/RenameStaticMethodRector.php b/rules/renaming/src/Rector/MethodCall/RenameStaticMethodRector.php index 2a94ccdc2548..185a2dd1d9f8 100644 --- a/rules/renaming/src/Rector/MethodCall/RenameStaticMethodRector.php +++ b/rules/renaming/src/Rector/MethodCall/RenameStaticMethodRector.php @@ -75,7 +75,7 @@ public function refactor(Node $node): ?Node } foreach ($oldToNewMethods as $oldMethod => $newMethod) { - if (! $this->isName($node, $oldMethod)) { + if (! $this->isName($node->name, $oldMethod)) { continue; } diff --git a/rules/shopware/src/Rector/MethodCall/ReplaceEnlightResponseWithSymfonyResponseRector.php b/rules/shopware/src/Rector/MethodCall/ReplaceEnlightResponseWithSymfonyResponseRector.php index e73933ab6217..46217ad944c7 100644 --- a/rules/shopware/src/Rector/MethodCall/ReplaceEnlightResponseWithSymfonyResponseRector.php +++ b/rules/shopware/src/Rector/MethodCall/ReplaceEnlightResponseWithSymfonyResponseRector.php @@ -67,7 +67,8 @@ public function refactor(Node $node): ?Node return null; } - $name = $this->getName($node); + $name = $this->getName($node->name); + switch ($name) { case 'setHeader': return $this->modifySetHeader($node); diff --git a/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php b/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php index f5d1fdd86990..b0984925129e 100644 --- a/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php +++ b/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php @@ -105,7 +105,7 @@ private function matchCommandNameNodeInConstruct(Expr $expr): ?Node return null; } - if (! $this->isName($expr, '__construct')) { + if (! $this->isName($expr->name, '__construct')) { return null; } diff --git a/rules/symfony/src/Rector/Yaml/ParseFileRector.php b/rules/symfony/src/Rector/Yaml/ParseFileRector.php index 02e5c5905f1a..a462e953070d 100644 --- a/rules/symfony/src/Rector/Yaml/ParseFileRector.php +++ b/rules/symfony/src/Rector/Yaml/ParseFileRector.php @@ -42,7 +42,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->isName($node, 'parse')) { + if (! $this->isName($node->name, 'parse')) { return null; } diff --git a/src/Php/Regex/RegexPatternArgumentManipulator.php b/src/Php/Regex/RegexPatternArgumentManipulator.php index 4b64ed78d163..1b910338801a 100644 --- a/src/Php/Regex/RegexPatternArgumentManipulator.php +++ b/src/Php/Regex/RegexPatternArgumentManipulator.php @@ -133,7 +133,7 @@ private function processStaticCall(StaticCall $staticCall): array } foreach ($methodNamesToArgumentPosition as $methodName => $argumentPosition) { - if (! $this->nodeNameResolver->isName($staticCall, $methodName)) { + if (! $this->nodeNameResolver->isName($staticCall->name, $methodName)) { continue; } diff --git a/src/PhpParser/Node/Manipulator/ChainMethodCallManipulator.php b/src/PhpParser/Node/Manipulator/ChainMethodCallManipulator.php index f19470c4176c..4a9631ff1d8a 100644 --- a/src/PhpParser/Node/Manipulator/ChainMethodCallManipulator.php +++ b/src/PhpParser/Node/Manipulator/ChainMethodCallManipulator.php @@ -48,7 +48,7 @@ public function isTypeAndChainCalls(Node $node, Type $type, array $methods): boo $methods = array_reverse($methods); foreach ($methods as $method) { - $activeMethodName = $this->nodeNameResolver->getName($node); + $activeMethodName = $this->nodeNameResolver->getName($node->name); if ($activeMethodName !== $method) { return false; } diff --git a/src/PhpParser/Node/Manipulator/IdentifierManipulator.php b/src/PhpParser/Node/Manipulator/IdentifierManipulator.php index 350a80655b66..b2a55719eef7 100644 --- a/src/PhpParser/Node/Manipulator/IdentifierManipulator.php +++ b/src/PhpParser/Node/Manipulator/IdentifierManipulator.php @@ -48,7 +48,7 @@ public function renameNodeWithMap(Node $node, array $renameMethodMap): void { $this->ensureNodeHasIdentifier($node); - $oldNodeMethodName = $this->nodeNameResolver->getName($node); + $oldNodeMethodName = $this->resolveOldMethodName($node); if ($oldNodeMethodName === null) { return; } @@ -85,4 +85,14 @@ private function ensureNodeHasIdentifier(Node $node): void implode('", "', self::NODE_CLASSES_WITH_IDENTIFIER) )); } + + private function resolveOldMethodName(Node $node) + { + if ($node instanceof StaticCall || $node instanceof MethodCall) { + $oldNodeMethodName = $this->nodeNameResolver->getName($node->name); + } else { + $oldNodeMethodName = $this->nodeNameResolver->getName($node); + } + return $oldNodeMethodName; + } } diff --git a/src/PhpParser/Node/Manipulator/MethodCallManipulator.php b/src/PhpParser/Node/Manipulator/MethodCallManipulator.php index 4b3693e44dae..24b9f09da6ef 100644 --- a/src/PhpParser/Node/Manipulator/MethodCallManipulator.php +++ b/src/PhpParser/Node/Manipulator/MethodCallManipulator.php @@ -51,7 +51,7 @@ public function findMethodCallNamesOnVariable(Variable $variable): array $methodCallNamesOnVariable = []; foreach ($methodCallsOnVariable as $methodCallOnVariable) { - $methodName = $this->nodeNameResolver->getName($methodCallOnVariable); + $methodName = $this->nodeNameResolver->getName($methodCallOnVariable->name); if ($methodName === null) { continue; } diff --git a/src/Rector/Argument/ArgumentRemoverRector.php b/src/Rector/Argument/ArgumentRemoverRector.php index eb0e5b2ae820..06c237c831cd 100644 --- a/src/Rector/Argument/ArgumentRemoverRector.php +++ b/src/Rector/Argument/ArgumentRemoverRector.php @@ -80,7 +80,7 @@ public function refactor(Node $node): ?Node } foreach ($positionByMethodName as $methodName => $positions) { - if (! $this->isName($node, $methodName)) { + if (! $this->isName($node->name, $methodName)) { continue; } diff --git a/src/Rector/ClassMethod/AddMethodParentCallRector.php b/src/Rector/ClassMethod/AddMethodParentCallRector.php index 97ac63af3291..acea7a773397 100644 --- a/src/Rector/ClassMethod/AddMethodParentCallRector.php +++ b/src/Rector/ClassMethod/AddMethodParentCallRector.php @@ -146,7 +146,7 @@ private function hasParentCallOfMethod(ClassMethod $classMethod, string $method) return false; } - return $this->isName($node, $method); + return $this->isName($node->name, $method); }); } } diff --git a/src/Rector/StaticCall/StaticCallToFunctionRector.php b/src/Rector/StaticCall/StaticCallToFunctionRector.php index c7de97cb11e8..1db2c369f62d 100644 --- a/src/Rector/StaticCall/StaticCallToFunctionRector.php +++ b/src/Rector/StaticCall/StaticCallToFunctionRector.php @@ -66,7 +66,7 @@ public function refactor(Node $node): ?Node } foreach ($methodNamesToFunctions as $methodName => $function) { - if (! $this->isName($node, $methodName)) { + if (! $this->isName($node->name, $methodName)) { continue; }