mirror of
https://github.com/danog/phpdoc-parser.git
synced 2024-11-26 12:04:52 +01:00
Add support for strict arrays and list shapes
This commit is contained in:
parent
066f9d07ee
commit
7978df2946
@ -5,6 +5,7 @@ namespace PHPStan\PhpDocParser\Parser;
|
||||
use LogicException;
|
||||
use PHPStan\PhpDocParser\Ast;
|
||||
use PHPStan\PhpDocParser\Lexer\Lexer;
|
||||
use function in_array;
|
||||
use function strpos;
|
||||
use function trim;
|
||||
|
||||
@ -123,7 +124,7 @@ class TypeParser
|
||||
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
||||
$type = $this->tryParseArrayOrOffsetAccess($tokens, $type);
|
||||
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
} elseif (in_array($type->name, ['array', 'list', 'strict-array', 'strict-list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
$type = $this->parseArrayShape($tokens, $type);
|
||||
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
||||
@ -409,7 +410,7 @@ class TypeParser
|
||||
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
|
||||
$type = $this->parseGeneric($tokens, $type);
|
||||
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
} elseif (in_array($type->name, ['array', 'list', 'strict-array', 'strict-list'], true) && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
$type = $this->parseArrayShape($tokens, $type);
|
||||
}
|
||||
}
|
||||
|
@ -592,6 +592,60 @@ class TypeParserTest extends TestCase
|
||||
),
|
||||
]),
|
||||
],
|
||||
[
|
||||
'strict-array{
|
||||
a: int,
|
||||
b: string
|
||||
}',
|
||||
new ArrayShapeNode([
|
||||
new ArrayShapeItemNode(
|
||||
new IdentifierTypeNode('a'),
|
||||
false,
|
||||
new IdentifierTypeNode('int')
|
||||
),
|
||||
new ArrayShapeItemNode(
|
||||
new IdentifierTypeNode('b'),
|
||||
false,
|
||||
new IdentifierTypeNode('string')
|
||||
),
|
||||
]),
|
||||
],
|
||||
[
|
||||
'strict-list{
|
||||
int,
|
||||
string
|
||||
}',
|
||||
new ArrayShapeNode([
|
||||
new ArrayShapeItemNode(
|
||||
null,
|
||||
false,
|
||||
new IdentifierTypeNode('int')
|
||||
),
|
||||
new ArrayShapeItemNode(
|
||||
null,
|
||||
false,
|
||||
new IdentifierTypeNode('string')
|
||||
),
|
||||
]),
|
||||
],
|
||||
[
|
||||
'list{
|
||||
int,
|
||||
string
|
||||
}',
|
||||
new ArrayShapeNode([
|
||||
new ArrayShapeItemNode(
|
||||
null,
|
||||
false,
|
||||
new IdentifierTypeNode('int')
|
||||
),
|
||||
new ArrayShapeItemNode(
|
||||
null,
|
||||
false,
|
||||
new IdentifierTypeNode('string')
|
||||
),
|
||||
]),
|
||||
],
|
||||
[
|
||||
'callable(): Foo',
|
||||
new CallableTypeNode(
|
||||
|
Loading…
Reference in New Issue
Block a user