diff --git a/src/Parser/TypeParser.php b/src/Parser/TypeParser.php index 46de7aa..79e7027 100644 --- a/src/Parser/TypeParser.php +++ b/src/Parser/TypeParser.php @@ -7,7 +7,9 @@ use PHPStan\PhpDocParser\Lexer\Lexer; use function in_array; use function str_replace; +use function strlen; use function strpos; +use function substr_compare; use function trim; class TypeParser @@ -380,10 +382,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; } diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index c52be80..3b44c3b 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -1301,6 +1301,20 @@ public function provideReturnTagsData(): Iterator ]), ]; + yield [ + 'OK with HTML description', + '/** @return MongoCollection
Returns a collection object representing the new collection.
*/', + new PhpDocNode([ + new PhpDocTagNode( + '@return', + new ReturnTagValueNode( + new IdentifierTypeNode('MongoCollection'), + 'Returns a collection object representing the new collection.
' + ) + ), + ]), + ]; + yield [ 'invalid without type and description', '/** @return */', diff --git a/tests/PHPStan/Parser/TypeParserTest.php b/tests/PHPStan/Parser/TypeParserTest.php index 2c66d98..0cc294f 100644 --- a/tests/PHPStan/Parser/TypeParserTest.php +++ b/tests/PHPStan/Parser/TypeParserTest.php @@ -2166,6 +2166,11 @@ public function provideParseData(): array false )), ], + [ + 'MongoCollectionReturns a collection object representing the new collection.
', + new IdentifierTypeNode('MongoCollection'), + Lexer::TOKEN_OPEN_ANGLE_BRACKET, + ], ]; }