|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Analyser\Generator\StmtHandler; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use PhpParser\Node\Stmt; |
| 7 | +use PhpParser\Node\Stmt\Echo_; |
| 8 | +use PHPStan\Analyser\ExpressionContext; |
| 9 | +use PHPStan\Analyser\Generator\ExprAnalysisRequest; |
| 10 | +use PHPStan\Analyser\Generator\GeneratorScope; |
| 11 | +use PHPStan\Analyser\Generator\StmtAnalysisResult; |
| 12 | +use PHPStan\Analyser\Generator\StmtHandler; |
| 13 | +use PHPStan\Analyser\ImpurePoint; |
| 14 | +use PHPStan\Analyser\StatementContext; |
| 15 | +use PHPStan\DependencyInjection\AutowiredService; |
| 16 | +use function array_merge; |
| 17 | + |
| 18 | +/** |
| 19 | + * @implements StmtHandler<Echo_> |
| 20 | + */ |
| 21 | +#[AutowiredService] |
| 22 | +final class EchoHandler implements StmtHandler |
| 23 | +{ |
| 24 | + |
| 25 | + public function supports(Stmt $stmt): bool |
| 26 | + { |
| 27 | + return $stmt instanceof Echo_; |
| 28 | + } |
| 29 | + |
| 30 | + public function analyseStmt(Stmt $stmt, GeneratorScope $scope, StatementContext $context, ?callable $alternativeNodeCallback): Generator |
| 31 | + { |
| 32 | + $hasYield = false; |
| 33 | + $throwPoints = []; |
| 34 | + $isAlwaysTerminating = false; |
| 35 | + foreach ($stmt->exprs as $echoExpr) { |
| 36 | + $result = yield new ExprAnalysisRequest($stmt, $echoExpr, $scope, ExpressionContext::createDeep(), $alternativeNodeCallback); |
| 37 | + $throwPoints = array_merge($throwPoints, $result->throwPoints); |
| 38 | + $scope = $result->scope; |
| 39 | + $hasYield = $hasYield || $result->hasYield; |
| 40 | + $isAlwaysTerminating = $isAlwaysTerminating || $result->isAlwaysTerminating; |
| 41 | + } |
| 42 | + |
| 43 | + return new StmtAnalysisResult( |
| 44 | + $scope, |
| 45 | + hasYield: $hasYield, |
| 46 | + isAlwaysTerminating: $isAlwaysTerminating, |
| 47 | + exitPoints: [], |
| 48 | + throwPoints: $throwPoints, |
| 49 | + impurePoints: [ |
| 50 | + new ImpurePoint($scope, $stmt, 'echo', 'echo', true), |
| 51 | + ], |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments