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 44500ca

Browse files
Andreas Frömerondrejmirtes
Andreas Frömer
authored andcommitted
Add support for trailing comma
1 parent 9efbbb6 commit 44500ca

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

‎src/Parser/TypeParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,15 @@ public function parseGeneric(TokenIterator $tokens, Ast\Type\IdentifierTypeNode
167167
$tokens->consumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET);
168168
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
169169
$genericTypes = [$this->parse($tokens)];
170-
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
170+
171+
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
171172

172173
while ($tokens->tryConsumeTokenType(Lexer::TOKEN_COMMA)) {
173174
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
175+
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_CLOSE_ANGLE_BRACKET)) {
176+
// trailing comma case
177+
return new Ast\Type\GenericTypeNode($baseType, $genericTypes);
178+
}
174179
$genericTypes[] = $this->parse($tokens);
175180
$tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL);
176181
}

‎tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,29 +3079,6 @@ public function provideRealWorldExampleData(): \Iterator
30793079
]),
30803080
];
30813081

3082-
// yield [
3083-
// 'multiline generic types - trailing comma',
3084-
// '/**' . PHP_EOL .
3085-
// ' * @implements Foo<' . PHP_EOL .
3086-
// ' * A,' . PHP_EOL .
3087-
// ' * >' . PHP_EOL .
3088-
// ' */',
3089-
// new PhpDocNode([
3090-
// new PhpDocTagNode(
3091-
// '@implements',
3092-
// new ImplementsTagValueNode(
3093-
// new GenericTypeNode(
3094-
// new IdentifierTypeNode('Foo'),
3095-
// [
3096-
// new IdentifierTypeNode('A'),
3097-
// ]
3098-
// ),
3099-
// ''
3100-
// )
3101-
// ),
3102-
// ]),
3103-
// ];
3104-
31053082
yield [
31063083
'multiline generic types - leading comma',
31073084
'/**' . PHP_EOL .
@@ -3126,6 +3103,31 @@ public function provideRealWorldExampleData(): \Iterator
31263103
),
31273104
]),
31283105
];
3106+
3107+
yield [
3108+
'multiline generic types - traling comma',
3109+
'/**' . PHP_EOL .
3110+
' * @implements Foo<' . PHP_EOL .
3111+
' * A,' . PHP_EOL .
3112+
' * B,' . PHP_EOL .
3113+
' * >' . PHP_EOL .
3114+
' */',
3115+
new PhpDocNode([
3116+
new PhpDocTagNode(
3117+
'@implements',
3118+
new ImplementsTagValueNode(
3119+
new GenericTypeNode(
3120+
new IdentifierTypeNode('Foo'),
3121+
[
3122+
new IdentifierTypeNode('A'),
3123+
new IdentifierTypeNode('B'),
3124+
]
3125+
),
3126+
''
3127+
)
3128+
),
3129+
]),
3130+
];
31293131
}
31303132

31313133
public function dataParseTagValue(): array

‎tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ public function provideParseData(): array
899899
new ConstTypeNode(new ConstFetchNode('QueueAttributeName', '*')),
900900
]),
901901
],
902-
[
902+
[
903903
'array<' . PHP_EOL .
904904
' Foo' . PHP_EOL .
905905
'>',
@@ -955,6 +955,26 @@ public function provideParseData(): array
955955
]
956956
),
957957
],
958+
[
959+
'array<' . PHP_EOL .
960+
' Foo,' . PHP_EOL .
961+
' array<' . PHP_EOL .
962+
' Bar,' . PHP_EOL .
963+
' >' . PHP_EOL .
964+
'>',
965+
new GenericTypeNode(
966+
new IdentifierTypeNode('array'),
967+
[
968+
new IdentifierTypeNode('Foo'),
969+
new GenericTypeNode(
970+
new IdentifierTypeNode('array'),
971+
[
972+
new IdentifierTypeNode('Bar'),
973+
]
974+
),
975+
]
976+
),
977+
],
958978
];
959979
}
960980

0 commit comments

Comments
(0)

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