|
8 | 8 | use PhpParser\Node\Expr\FuncCall; |
9 | 9 | use PhpParser\Node\Expr\MethodCall; |
10 | 10 | use PhpParser\Node\Expr\StaticCall; |
| 11 | +use PhpParser\Node\Expr\Variable; |
| 12 | +use PhpParser\Node\Name; |
| 13 | +use PhpParser\NodeFinder; |
11 | 14 | use PHPStan\Analyser\MutatingScope; |
12 | 15 | use PHPStan\Analyser\Scope; |
13 | 16 | use PHPStan\Analyser\TypeSpecifier; |
@@ -421,28 +424,22 @@ private function isExpressionDependentOnTraitContext(Scope $scope, Expr $expr): |
421 | 424 |
|
422 | 425 | private static function isExpressionDependentOnThis(Expr $expr): bool |
423 | 426 | { |
424 | | - if ($expr instanceof Expr\Variable && $expr->name === 'this') { |
425 | | - return true; |
426 | | - } |
427 | | - |
428 | | - if ($expr instanceof Expr\PropertyFetch || $expr instanceof Expr\NullsafePropertyFetch) { |
429 | | - return self::isExpressionDependentOnThis($expr->var); |
430 | | - } |
431 | | - |
432 | | - if ($expr instanceof Expr\MethodCall || $expr instanceof Expr\NullsafeMethodCall) { |
433 | | - return self::isExpressionDependentOnThis($expr->var); |
434 | | - } |
435 | | - |
436 | | - if ($expr instanceof Expr\StaticPropertyFetch || $expr instanceof Expr\StaticCall) { |
437 | | - if ($expr->class instanceof Expr) { |
438 | | - return self::isExpressionDependentOnThis($expr->class); |
| 427 | + $nodeFinder = new NodeFinder(); |
| 428 | + return $nodeFinder->findFirst([$expr], static function (Node $node): bool { |
| 429 | + if ($node instanceof Variable && $node->name === 'this') { |
| 430 | + return true; |
439 | 431 | } |
440 | 432 |
|
441 | | - $className = $expr->class->toString(); |
442 | | - return in_array($className, ['self', 'static', 'parent'], true); |
443 | | - } |
| 433 | + if ( |
| 434 | + ($node instanceof Expr\StaticPropertyFetch || $node instanceof Expr\StaticCall) |
| 435 | + && $node->class instanceof Name |
| 436 | + && in_array($node->class->toString(), ['self', 'static', 'parent'], true) |
| 437 | + ) { |
| 438 | + return true; |
| 439 | + } |
444 | 440 |
|
445 | | - return false; |
| 441 | + return false; |
| 442 | + }) !== null; |
446 | 443 | } |
447 | 444 |
|
448 | 445 | private static function isSpecified(Scope $scope, Expr $node, Expr $expr): bool |
|
0 commit comments