Skip to content

Commit 76477a6

Browse files
committed
make PropertyFetchFinder more generic (to be used in rector-phpunit)
1 parent 5140305 commit 76477a6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/PhpParser/NodeFinder/PropertyFetchFinder.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PhpParser\Node\Param;
1818
use PhpParser\Node\Stmt;
1919
use PhpParser\Node\Stmt\Class_;
20+
use PhpParser\Node\Stmt\ClassMethod;
2021
use PhpParser\Node\Stmt\Property;
2122
use PhpParser\Node\Stmt\Trait_;
2223
use PHPStan\Analyser\Scope;
@@ -73,11 +74,11 @@ public function findPrivatePropertyFetches(
7374
/**
7475
* @return PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[]
7576
*/
76-
public function findLocalPropertyFetchesByName(Class_ $class, string $paramName): array
77+
public function findLocalPropertyFetchesByName(Class_|ClassMethod $node, string $paramName): array
7778
{
7879
/** @var PropertyFetch[]|StaticPropertyFetch[]|NullsafePropertyFetch[] $foundPropertyFetches */
7980
$foundPropertyFetches = $this->betterNodeFinder->find(
80-
$this->resolveNodesToLocate($class),
81+
$this->resolveNodesToLocate($node),
8182
function (Node $subNode) use ($paramName): bool {
8283
if ($subNode instanceof PropertyFetch) {
8384
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
@@ -162,14 +163,18 @@ public function isLocalPropertyFetchByName(Expr $expr, Class_|Trait_ $class, str
162163
/**
163164
* @return Stmt[]
164165
*/
165-
private function resolveNodesToLocate(Class_ $class): array
166+
private function resolveNodesToLocate(Class_|ClassMethod $node): array
166167
{
168+
if ($node instanceof ClassMethod) {
169+
return [$node];
170+
}
171+
167172
$propertyWithHooks = array_filter(
168-
$class->getProperties(),
173+
$node->getProperties(),
169174
fn (Property $property): bool => $property->hooks !== []
170175
);
171176

172-
return [...$propertyWithHooks, ...$class->getMethods()];
177+
return [...$propertyWithHooks, ...$node->getMethods()];
173178
}
174179

175180
/**

0 commit comments

Comments
 (0)