|
5 | 5 | use LogicException;
|
6 | 6 | use PHPStan\PhpDocParser\Ast;
|
7 | 7 | use PHPStan\PhpDocParser\Lexer\Lexer;
|
| 8 | +use function in_array; |
8 | 9 | use function strpos;
|
9 | 10 | use function trim;
|
10 | 11 |
|
@@ -123,8 +124,8 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
|
123 | 124 | } elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
124 | 125 | $type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
125 | 126 |
|
126 |
| - } elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) { |
127 |
| - $type = $this->parseArrayShape($tokens, $type); |
| 127 | + } elseif (in_array($type->name, ['array', 'list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) { |
| 128 | + $type = $this->parseArrayShape($tokens, $type, $type->name); |
128 | 129 |
|
129 | 130 | if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
130 | 131 | $type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
@@ -439,8 +440,8 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
|
439 | 440 | if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
|
440 | 441 | $type = $this->parseGeneric($tokens, $type);
|
441 | 442 |
|
442 |
| - } elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) { |
443 |
| - $type = $this->parseArrayShape($tokens, $type); |
| 443 | + } elseif (in_array($type->name, ['array', 'list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) { |
| 444 | + $type = $this->parseArrayShape($tokens, $type, $type->name); |
444 | 445 | }
|
445 | 446 | }
|
446 | 447 |
|
@@ -499,8 +500,11 @@ private function tryParseArrayOrOffsetAccess(TokenIterator $tokens, Ast\Type\Typ
|
499 | 500 | }
|
500 | 501 |
|
501 | 502 |
|
502 |
| - /** @phpstan-impure */ |
503 |
| - private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type): Ast\Type\ArrayShapeNode |
| 503 | + /** |
| 504 | + * @phpstan-impure |
| 505 | + * @param Ast\Type\ArrayShapeNode::KIND_* $kind |
| 506 | + */ |
| 507 | + private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type, string $kind): Ast\Type\ArrayShapeNode |
504 | 508 | {
|
505 | 509 | $tokens->consumeTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET);
|
506 | 510 |
|
@@ -528,7 +532,7 @@ private function parseArrayShape(TokenIterator $tokens, Ast\Type\TypeNode $type)
|
528 | 532 | $tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
|
529 | 533 | $tokens->consumeTokenType(Lexer::TOKEN_CLOSE_CURLY_BRACKET);
|
530 | 534 |
|
531 |
| - return new Ast\Type\ArrayShapeNode($items, $sealed); |
| 535 | + return new Ast\Type\ArrayShapeNode($items, $sealed, $kind); |
532 | 536 | }
|
533 | 537 |
|
534 | 538 |
|
|
0 commit comments