|
17 | 17 | use PhpParser\Node\Param; |
18 | 18 | use PhpParser\Node\Stmt; |
19 | 19 | use PhpParser\Node\Stmt\Class_; |
| 20 | +use PhpParser\Node\Stmt\ClassMethod; |
20 | 21 | use PhpParser\Node\Stmt\Property; |
21 | 22 | use PhpParser\Node\Stmt\Trait_; |
22 | 23 | use PHPStan\Analyser\Scope; |
@@ -73,11 +74,11 @@ public function findPrivatePropertyFetches( |
73 | 74 | /** |
74 | 75 | * @return PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[] |
75 | 76 | */ |
76 | | - public function findLocalPropertyFetchesByName(Class_ $class, string $paramName): array |
| 77 | + public function findLocalPropertyFetchesByName(Class_|ClassMethod $node, string $paramName): array |
77 | 78 | { |
78 | 79 | /** @var PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[] $foundPropertyFetches */ |
79 | 80 | $foundPropertyFetches = $this->betterNodeFinder->find( |
80 | | - $this->resolveNodesToLocate($class), |
| 81 | + $this->resolveNodesToLocate($node), |
81 | 82 | function (Node $subNode) use ($paramName): bool { |
82 | 83 | if ($subNode instanceof PropertyFetch) { |
83 | 84 | return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName); |
@@ -162,14 +163,18 @@ public function isLocalPropertyFetchByName(Expr $expr, Class_|Trait_ $class, str |
162 | 163 | /** |
163 | 164 | * @return Stmt[] |
164 | 165 | */ |
165 | | - private function resolveNodesToLocate(Class_ $class): array |
| 166 | + private function resolveNodesToLocate(Class_|ClassMethod $node): array |
166 | 167 | { |
| 168 | + if ($node instanceof ClassMethod) { |
| 169 | + return [$node]; |
| 170 | + } |
| 171 | + |
167 | 172 | $propertyWithHooks = array_filter( |
168 | | - $class->getProperties(), |
| 173 | + $node->getProperties(), |
169 | 174 | fn (Property $property): bool => $property->hooks !== [] |
170 | 175 | ); |
171 | 176 |
|
172 | | - return [...$propertyWithHooks, ...$class->getMethods()]; |
| 177 | + return [...$propertyWithHooks, ...$node->getMethods()]; |
173 | 178 | } |
174 | 179 |
|
175 | 180 | /** |
|
0 commit comments