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