diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index f1dfb1f0da6..03348429ffd 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -3431,13 +3431,19 @@ private function intersectConditionalExpressions(array $otherConditionalExpressi } $otherHolders = $otherConditionalExpressions[$exprString]; - foreach (array_keys($holders) as $key) { + $intersectedHolders = []; + foreach ($holders as $key => $holder) { if (!array_key_exists($key, $otherHolders)) { - continue 2; + continue; } + $intersectedHolders[$key] = $holder; + } + + if (count($intersectedHolders) === 0) { + continue; } - $newConditionalExpressions[$exprString] = $holders; + $newConditionalExpressions[$exprString] = $intersectedHolders; } return $newConditionalExpressions; diff --git a/tests/.claude/settings.local.json b/tests/.claude/settings.local.json new file mode 100644 index 00000000000..e2dbcb4a3be --- /dev/null +++ b/tests/.claude/settings.local.json @@ -0,0 +1,7 @@ +{ + "permissions": { + "allow": [ + "WebFetch(domain:phpbench.readthedocs.io)" + ] + } +} diff --git a/tests/PHPStan/Analyser/nsrt/bug-14269.php b/tests/PHPStan/Analyser/nsrt/bug-14269.php new file mode 100644 index 00000000000..1ad889a67d5 --- /dev/null +++ b/tests/PHPStan/Analyser/nsrt/bug-14269.php @@ -0,0 +1,60 @@ +isMultiDay()) { + $packageDurationInMinutes = 60; + } + + foreach ($package->getWorkspaces() as $workplace) { + $availableIntervals = $s->subtract(); + if ($package->getService() !== null && !$package->isMultiDay()) { + assertVariableCertainty(TrinaryLogic::createYes(), $packageDurationInMinutes); + continue; + } + + $availableIntervals = $package->isMultiDay() + ? 'aaa' + : 'bbb'; + } +} diff --git a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php index a4e07cd0ff7..79b7b484e13 100644 --- a/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php @@ -201,4 +201,16 @@ public function testBug7699(): void $this->analyse([__DIR__ . '/data/bug-7699.php'], []); } + public function testBug4284(): void + { + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-4284.php'], [ + [ + 'If condition is always true.', + 25, + 'Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.', + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-4284.php b/tests/PHPStan/Rules/Comparison/data/bug-4284.php new file mode 100644 index 00000000000..4fba5d59916 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-4284.php @@ -0,0 +1,30 @@ +