From 5d9ed0826ede15c989db0c91c5bb7e14899c41f0 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 15 Sep 2024 21:18:15 +0200 Subject: [PATCH] Return to the more original behaviour --- src/Parser/PhpDocParser.php | 38 +-------------------- tests/PHPStan/Parser/PhpDocParserTest.php | 40 +++++++++++------------ 2 files changed, 21 insertions(+), 57 deletions(-) diff --git a/src/Parser/PhpDocParser.php b/src/Parser/PhpDocParser.php index 35a79ad..f5a6feb 100644 --- a/src/Parser/PhpDocParser.php +++ b/src/Parser/PhpDocParser.php @@ -155,7 +155,7 @@ private function parseChild(TokenIterator $tokens): Ast\PhpDoc\PhpDocChildNode $startLine = $tokens->currentTokenLine(); $startIndex = $tokens->currentTokenIndex(); - $text = $this->parsePhpDocTextNode($tokens); + $text = $this->parseText($tokens); return $this->enrichWithAttributes($tokens, $text, $startLine, $startIndex); } @@ -313,42 +313,6 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens) } - private function parsePhpDocTextNode(TokenIterator $tokens): Ast\PhpDoc\PhpDocTextNode - { - $text = ''; - - $endTokens = [Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC, Lexer::TOKEN_END]; - - // if the next token is EOL, everything below is skipped and empty string is returned - while (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL)) { - $tmpText = $tokens->getSkippedHorizontalWhiteSpaceIfAny() . $tokens->joinUntil(Lexer::TOKEN_PHPDOC_EOL, ...$endTokens); - $text .= $tmpText; - - // stop if we're not at EOL - meaning it's the end of PHPDoc - if (!$tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_EOL, Lexer::TOKEN_CLOSE_PHPDOC)) { - break; - } - - $tokens->pushSavePoint(); - $tokens->next(); - - // if we're at EOL, check what's next - // if next is a PHPDoc tag, EOL, or end of PHPDoc, stop - if ($tokens->isCurrentTokenType(Lexer::TOKEN_PHPDOC_TAG, Lexer::TOKEN_DOCTRINE_TAG, ...$endTokens)) { - $tokens->rollback(); - break; - } - - // otherwise if the next is text, continue building the description string - - $tokens->dropSavePoint(); - $text .= $tokens->getDetectedNewline() ?? "\n"; - } - - return new Ast\PhpDoc\PhpDocTextNode(trim($text, " \t")); - } - - public function parseTag(TokenIterator $tokens): Ast\PhpDoc\PhpDocTagNode { $tag = $tokens->currentTokenValue(); diff --git a/tests/PHPStan/Parser/PhpDocParserTest.php b/tests/PHPStan/Parser/PhpDocParserTest.php index cd68054..d352da4 100644 --- a/tests/PHPStan/Parser/PhpDocParserTest.php +++ b/tests/PHPStan/Parser/PhpDocParserTest.php @@ -3968,8 +3968,8 @@ public function provideMultiLinePhpDocData(): iterable ' *' . PHP_EOL . ' */', new PhpDocNode([ - new PhpDocTextNode(''), new PhpDocTextNode( + PHP_EOL . 'MultiLine' . PHP_EOL . 'description', ), @@ -5073,13 +5073,13 @@ public function providerDebug(): Iterator 'OK class line', $sample, new PhpDocNode([ - new PhpDocTextNode('Returns the schema for the field.'), - new PhpDocTextNode(''), - new PhpDocTextNode('This method is static because the field schema information is needed on + new PhpDocTextNode('Returns the schema for the field. + +This method is static because the field schema information is needed on creation of the field. FieldItemInterface objects instantiated at that -time are not reliable as field settings might be missing.'), - new PhpDocTextNode(''), - new PhpDocTextNode('Computed fields having no schema should return an empty array.'), +time are not reliable as field settings might be missing. + +Computed fields having no schema should return an empty array.'), ]), ]; } @@ -5127,13 +5127,13 @@ public function provideRealWorldExampleData(): Iterator 'OK FieldItemInterface::schema', $sample, new PhpDocNode([ - new PhpDocTextNode('Returns the schema for the field.'), - new PhpDocTextNode(''), - new PhpDocTextNode('This method is static because the field schema information is needed on + new PhpDocTextNode('Returns the schema for the field. + +This method is static because the field schema information is needed on creation of the field. FieldItemInterface objects instantiated at that -time are not reliable as field settings might be missing.'), - new PhpDocTextNode(''), - new PhpDocTextNode('Computed fields having no schema should return an empty array.'), +time are not reliable as field settings might be missing. + +Computed fields having no schema should return an empty array.'), new PhpDocTextNode(''), new PhpDocTagNode( '@param', @@ -5201,9 +5201,9 @@ public function provideRealWorldExampleData(): Iterator 'OK AbstractChunkedController::parseChunkedRequest', $sample, new PhpDocNode([ - new PhpDocTextNode('Parses a chunked request and return relevant information.'), - new PhpDocTextNode(''), - new PhpDocTextNode('This function must return an array containing the following + new PhpDocTextNode('Parses a chunked request and return relevant information. + + This function must return an array containing the following keys and their corresponding values: - last: Wheter this is the last chunk of the uploaded file - uuid: A unique id which distinguishes two uploaded files @@ -5247,9 +5247,9 @@ public function provideRealWorldExampleData(): Iterator * */", new PhpDocNode([ - new PhpDocTextNode('Finder allows searching through directory trees using iterator.'), - new PhpDocTextNode(''), - new PhpDocTextNode(" + new PhpDocTextNode("Finder allows searching through directory trees using iterator. + + Finder::findFiles('*.php') ->size('> 10kB') ->from('.') @@ -7563,8 +7563,8 @@ public function dataTextBetweenTagsBelongsToDescription(): iterable ' *' . PHP_EOL . ' */', new PhpDocNode([ - new PhpDocTextNode(''), new PhpDocTextNode( + PHP_EOL . 'MultiLine' . PHP_EOL . 'description', ),