Skip to content

Commit a361600

Browse files
committed
implement more cases
1 parent 3de6708 commit a361600

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
@@ -3289,7 +3289,7 @@ static function (): void {
32893289
return new ExpressionResult(
32903290
$leftMergedWithRightScope,
32913291
$leftResult->hasYield() || $rightResult->hasYield(),
3292-
false,
3292+
$leftResult->isAlwaysTerminating() || $rightResult->isAlwaysTerminating(),
32933293
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
32943294
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
32953295
static fn (): MutatingScope => $rightResult->getScope()->filterByTruthyValue($expr),
@@ -3310,7 +3310,7 @@ static function (): void {
33103310
return new ExpressionResult(
33113311
$leftMergedWithRightScope,
33123312
$leftResult->hasYield() || $rightResult->hasYield(),
3313-
false,
3313+
$leftResult->isAlwaysTerminating(),
33143314
array_merge($leftResult->getThrowPoints(), $rightResult->getThrowPoints()),
33153315
array_merge($leftResult->getImpurePoints(), $rightResult->getImpurePoints()),
33163316
static fn (): MutatingScope => $leftMergedWithRightScope->filterByTruthyValue($expr),
@@ -3335,7 +3335,7 @@ static function (): void {
33353335
$hasYield = $condResult->hasYield() || $rightResult->hasYield();
33363336
$throwPoints = array_merge($condResult->getThrowPoints(), $rightResult->getThrowPoints());
33373337
$impurePoints = array_merge($condResult->getImpurePoints(), $rightResult->getImpurePoints());
3338-
$isAlwaysTerminating = false;
3338+
$isAlwaysTerminating = $condResult->isAlwaysTerminating();
33393339
} elseif ($expr instanceof BinaryOp) {
33403340
$result = $this->processExprNode($stmt, $expr->left, $scope, $nodeCallback, $context->enterDeep());
33413341
$scope = $result->getScope();
@@ -3368,7 +3368,7 @@ static function (): void {
33683368
true,
33693369
);
33703370
$hasYield = $result->hasYield();
3371-
$isAlwaysTerminating = false;
3371+
$isAlwaysTerminating = $result->isAlwaysTerminating();
33723372
$scope = $result->getScope()->afterExtractCall();
33733373
} elseif ($expr instanceof Expr\Print_) {
33743374
$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)