Skip to content

Commit

Permalink
fix HTML description detection for phpstorm stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed Nov 17, 2023
1 parent c2b8bbf commit 0601081
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,16 @@ public function isHtml(TokenIterator $tokens): bool
return false;
}

$endTag = '</' . $htmlTagName . '>';
$endTagSearchOffset = - strlen($endTag);

while (!$tokens->isCurrentTokenType(Lexer::TOKEN_END)) {
if (
$tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)
&& strpos($tokens->currentTokenValue(), '/' . $htmlTagName . '>') !== false
(
$tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_ANGLE_BRACKET)
&& strpos($tokens->currentTokenValue(), '/' . $htmlTagName . '>') !== false
)
|| substr_compare($tokens->currentTokenValue(), $endTag, $endTagSearchOffset) === 0
) {
return true;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,20 @@ public function provideReturnTagsData(): Iterator
]),
];

yield [
'OK with HTML description',
'/** @return MongoCollection <p>Returns a collection object representing the new collection.</p> */',
new PhpDocNode([
new PhpDocTagNode(
'@return',
new ReturnTagValueNode(
new IdentifierTypeNode('MongoCollection'),
'<p>Returns a collection object representing the new collection.</p>'
)
),
]),
];

yield [
'invalid without type and description',
'/** @return */',
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,11 @@ public function provideParseData(): array
false
)),
],
[
'MongoCollection <p>Returns a collection object representing the new collection.</p>',
new IdentifierTypeNode('MongoCollection'),
Lexer::TOKEN_OPEN_ANGLE_BRACKET,
],
];
}

Expand Down

0 comments on commit 0601081

Please sign in to comment.