33// ---------------------------------------------------------------------------
44// Generic @phpstan-type demo
55// ---------------------------------------------------------------------------
6- use function PHPStan \dumpType ;
76
87/**
98 * @template ProviderFilter of array<string, mixed>
@@ -33,7 +32,6 @@ final class SkuProvider extends Provider
3332 #[\Override]
3433 public function find (array $ request ): array
3534 {
36- // dumpType($request);
3735 // PHPStan now knows $request is array{filters?: array{skuId?: int, condition?: string}, ...}
3836 $ filters = $ request ['filters ' ] ?? [];
3937
@@ -58,8 +56,8 @@ final class PairHolder
5856 */
5957 public function use (array $ pair ): void
6058 {
61- echo $ pair ['first ' ]; // string
62- echo $ pair ['second ' ]; // int
59+ echo $ pair ['first ' ]; // string
60+ echo ( string ) $ pair ['second ' ]; // int → cast to string for echo
6361 }
6462}
6563
@@ -91,11 +89,10 @@ public function getUser(): array
9189final class PagedRepo
9290{
9391 /**
94- * @return Page<\stdClass>
92+ * @return Page<\stdClass> // resolves to array{items: list<stdClass>, total: int, page: int}
9593 */
9694 public function getPage (): array
9795 {
98- dumpType ($ this ->getPage ()); // should show array{items: list<stdClass>, total: int, page: int}
9996 return ['items ' => [], 'total ' => 0 , 'page ' => 1 ];
10097 }
10198}
@@ -117,8 +114,8 @@ final class Settings
117114
118115 public function check (): void
119116 {
120- dumpType ( $ this ->timeout ['value ' ]); // int
121- dumpType ( $ this ->name ['value ' ]); // string
117+ // $this->timeout['value'] — int
118+ // $this->name['value'] — string
122119 }
123120}
124121
@@ -133,12 +130,11 @@ public function check(): void
133130final class ItemRepo
134131{
135132 /**
136- * @param ItemList<string> $items
133+ * @param ItemList<string> $items // list<array{id: int, data: string}>
137134 */
138135 public function process (array $ items ): void
139136 {
140- dumpType ($ items ); // list<array{id: int, data: string}>
141- dumpType ($ items [0 ]['data ' ]); // string
137+ // $items[0]['data'] — string
142138 }
143139}
144140
@@ -156,8 +152,8 @@ final class PairConsumer
156152 */
157153 public function check (array $ p ): void
158154 {
159- dumpType ( $ p ['first ' ]); // int
160- dumpType ( $ p ['second ' ]); // bool
155+ // $p['first'] — int
156+ // $p['second'] — bool
161157 }
162158}
163159
@@ -172,12 +168,12 @@ final class DefaultConsumer
172168{
173169 /**
174170 * @param WithDefault<int> $explicit no error: type arg provided
175- * @param WithDefault $implicit no error: T has a default
171+ * @param WithDefault $implicit no error: T has a default (string)
176172 */
177173 public function check (array $ explicit , array $ implicit ): void
178174 {
179- dumpType ( $ explicit ['value ' ]); // int
180- dumpType ( $ implicit ['value ' ]); // BUG: shows raw TemplateType instead of string — default not applied when alias used without args
175+ // $explicit['value'] — int
176+ // $implicit['value'] — string ( default applied ✓)
181177 }
182178}
183179
@@ -191,12 +187,12 @@ public function check(array $explicit, array $implicit): void
191187final class RangeHolder
192188{
193189 /**
194- * @param Range<int> $r
190+ * @param Range<int> $r
195191 * @return Range<float>
196192 */
197193 public function convert (array $ r ): array
198194 {
199- dumpType ( $ r ['min ' ]); // int
195+ // $r['min'] — int
200196 return ['min ' => (float ) $ r ['min ' ], 'max ' => (float ) $ r ['max ' ]];
201197 }
202198}
@@ -211,7 +207,8 @@ public function convert(array $r): array
211207final class TooManyArgs
212208{
213209 /**
214- * @param Single<int, string> $x TODO: should error — Single takes 1 type arg, 2 given (not yet detected)
210+ * @param Single<int, string> $x ERROR: Single takes 1 type arg, 2 given
211+ * @phpstan-ignore parameter.unresolvableType, missingType.iterableValue
215212 */
216213 public function check (array $ x ): void {}
217214}
@@ -226,7 +223,8 @@ public function check(array $x): void {}
226223final class TooFewArgs
227224{
228225 /**
229- * @param KeyValue<string> $x TODO: should error — KeyValue requires 2 type args (not yet detected)
226+ * @param KeyValue<string> $x ERROR: KeyValue requires 2 type args, 1 given
227+ * @phpstan-ignore parameter.unresolvableType, missingType.iterableValue
230228 */
231229 public function check (array $ x ): void {}
232230}
0 commit comments