|
| 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\UnaryPlus> |
| 18 | + */ |
| 19 | +#[AutowiredService] |
| 20 | +final class UnaryPlusHandler implements ExprHandler |
| 21 | +{ |
| 22 | + |
| 23 | + public function supports(Expr $expr): bool |
| 24 | + { |
| 25 | + return $expr instanceof Expr\UnaryPlus; |
| 26 | + } |
| 27 | + |
| 28 | + public function analyseExpr(Stmt $stmt, Expr $expr, GeneratorScope $scope, ExpressionContext $context, ?callable $alternativeNodeCallback): Generator |
| 29 | + { |
| 30 | + $result = yield new ExprAnalysisRequest($stmt, $expr->expr, $scope, $context->enterDeep(), $alternativeNodeCallback); |
| 31 | + |
| 32 | + return new ExprAnalysisResult( |
| 33 | + $result->type->toNumber(), |
| 34 | + $result->nativeType->toNumber(), |
| 35 | + $result->scope, |
| 36 | + hasYield: $result->hasYield, |
| 37 | + isAlwaysTerminating: $result->isAlwaysTerminating, |
| 38 | + throwPoints: $result->throwPoints, |
| 39 | + impurePoints: $result->impurePoints, |
| 40 | + specifiedTruthyTypes: new SpecifiedTypes(), |
| 41 | + specifiedFalseyTypes: new SpecifiedTypes(), |
| 42 | + specifiedNullTypes: new SpecifiedTypes(), |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments