diff --git a/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/Fixture/rename_self_static.php.inc b/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/Fixture/rename_self_static.php.inc new file mode 100644 index 00000000000..51b49d428cd --- /dev/null +++ b/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/Fixture/rename_self_static.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/config/configured_rule.php b/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/config/configured_rule.php index f3a3142b00b..c49d413530f 100644 --- a/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/config/configured_rule.php +++ b/rules-tests/Renaming/Rector/PropertyFetch/RenamePropertyRector/config/configured_rule.php @@ -34,5 +34,10 @@ 'oldProperty', 'newProperty' ), + new RenameProperty( + 'Rector\Tests\Renaming\Rector\PropertyFetch\RenamePropertyRector\Fixture\MyClass', + '_config', + 'config' + ), ]); }; diff --git a/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php b/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php index 9cead89df84..1071f22eb86 100644 --- a/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php +++ b/rules/Renaming/Rector/PropertyFetch/RenamePropertyRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\PropertyFetch; +use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; @@ -46,11 +47,11 @@ public function getRuleDefinition(): RuleDefinition */ public function getNodeTypes(): array { - return [PropertyFetch::class, ClassLike::class]; + return [PropertyFetch::class, StaticPropertyFetch::class, ClassLike::class]; } /** - * @param PropertyFetch|ClassLike $node + * @param PropertyFetch|StaticPropertyFetch|ClassLike $node */ public function refactor(Node $node): ?Node { @@ -110,7 +111,7 @@ private function renameProperty(ClassLike $classLike, RenameProperty $renameProp $property->props[0]->name = new VarLikeIdentifier($newProperty); } - private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?PropertyFetch + private function refactorPropertyFetch(PropertyFetch|StaticPropertyFetch $propertyFetch): null|PropertyFetch|StaticPropertyFetch { foreach ($this->renamedProperties as $renamedProperty) { $oldProperty = $renamedProperty->getOldProperty(); @@ -118,11 +119,14 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?PropertyF continue; } - if (! $this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) { + $varPropertyFetch = $propertyFetch instanceof PropertyFetch ? $propertyFetch->var : $propertyFetch->class; + if (! $this->isObjectType($varPropertyFetch, $renamedProperty->getObjectType())) { continue; } - $propertyFetch->name = new Identifier($renamedProperty->getNewProperty()); + $propertyFetch->name = $propertyFetch instanceof PropertyFetch + ? new Identifier($renamedProperty->getNewProperty()) + : new VarLikeIdentifier($renamedProperty->getNewProperty()); return $propertyFetch; }