File tree Expand file tree Collapse file tree
tests/PHPStan/Rules/DeadCode Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,4 +159,38 @@ public function testPhp8(): void
159159 ]);
160160 }
161161
162+ public function testBug12789 (): void
163+ {
164+ $ this ->analyse ([__DIR__ . '/data/bug-12789.php ' ], [
165+ [
166+ 'Value assigned to variable $RetVal is never read. ' ,
167+ 12 ,
168+ ],
169+ ]);
170+ }
171+
172+ public function testBug13472 (): void
173+ {
174+ $ this ->analyse ([__DIR__ . '/data/bug-13472.php ' ], [
175+ [
176+ 'Value assigned to variable $v is never read. ' ,
177+ 14 ,
178+ ],
179+ [
180+ 'Value assigned to variable $item is never read. ' ,
181+ 41 ,
182+ ],
183+ ]);
184+ }
185+
186+ public function testBug14258 (): void
187+ {
188+ $ this ->analyse ([__DIR__ . '/data/bug-14258.php ' ], [
189+ [
190+ 'Value assigned to variable $cutsomerId is never read. ' ,
191+ 15 ,
192+ ],
193+ ]);
194+ }
195+
162196}
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug12789 ;
4+
5+ class HelloWorld
6+ {
7+ public function concat (string $ str1 , string $ str2 ): string
8+ {
9+ $ retVal = $ str1 . $ str2 ;
10+ if (strlen ($ retVal ) > 4 ) {
11+ // Typo in next line - should be $retVal rather than $RetVal
12+ $ RetVal = $ str2 . $ str1 ;
13+ }
14+ return $ retVal ;
15+ }
16+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug13472 ;
4+
5+ use function PHPStan \dumpType ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ class Foo
9+ {
10+ public function dummyConsume (int $ v ): void {}
11+
12+ public function testOverwrittenAndUnused (): int
13+ {
14+ $ v = 1 ; // this assign should be reported
15+ $ v = 2 ;
16+
17+ return $ v ;
18+ }
19+
20+ public function testOverwrittenButUsed (): int
21+ {
22+ $ v = 1 ;
23+ $ this ->dummyConsume ($ v );
24+ $ v = 10 ;
25+
26+ return $ v ;
27+ }
28+
29+ public function testOverwrittenButUsed2 (): int
30+ {
31+ $ v = 1 ;
32+ $ v = $ v + 1 ;
33+
34+ return $ v ;
35+ }
36+
37+ /** @param list<string> $possiblyEmptyList */
38+ public function testOverwrittenButUsed3 (array $ possiblyEmptyList ): int
39+ {
40+ $ v = 1 ;
41+ foreach ($ possiblyEmptyList as $ item ) {
42+ $ v = 2 ;
43+ }
44+
45+ return $ v ;
46+ }
47+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace Bug14258 ;
4+
5+ use function PHPStan \dumpType ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ class HelloWorld
9+ {
10+ public function getCustomerId (bool $ b ): string
11+ {
12+ $ customerId = 'z ' ;
13+ if ($ b ) {
14+ // typo: fails to override the ID
15+ $ cutsomerId = 'x ' ;
16+ }
17+ return $ customerId ;
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments