|
25 | 25 | use phpDocumentor\Reflection\PseudoTypes\IntegerRange; |
26 | 26 | use phpDocumentor\Reflection\PseudoTypes\IntegerValue; |
27 | 27 | use phpDocumentor\Reflection\PseudoTypes\List_; |
| 28 | +use phpDocumentor\Reflection\PseudoTypes\ListShape; |
| 29 | +use phpDocumentor\Reflection\PseudoTypes\ListShapeItem; |
28 | 30 | use phpDocumentor\Reflection\PseudoTypes\LiteralString; |
29 | 31 | use phpDocumentor\Reflection\PseudoTypes\LowercaseString; |
30 | 32 | use phpDocumentor\Reflection\PseudoTypes\NegativeInteger; |
|
34 | 36 | use phpDocumentor\Reflection\PseudoTypes\NonEmptyString; |
35 | 37 | use phpDocumentor\Reflection\PseudoTypes\Numeric_; |
36 | 38 | use phpDocumentor\Reflection\PseudoTypes\NumericString; |
| 39 | +use phpDocumentor\Reflection\PseudoTypes\ObjectShape; |
| 40 | +use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem; |
37 | 41 | use phpDocumentor\Reflection\PseudoTypes\PositiveInteger; |
38 | 42 | use phpDocumentor\Reflection\PseudoTypes\StringValue; |
39 | 43 | use phpDocumentor\Reflection\PseudoTypes\TraitString; |
|
83 | 87 | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; |
84 | 88 | use PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode; |
85 | 89 | use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode; |
| 90 | +use PHPStan\PhpDocParser\Ast\Type\ObjectShapeItemNode; |
| 91 | +use PHPStan\PhpDocParser\Ast\Type\ObjectShapeNode; |
86 | 92 | use PHPStan\PhpDocParser\Ast\Type\OffsetAccessTypeNode; |
87 | 93 | use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; |
88 | 94 | use PHPStan\PhpDocParser\Ast\Type\TypeNode; |
@@ -236,10 +242,43 @@ public function createType(?TypeNode $type, Context $context): Type |
236 | 242 | ); |
237 | 243 |
|
238 | 244 | case ArrayShapeNode::class: |
239 | | - return new ArrayShape( |
| 245 | + switch ($type->kind) { |
| 246 | + case ArrayShapeNode::KIND_ARRAY: |
| 247 | + return new ArrayShape( |
| 248 | + ...array_map( |
| 249 | + function (ArrayShapeItemNode $item) use ($context): ArrayShapeItem { |
| 250 | + return new ArrayShapeItem( |
| 251 | + (string) $item->keyName, |
| 252 | + $this->createType($item->valueType, $context), |
| 253 | + $item->optional |
| 254 | + ); |
| 255 | + }, |
| 256 | + $type->items |
| 257 | + ) |
| 258 | + ); |
| 259 | + |
| 260 | + case ArrayShapeNode::KIND_LIST: |
| 261 | + return new ListShape( |
| 262 | + ...array_map( |
| 263 | + function (ArrayShapeItemNode $item) use ($context): ListShapeItem { |
| 264 | + return new ListShapeItem( |
| 265 | + null, |
| 266 | + $this->createType($item->valueType, $context), |
| 267 | + $item->optional |
| 268 | + ); |
| 269 | + }, |
| 270 | + $type->items |
| 271 | + ) |
| 272 | + ); |
| 273 | + |
| 274 | + default: |
| 275 | + throw new RuntimeException('Unsupported array shape kind'); |
| 276 | + } |
| 277 | + case ObjectShapeNode::class: |
| 278 | + return new ObjectShape( |
240 | 279 | ...array_map( |
241 | | - function (ArrayShapeItemNode $item) use ($context): ArrayShapeItem { |
242 | | - return new ArrayShapeItem( |
| 280 | + function (ObjectShapeItemNode $item) use ($context): ObjectShapeItem { |
| 281 | + return new ObjectShapeItem( |
243 | 282 | (string) $item->keyName, |
244 | 283 | $this->createType($item->valueType, $context), |
245 | 284 | $item->optional |
|
0 commit comments