Skip to content

Commit 2d64aa6

Browse files
committed
Virtual TypeExprHandler
1 parent 4101283 commit 2d64aa6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\Generator\ExprHandler\Virtual;
4+
5+
use Generator;
6+
use PhpParser\Node\Expr;
7+
use PhpParser\Node\Stmt;
8+
use PHPStan\Analyser\ExpressionContext;
9+
use PHPStan\Analyser\Generator\ExprAnalysisResult;
10+
use PHPStan\Analyser\Generator\ExprHandler;
11+
use PHPStan\Analyser\Generator\GeneratorScope;
12+
use PHPStan\Analyser\SpecifiedTypes;
13+
use PHPStan\DependencyInjection\AutowiredService;
14+
use PHPStan\Node\Expr\TypeExpr;
15+
16+
/**
17+
* @implements ExprHandler<TypeExpr>
18+
*/
19+
#[AutowiredService]
20+
final class TypeExprHandler implements ExprHandler
21+
{
22+
23+
public function supports(Expr $expr): bool
24+
{
25+
return $expr instanceof TypeExpr;
26+
}
27+
28+
public function analyseExpr(Stmt $stmt, Expr $expr, GeneratorScope $scope, ExpressionContext $context, ?callable $alternativeNodeCallback): Generator
29+
{
30+
yield from [];
31+
return new ExprAnalysisResult(
32+
type: $expr->getExprType(),
33+
nativeType: $expr->getExprType(),
34+
scope: $scope,
35+
hasYield: false,
36+
isAlwaysTerminating: false,
37+
throwPoints: [],
38+
impurePoints: [],
39+
specifiedTruthyTypes: new SpecifiedTypes(),
40+
specifiedFalseyTypes: new SpecifiedTypes(),
41+
specifiedNullTypes: new SpecifiedTypes(),
42+
);
43+
}
44+
45+
}

0 commit comments

Comments
 (0)