|
6 | 6 | use Generator; |
7 | 7 | use PhpParser\Node; |
8 | 8 | use PhpParser\Node\Expr; |
| 9 | +use PhpParser\Node\Expr\FuncCall; |
| 10 | +use PhpParser\Node\Expr\MethodCall; |
| 11 | +use PhpParser\Node\Expr\New_; |
| 12 | +use PhpParser\Node\Expr\StaticCall; |
9 | 13 | use PhpParser\Node\Stmt; |
| 14 | +use PhpParser\Node\Stmt\Class_; |
10 | 15 | use PHPStan\Analyser\ExpressionContext; |
11 | 16 | use PHPStan\Analyser\Generator\NodeHandler\AttrGroupsHandler; |
12 | 17 | use PHPStan\Analyser\Generator\NodeHandler\StmtsHandler; |
13 | 18 | use PHPStan\Analyser\Scope; |
14 | 19 | use PHPStan\Analyser\StatementContext; |
15 | 20 | use PHPStan\DependencyInjection\Container; |
16 | 21 | use PHPStan\NeverException; |
| 22 | +use PHPStan\Node\FunctionCallableNode; |
| 23 | +use PHPStan\Node\InstantiationCallableNode; |
| 24 | +use PHPStan\Node\MethodCallableNode; |
17 | 25 | use PHPStan\Node\Printer\ExprPrinter; |
| 26 | +use PHPStan\Node\StaticMethodCallableNode; |
18 | 27 | use PHPStan\ShouldNotHappenException; |
19 | 28 | use Throwable; |
20 | 29 | use function array_merge; |
@@ -422,6 +431,25 @@ private function analyseExpr(ExprAnalysisResultStorage $storage, Stmt $stmt, Exp |
422 | 431 | throw new ShouldNotHappenException(sprintf('Expr %s on line %d has already been analysed', $this->exprPrinter->printExpr($expr), $expr->getStartLine())); |
423 | 432 | } |
424 | 433 |
|
| 434 | + if ($expr instanceof Expr\CallLike && $expr->isFirstClassCallable()) { |
| 435 | + if ($expr instanceof FuncCall) { |
| 436 | + $newExpr = new FunctionCallableNode($expr->name, $expr); |
| 437 | + } elseif ($expr instanceof MethodCall) { |
| 438 | + $newExpr = new MethodCallableNode($expr->var, $expr->name, $expr); |
| 439 | + } elseif ($expr instanceof StaticCall) { |
| 440 | + $newExpr = new StaticMethodCallableNode($expr->class, $expr->name, $expr); |
| 441 | + } elseif ($expr instanceof New_ && !$expr->class instanceof Class_) { |
| 442 | + $newExpr = new InstantiationCallableNode($expr->class, $expr); |
| 443 | + } else { |
| 444 | + throw new ShouldNotHappenException(); |
| 445 | + } |
| 446 | + |
| 447 | + $exprGen = $this->analyseExpr($storage, $stmt, $newExpr, $scope, $context, $alternativeNodeCallback); |
| 448 | + yield from $exprGen; |
| 449 | + |
| 450 | + return $exprGen->getReturn(); |
| 451 | + } |
| 452 | + |
425 | 453 | yield new NodeCallbackRequest($expr, $context->isDeep() ? $scope->exitFirstLevelStatements() : $scope, $alternativeNodeCallback); |
426 | 454 |
|
427 | 455 | /** |
|
0 commit comments