File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -1155,6 +1155,7 @@ public function dataFileAsserts(): iterable
1155
1155
}
1156
1156
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/pathinfo.php ' );
1157
1157
yield from $ this ->gatherAssertTypes (__DIR__ . '/data/bug-8568.php ' );
1158
+ yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/DeadCode/data/bug-8620.php ' );
1158
1159
}
1159
1160
1160
1161
/**
Original file line number Diff line number Diff line change @@ -131,4 +131,10 @@ public function testBug7188(): void
131
131
]);
132
132
}
133
133
134
+ public function testBug8620 (): void
135
+ {
136
+ $ this ->treatPhpDocTypesAsCertain = true ;
137
+ $ this ->analyse ([__DIR__ . '/data/bug-8620.php ' ], []);
138
+ }
139
+
134
140
}
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace Bug8620 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ class HelloWorld
8
+ {
9
+ public function nullCoalesceAndConcatenation (?int $ a = null ): int
10
+ {
11
+ $ key = ($ a ?? "x " ) . "- " ;
12
+ assertType ('non-falsy-string ' , $ key );
13
+ if ($ key === "x- " ) { return 0 ; }
14
+
15
+ return 1 ;
16
+ }
17
+
18
+ public function nullCoalesce (?int $ a = null ): int
19
+ {
20
+ $ key = ($ a ?? "" );
21
+ assertType ("''|int " , $ key );
22
+ if ($ key === "" ) { return 0 ; }
23
+
24
+ return 1 ;
25
+ }
26
+
27
+ public function nullCheck (?int $ a = null ): int
28
+ {
29
+ if (is_null ($ a )) { return 0 ; }
30
+
31
+ return 1 ;
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments