File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed
Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -784,7 +784,7 @@ private function processStmtNode(
784784 }
785785
786786 if ($ stmt ->else === null ) {
787- if (!$ ifAlwaysTrue ) {
787+ if (!$ ifAlwaysTrue && ! $ lastElseIfConditionIsTrue ) {
788788 $ finalScope = $ scope ->mergeWith ($ finalScope );
789789 $ alwaysTerminating = false ;
790790 }
Original file line number Diff line number Diff line change @@ -1165,6 +1165,7 @@ public function dataFileAsserts(): iterable
11651165 if (PHP_VERSION_ID >= 80000 ) {
11661166 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/pathinfo-php8.php ' );
11671167 }
1168+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/always-true-elseif.php ' );
11681169 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/pathinfo.php ' );
11691170 yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8568.php ' );
11701171 yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/DeadCode/data/bug-8620.php ' );
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace AlwaysTrueElseif ;
4+
5+ use PHPStan \TrinaryLogic ;
6+ use function PHPStan \Testing \assertVariableCertainty ;
7+
8+ class Foo
9+ {
10+
11+ /**
12+ * @param 'a'|'b'|'c' $s
13+ * @return void
14+ */
15+ public function doFoo (string $ s ): void
16+ {
17+ if ($ s === 'a ' ) {
18+ $ a = true ;
19+ } elseif ($ s === 'b ' ) {
20+ $ a = false ;
21+ } elseif ($ s === 'c ' ) {
22+ $ a = true ;
23+ }
24+
25+ assertVariableCertainty (TrinaryLogic::createYes (), $ a );
26+ }
27+
28+ }
You can’t perform that action at this time.
0 commit comments