|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Analyser\Generator\ExprHandler; |
| 4 | + |
| 5 | +use Generator; |
| 6 | +use PhpParser\Node\Expr; |
| 7 | +use PhpParser\Node\Stmt; |
| 8 | +use PHPStan\Analyser\ExpressionContext; |
| 9 | +use PHPStan\Analyser\Generator\ExprAnalysisRequest; |
| 10 | +use PHPStan\Analyser\Generator\ExprAnalysisResult; |
| 11 | +use PHPStan\Analyser\Generator\ExprHandler; |
| 12 | +use PHPStan\Analyser\Generator\GeneratorScope; |
| 13 | +use PHPStan\Analyser\SpecifiedTypes; |
| 14 | +use PHPStan\DependencyInjection\AutowiredService; |
| 15 | + |
| 16 | +/** |
| 17 | + * @implements ExprHandler<Expr\Cast\String_> |
| 18 | + */ |
| 19 | +#[AutowiredService] |
| 20 | +final class CastStringHandler implements ExprHandler |
| 21 | +{ |
| 22 | + |
| 23 | + public function supports(Expr $expr): bool |
| 24 | + { |
| 25 | + return $expr instanceof Expr\Cast\String_; |
| 26 | + } |
| 27 | + |
| 28 | + public function analyseExpr( |
| 29 | + Stmt $stmt, |
| 30 | + Expr $expr, |
| 31 | + GeneratorScope $scope, |
| 32 | + ExpressionContext $context, |
| 33 | + ?callable $alternativeNodeCallback, |
| 34 | + ): Generator |
| 35 | + { |
| 36 | + $exprResult = yield new ExprAnalysisRequest($stmt, $expr->expr, $scope, $context->enterDeep(), $alternativeNodeCallback); |
| 37 | + |
| 38 | + return new ExprAnalysisResult( |
| 39 | + $exprResult->type->toString(), |
| 40 | + $exprResult->nativeType->toString(), |
| 41 | + $scope, |
| 42 | + hasYield: false, |
| 43 | + isAlwaysTerminating: false, |
| 44 | + throwPoints: [], |
| 45 | + impurePoints: [], |
| 46 | + specifiedTruthyTypes: new SpecifiedTypes(), |
| 47 | + specifiedFalseyTypes: new SpecifiedTypes(), |
| 48 | + specifiedNullTypes: new SpecifiedTypes(), |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments