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 d579798

Browse files
rvanvelzenondrejmirtes
authored andcommitted
Require whitespace before description with limited start tokens
1 parent b75949e commit d579798

File tree

2 files changed

+72
-12
lines changed

2 files changed

+72
-12
lines changed

‎src/Parser/PhpDocParser.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ private function parseOptionalDescription(TokenIterator $tokens, bool $limitStar
474474

475475
$tokens->consumeTokenType(Lexer::TOKEN_OTHER); // will throw exception
476476
}
477+
478+
if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL) && !$tokens->isPrecededByHorizontalWhitespace()) {
479+
$tokens->consumeTokenType(Lexer::TOKEN_HORIZONTAL_WS); // will throw exception
480+
}
477481
}
478482

479483
return $this->parseText($tokens)->text;

‎tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,58 @@ public function provideReturnTagsData(): Iterator
13101310
),
13111311
]),
13121312
];
1313+
1314+
yield [
1315+
'OK variadic callable',
1316+
'/** @return \Closure(int ...$u, string): string */',
1317+
new PhpDocNode([
1318+
new PhpDocTagNode(
1319+
'@return',
1320+
new ReturnTagValueNode(
1321+
new CallableTypeNode(
1322+
new IdentifierTypeNode('\Closure'),
1323+
[
1324+
new CallableTypeParameterNode(
1325+
new IdentifierTypeNode('int'),
1326+
false,
1327+
true,
1328+
'$u',
1329+
false
1330+
),
1331+
new CallableTypeParameterNode(
1332+
new IdentifierTypeNode('string'),
1333+
false,
1334+
false,
1335+
'',
1336+
false
1337+
),
1338+
],
1339+
new IdentifierTypeNode('string')
1340+
),
1341+
''
1342+
)
1343+
),
1344+
]),
1345+
];
1346+
1347+
yield [
1348+
'invalid variadic callable',
1349+
'/** @return \Closure(...int, string): string */',
1350+
new PhpDocNode([
1351+
new PhpDocTagNode(
1352+
'@return',
1353+
new InvalidTagValueNode(
1354+
'\Closure(...int, string): string',
1355+
new ParserException(
1356+
'(',
1357+
Lexer::TOKEN_OPEN_PARENTHESES,
1358+
20,
1359+
Lexer::TOKEN_HORIZONTAL_WS
1360+
)
1361+
)
1362+
),
1363+
]),
1364+
];
13131365
}
13141366

13151367

@@ -2104,10 +2156,14 @@ public function provideSingleLinePhpDocData(): Iterator
21042156
new PhpDocNode([
21052157
new PhpDocTagNode(
21062158
'@var',
2107-
new VarTagValueNode(
2108-
new IdentifierTypeNode('callable'),
2109-
'',
2110-
'(int)'
2159+
new InvalidTagValueNode(
2160+
'callable(int)',
2161+
new ParserException(
2162+
'(',
2163+
Lexer::TOKEN_OPEN_PARENTHESES,
2164+
17,
2165+
Lexer::TOKEN_HORIZONTAL_WS
2166+
)
21112167
)
21122168
),
21132169
]),
@@ -4076,14 +4132,14 @@ public function provideDescriptionWithOrWithoutHtml(): Iterator
40764132
new PhpDocNode([
40774133
new PhpDocTagNode(
40784134
'@return',
4079-
new ReturnTagValueNode(
4080-
newGenericTypeNode(
4081-
new IdentifierTypeNode('Foo'),
4082-
[
4083-
newIdentifierTypeNode('strong'),
4084-
]
4085-
),
4086-
'Important description'
4135+
new InvalidTagValueNode(
4136+
'Foo <strong>Important description',
4137+
new ParserException(
4138+
'Important',
4139+
Lexer::TOKEN_IDENTIFIER,
4140+
27,
4141+
Lexer::TOKEN_HORIZONTAL_WS
4142+
)
40874143
)
40884144
),
40894145
]),

0 commit comments

Comments
(0)

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