File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1276,4 +1276,9 @@ public function testBug9494(): void
12761276 $ this ->analyse ([__DIR__ . '/data/bug-9494.php ' ], []);
12771277 }
12781278
1279+ public function testBug8438 (): void
1280+ {
1281+ $ this ->analyse ([__DIR__ . '/data/bug-8438.php ' ], []);
1282+ }
1283+
12791284}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug8438 ;
4+
5+ class HelloWorld
6+ {
7+ /**
8+ * @param array<string, string> $array
9+ *
10+ * @return array{expr: mixed, ...}
11+ */
12+ protected function foo (array $ array ): array
13+ {
14+ $ rnd = mt_rand ();
15+ if ($ rnd === 0 ) {
16+ return ['expr ' => 'test ' ];
17+ } elseif ($ rnd === 1 ) {
18+ // no error with checkBenevolentUnionTypes: false (default even with l9 + strict rules)
19+ return ['expr ' => 'test ' , 1 => 'ok ' ];
20+ } else {
21+ // phpstan must understand 'expr' key is always present in the result,
22+ // then there will be no error here neither
23+ return array_merge ($ array , ['expr ' => 'test ' , 1 => 'ok ' ]);
24+ }
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments