Skip to content

Commit 0601081

Browse files
committed
fix HTML description detection for phpstorm stubs
1 parent c2b8bbf commit 0601081

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Parser/TypeParser.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,16 @@ public function isHtml(TokenIterator $tokens): bool
380380
return false;
381381
}
382382

383+
$endTag = '</' . $htmlTagName . '>';
384+
$endTagSearchOffset = - strlen($endTag);
385+
383386
while (!$tokens->isCurrentTokenType(Lexer::TOKEN_END)) {
384387
if (
385-
$tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)
386-
&& strpos($tokens->currentTokenValue(), '/' . $htmlTagName . '>') !== false
388+
(
389+
$tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)
390+
&& strpos($tokens->currentTokenValue(), '/' . $htmlTagName . '>') !== false
391+
)
392+
|| substr_compare($tokens->currentTokenValue(), $endTag, $endTagSearchOffset) === 0
387393
) {
388394
return true;
389395
}

tests/PHPStan/Parser/PhpDocParserTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,20 @@ public function provideReturnTagsData(): Iterator
13011301
]),
13021302
];
13031303

1304+
yield [
1305+
'OK with HTML description',
1306+
'/** @return MongoCollection <p>Returns a collection object representing the new collection.</p> */',
1307+
new PhpDocNode([
1308+
new PhpDocTagNode(
1309+
'@return',
1310+
new ReturnTagValueNode(
1311+
new IdentifierTypeNode('MongoCollection'),
1312+
'<p>Returns a collection object representing the new collection.</p>'
1313+
)
1314+
),
1315+
]),
1316+
];
1317+
13041318
yield [
13051319
'invalid without type and description',
13061320
'/** @return */',

tests/PHPStan/Parser/TypeParserTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,11 @@ public function provideParseData(): array
21662166
false
21672167
)),
21682168
],
2169+
[
2170+
'MongoCollection <p>Returns a collection object representing the new collection.</p>',
2171+
new IdentifierTypeNode('MongoCollection'),
2172+
Lexer::TOKEN_OPEN_ANGLE_BRACKET,
2173+
],
21692174
];
21702175
}
21712176

0 commit comments

Comments
 (0)