Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix HTML description detection for phpstorm stubs #220

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
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