Skip to content

Commit 560aa0c

Browse files
committed
implement more cases
1 parent 5696c88 commit 560aa0c

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,7 @@ static function (): void {
32873287
return new ExpressionResult(
32883288
$leftMergedWithRightScope,
32893289
$leftResult->hasYield() || $rightResult->hasYield(),
3290-
false,
3290+
$leftResult->isAlwaysTerminating() || $rightResult->isAlwaysTerminating(),
32913291
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32923292
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32933293
static fn (): MutatingScope => $rightResult->getScope()->filterByTruthyValue($expr),
@@ -3308,7 +3308,7 @@ static function (): void {
33083308
return new ExpressionResult(
33093309
$leftMergedWithRightScope,
33103310
$leftResult->hasYield() || $rightResult->hasYield(),
3311-
false,
3311+
$leftResult->isAlwaysTerminating(),
33123312
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
33133313
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
33143314
static fn (): MutatingScope => $leftMergedWithRightScope->filterByTruthyValue($expr),
@@ -3333,7 +3333,7 @@ static function (): void {
33333333
$hasYield = $condResult->hasYield() || $rightResult->hasYield();
33343334
$throwPoints = array_merge($condResult->getThrowPoints(), $rightResult->getThrowPoints());
33353335
$impurePoints = array_merge($condResult->getImpurePoints(), $rightResult->getImpurePoints());
3336-
$isAlwaysTerminating = false;
3336+
$isAlwaysTerminating = $condResult->isAlwaysTerminating();
33373337
} elseif ($expr instanceof BinaryOp) {
33383338
$result = $this->processExprNode($stmt, $expr->left, $scope, $nodeCallback, $context->enterDeep());
33393339
$scope = $result->getScope();
@@ -3366,7 +3366,7 @@ static function (): void {
33663366
true,
33673367
);
33683368
$hasYield = $result->hasYield();
3369-
$isAlwaysTerminating = false;
3369+
$isAlwaysTerminating = $result->isAlwaysTerminating();
33703370
$scope = $result->getScope()->afterExtractCall();
33713371
} elseif ($expr instanceof Expr\Print_) {
33723372
$result = $this->processExprNode($stmt, $expr->expr, $scope, $nodeCallback, $context->enterDeep());

tests/PHPStan/Analyser/ExpressionResultTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public static function dataIsAlwaysTerminating(): array
3838
'(string) $x;',
3939
false,
4040
],
41+
[
42+
'$x || exit();',
43+
false,
44+
],
45+
[
46+
'$x ?? exit();',
47+
false,
48+
],
4149
[
4250
'sprintf("hello %s", exit());',
4351
true,
@@ -78,6 +86,22 @@ public static function dataIsAlwaysTerminating(): array
7886
'@exit();',
7987
true,
8088
],
89+
[
90+
'$x && exit();',
91+
true,
92+
],
93+
[
94+
'exit() && $x;',
95+
true,
96+
],
97+
[
98+
'exit() || $x;',
99+
true,
100+
],
101+
[
102+
'exit() ?? $x;',
103+
true,
104+
],
81105
];
82106
}
83107

0 commit comments

Comments
 (0)