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(
784
784
}
785
785
786
786
if ($ stmt ->else === null ) {
787
- if (!$ ifAlwaysTrue ) {
787
+ if (!$ ifAlwaysTrue && ! $ lastElseIfConditionIsTrue ) {
788
788
$ finalScope = $ scope ->mergeWith ($ finalScope );
789
789
$ alwaysTerminating = false ;
790
790
}
Original file line number Diff line number Diff line change @@ -1165,6 +1165,7 @@ public function dataFileAsserts(): iterable
1165
1165
if (PHP_VERSION_ID >= 80000 ) {
1166
1166
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/pathinfo-php8.php ' );
1167
1167
}
1168
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/data/always-true-elseif.php ' );
1168
1169
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/pathinfo.php ' );
1169
1170
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8568.php ' );
1170
1171
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