|
6 | 6 |
|
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Expr\PropertyFetch; |
| 9 | +use PhpParser\Node\Expr\StaticPropertyFetch; |
9 | 10 | use PhpParser\Node\Identifier; |
10 | 11 | use PhpParser\Node\Stmt\ClassLike; |
11 | 12 | use PhpParser\Node\Stmt\Property; |
@@ -46,11 +47,11 @@ public function getRuleDefinition(): RuleDefinition |
46 | 47 | */ |
47 | 48 | public function getNodeTypes(): array |
48 | 49 | { |
49 | | - return [PropertyFetch::class, ClassLike::class]; |
| 50 | + return [PropertyFetch::class, StaticPropertyFetch::class, ClassLike::class]; |
50 | 51 | } |
51 | 52 |
|
52 | 53 | /** |
53 | | - * @param PropertyFetch|ClassLike $node |
| 54 | + * @param PropertyFetch|StaticPropertyFetch|ClassLike $node |
54 | 55 | */ |
55 | 56 | public function refactor(Node $node): ?Node |
56 | 57 | { |
@@ -110,19 +111,22 @@ private function renameProperty(ClassLike $classLike, RenameProperty $renameProp |
110 | 111 | $property->props[0]->name = new VarLikeIdentifier($newProperty); |
111 | 112 | } |
112 | 113 |
|
113 | | - private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?PropertyFetch |
| 114 | + private function refactorPropertyFetch(PropertyFetch|StaticPropertyFetch $propertyFetch): null|PropertyFetch|StaticPropertyFetch |
114 | 115 | { |
115 | 116 | foreach ($this->renamedProperties as $renamedProperty) { |
116 | 117 | $oldProperty = $renamedProperty->getOldProperty(); |
117 | 118 | if (! $this->isName($propertyFetch, $oldProperty)) { |
118 | 119 | continue; |
119 | 120 | } |
120 | 121 |
|
121 | | - if (! $this->isObjectType($propertyFetch->var, $renamedProperty->getObjectType())) { |
| 122 | + $varPropertyFetch = $propertyFetch instanceof PropertyFetch ? $propertyFetch->var : $propertyFetch->class; |
| 123 | + if (! $this->isObjectType($varPropertyFetch, $renamedProperty->getObjectType())) { |
122 | 124 | continue; |
123 | 125 | } |
124 | 126 |
|
125 | | - $propertyFetch->name = new Identifier($renamedProperty->getNewProperty()); |
| 127 | + $propertyFetch->name = $propertyFetch instanceof PropertyFetch |
| 128 | + ? new Identifier($renamedProperty->getNewProperty()) |
| 129 | + : new VarLikeIdentifier($renamedProperty->getNewProperty()); |
126 | 130 | return $propertyFetch; |
127 | 131 | } |
128 | 132 |
|
|
0 commit comments