File tree Expand file tree Collapse file tree 3 files changed +81
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 3 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,9 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
8989
9090 if (count ($ functionCall ->getArgs ()) > $ replaceArgumentPosition ) {
9191 $ replaceArgumentType = $ scope ->getType ($ functionCall ->getArgs ()[$ replaceArgumentPosition ]->value );
92+ if ($ replaceArgumentType ->isArray ()->yes ()) {
93+ $ replaceArgumentType = $ replaceArgumentType ->getIterableValueType ();
94+ }
9295
9396 $ accessories = [];
9497 if ($ subjectArgumentType ->isNonFalsyString ()->yes () && $ replaceArgumentType ->isNonFalsyString ()->yes ()) {
Original file line number Diff line number Diff line change @@ -1246,4 +1246,14 @@ public function testBug4443(): void
12461246 ]);
12471247 }
12481248
1249+ public function testBug12928 (): void
1250+ {
1251+ $ this ->analyse ([__DIR__ . '/data/bug-12928.php ' ], [
1252+ [
1253+ 'Method Bug12928\FooBarBaz::render() should return non-empty-string but returns string. ' ,
1254+ 59 ,
1255+ ],
1256+ ]);
1257+ }
1258+
12491259}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug12928 ;
4+
5+ class Foo {
6+ /**
7+ * @param non-empty-string $phptFile
8+ * @param non-empty-string $code
9+ *
10+ * @return non-empty-string
11+ */
12+ public function render (string $ phptFile , string $ code ): string
13+ {
14+ return str_replace (
15+ [
16+ '__DIR__ ' ,
17+ '__FILE__ ' ,
18+ ],
19+ [
20+ "' " . dirname ($ phptFile ) . "' " ,
21+ "' " . $ phptFile . "' " ,
22+ ],
23+ $ code ,
24+ );
25+ }
26+ }
27+
28+ class FooBar {
29+ /**
30+ * @param non-empty-string $phptFile
31+ * @param non-falsy-string $code
32+ * @param array<non-falsy-string> $replace
33+ *
34+ * @return non-falsy-string
35+ */
36+ public function render (string $ code , array $ replace ): string
37+ {
38+ return str_replace (
39+ [
40+ '__DIR__ ' ,
41+ '__FILE__ ' ,
42+ ],
43+ $ replace ,
44+ $ code ,
45+ );
46+ }
47+ }
48+
49+
50+ class FooBarBaz {
51+ /**
52+ * @param non-empty-string $phptFile
53+ * @param non-empty-string $code
54+ *
55+ * @return non-empty-string
56+ */
57+ public function render (string $ code , array $ replace ): string
58+ {
59+ return str_replace (
60+ [
61+ '__DIR__ ' ,
62+ '__FILE__ ' ,
63+ ],
64+ $ replace ,
65+ $ code ,
66+ );
67+ }
68+ }
You can’t perform that action at this time.
0 commit comments