Skip to content

Commit 1bd36df

Browse files
committed
ErrorSuppressHandler
1 parent f3d7657 commit 1bd36df

2 files changed

Lines changed: 50 additions & 8 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\ExprHandler;
4+
5+
use PhpParser\Node\Expr;
6+
use PhpParser\Node\Expr\ErrorSuppress;
7+
use PhpParser\Node\Stmt;
8+
use PHPStan\Analyser\ExpressionContext;
9+
use PHPStan\Analyser\ExpressionResult;
10+
use PHPStan\Analyser\ExpressionResultStorage;
11+
use PHPStan\Analyser\ExprHandler;
12+
use PHPStan\Analyser\MutatingScope;
13+
use PHPStan\Analyser\NodeScopeResolver;
14+
use PHPStan\DependencyInjection\AutowiredService;
15+
16+
/**
17+
* @implements ExprHandler<ErrorSuppress>
18+
*/
19+
#[AutowiredService]
20+
final class ErrorSuppressHandler implements ExprHandler
21+
{
22+
23+
public function __construct(
24+
private NodeScopeResolver $nodeScopeResolver,
25+
)
26+
{
27+
}
28+
29+
public function supports(Expr $expr): bool
30+
{
31+
return $expr instanceof ErrorSuppress;
32+
}
33+
34+
public function processExpr(Stmt $stmt, Expr $expr, MutatingScope $scope, ExpressionResultStorage $storage, callable $nodeCallback, ExpressionContext $context): ExpressionResult
35+
{
36+
$result = $this->nodeScopeResolver->processExprNode($stmt, $expr->expr, $scope, $storage, $nodeCallback, $context);
37+
$scope = $result->getScope();
38+
39+
return new ExpressionResult(
40+
$scope,
41+
hasYield: $result->hasYield(),
42+
isAlwaysTerminating: $result->isAlwaysTerminating(),
43+
throwPoints: $result->getThrowPoints(),
44+
impurePoints: $result->getImpurePoints(),
45+
truthyScopeCallback: static fn (): MutatingScope => $scope->filterByTruthyValue($expr),
46+
falseyScopeCallback: static fn (): MutatingScope => $scope->filterByFalseyValue($expr),
47+
);
48+
}
49+
50+
}

‎src/Analyser/NodeScopeResolver.php‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
use PhpParser\Node\Expr\CallLike;
2626
use PhpParser\Node\Expr\Cast;
2727
use PhpParser\Node\Expr\ConstFetch;
28-
use PhpParser\Node\Expr\ErrorSuppress;
2928
use PhpParser\Node\Expr\Exit_;
3029
use PhpParser\Node\Expr\FuncCall;
3130
use PhpParser\Node\Expr\Instanceof_;
@@ -3614,13 +3613,6 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
36143613
[],
36153614
[],
36163615
);
3617-
} elseif ($expr instanceof ErrorSuppress) {
3618-
$result = $this->processExprNode($stmt, $expr->expr, $scope, $storage, $nodeCallback, $context);
3619-
$hasYield = $result->hasYield();
3620-
$throwPoints = $result->getThrowPoints();
3621-
$impurePoints = $result->getImpurePoints();
3622-
$isAlwaysTerminating = $result->isAlwaysTerminating();
3623-
$scope = $result->getScope();
36243616
} elseif ($expr instanceof Exit_) {
36253617
$hasYield = false;
36263618
$throwPoints = [];

0 commit comments

Comments
 (0)