mirror of
https://github.com/danog/phpdoc-parser.git
synced 2024-11-26 20:15:11 +01:00
Disallow whitespaces between 'array' and '{'
This commit is contained in:
parent
c6ffc4b4f1
commit
1e2a8ece06
@ -64,6 +64,12 @@ class TokenIterator
|
||||
}
|
||||
|
||||
|
||||
public function isPrecededByHorizontalWhitespace(): bool
|
||||
{
|
||||
return ($this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] ?? -1) === Lexer::TOKEN_HORIZONTAL_WS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $tokenType
|
||||
* @throws \PHPStan\PhpDocParser\Parser\ParserException
|
||||
|
@ -54,7 +54,7 @@ class TypeParser
|
||||
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
|
||||
$type = $this->tryParseArray($tokens, $type);
|
||||
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) {
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
$type = $this->parseArrayShape($tokens, $type);
|
||||
}
|
||||
}
|
||||
@ -97,7 +97,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)) {
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
$type = $this->parseArrayShape($tokens, $type);
|
||||
}
|
||||
|
||||
@ -174,7 +174,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)) {
|
||||
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
|
||||
$type = $this->parseArrayShape($tokens, $type);
|
||||
}
|
||||
}
|
||||
|
@ -268,6 +268,12 @@ class TypeParserTest extends \PHPUnit\Framework\TestCase
|
||||
]
|
||||
),
|
||||
],
|
||||
[
|
||||
'array {\'a\': int}',
|
||||
new IdentifierTypeNode('array'),
|
||||
Lexer::TOKEN_OPEN_CURLY_BRACKET,
|
||||
],
|
||||
|
||||
[
|
||||
'array{\'a\': int}',
|
||||
new ArrayShapeNode([
|
||||
|
Loading…
Reference in New Issue
Block a user