File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -1184,6 +1184,12 @@ public function testBug5091(): void
11841184 $ this ->assertNoErrors ($ errors );
11851185 }
11861186
1187+ public function testBug9346 (): void
1188+ {
1189+ $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-9346.php ' );
1190+ $ this ->assertNoErrors ($ errors );
1191+ }
1192+
11871193 public function testBug9459 (): void
11881194 {
11891195 $ errors = $ this ->runAnalyse (__DIR__ . '/data/bug-9459.php ' );
Original file line number Diff line number Diff line change @@ -181,6 +181,8 @@ public function dataFileAsserts(): iterable
181181 yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/Methods/data/bug-9542.php ' );
182182 yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/Functions/data/bug-9803.php ' );
183183 yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/PhpDoc/data/bug-10594.php ' );
184+
185+ yield from $ this ->gatherAssertTypes (__DIR__ . '/../Rules/Methods/data/bug-9346.php ' );
184186 }
185187
186188 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug9346 ;
4+
5+ use DateTime ;
6+
7+ /**
8+ * @phpstan-type MyType array{
9+ * key?: string,
10+ * }
11+ */
12+ class Test
13+ {
14+ /**
15+ * @param MyType $params
16+ */
17+ public function create (array $ params = []): object
18+ {
19+ return new class ($ params ) {
20+ /**
21+ * @param MyType $params
22+ */
23+ public function __construct (private array $ params )
24+ {
25+ }
26+ };
27+ }
28+ }
29+
30+ /**
31+ * @phpstan-type FooJson array{bar: string}
32+ */
33+ interface Foo
34+ {
35+ /**
36+ * @phpstan-return FooJson
37+ */
38+ public function sayHello (DateTime $ date ): array ;
39+ }
40+
41+ /**
42+ * @phpstan-import-type FooJson from Foo
43+ */
44+ class HelloWorld
45+ {
46+ public function createFoo (): Foo
47+ {
48+ $ foo = new class () implements Foo {
49+ /**
50+ * @phpstan-var FooJson $var
51+ */
52+ private array $ var = ['bar ' => 'baz ' ];
53+
54+ /**
55+ * @phpstan-return FooJson
56+ */
57+ public function sayHello (DateTime $ date ): array
58+ {
59+ return $ this ->var ;
60+ }
61+ };
62+ return $ foo ;
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments