Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 03768b2

Browse files
Disallow whitespaces between 'array' and '{'
1 parent e8fa232 commit 03768b2

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

‎src/Parser/TokenIterator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public function isCurrentTokenType(int $tokenType): bool
6464
}
6565

6666

67+
public function isPrecededByHorizontalWhitespace(): bool
68+
{
69+
return ($this->tokens[$this->index - 1][Lexer::TYPE_OFFSET] ?? -1) === Lexer::TOKEN_HORIZONTAL_WS;
70+
}
71+
6772
/**
6873
* @param int $tokenType
6974
* @throws \PHPStan\PhpDocParser\Parser\ParserException

‎src/Parser/TypeParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function parseAtomic(TokenIterator $tokens): Ast\Type\TypeNode
5454
} elseif ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_SQUARE_BRACKET)) {
5555
$type = $this->tryParseArray($tokens, $type);
5656

57-
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) {
57+
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
5858
$type = $this->parseArrayShape($tokens, $type);
5959
}
6060
}
@@ -97,7 +97,7 @@ private function parseNullable(TokenIterator $tokens): Ast\Type\TypeNode
9797
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
9898
$type = $this->parseGeneric($tokens, $type);
9999

100-
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) {
100+
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
101101
$type = $this->parseArrayShape($tokens, $type);
102102
}
103103

@@ -174,7 +174,7 @@ private function parseCallableReturnType(TokenIterator $tokens): Ast\Type\TypeNo
174174
if ($tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)) {
175175
$type = $this->parseGeneric($tokens, $type);
176176

177-
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET)) {
177+
} elseif ($type->name === 'array' && $tokens->isCurrentTokenType(Lexer::TOKEN_OPEN_CURLY_BRACKET) && !$tokens->isPrecededByHorizontalWhitespace()) {
178178
$type = $this->parseArrayShape($tokens, $type);
179179
}
180180
}

‎tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ public function provideParseData(): array
268268
]
269269
),
270270
],
271+
[
272+
'array {\'a\': int}',
273+
new IdentifierTypeNode('array'),
274+
Lexer::TOKEN_OPEN_CURLY_BRACKET,
275+
],
276+
271277
[
272278
'array{\'a\': int}',
273279
new ArrayShapeNode([

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /