Skip to content

Commit

Permalink
Return to the more original behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 16, 2024
1 parent 769ba88 commit 5d9ed08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 57 deletions.
38 changes: 1 addition & 37 deletions src/Parser/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
40 changes: 20 additions & 20 deletions tests/PHPStan/Parser/PhpDocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3968,8 +3968,8 @@ public function provideMultiLinePhpDocData(): iterable
' *' . PHP_EOL .
' */',
new PhpDocNode([
new PhpDocTextNode(''),
new PhpDocTextNode(
PHP_EOL .
'MultiLine' . PHP_EOL .
'description',
),
Expand Down Expand Up @@ -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.'),
]),
];
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -5247,9 +5247,9 @@ public function provideRealWorldExampleData(): Iterator
* </code>
*/",
new PhpDocNode([
new PhpDocTextNode('Finder allows searching through directory trees using iterator.'),
new PhpDocTextNode(''),
new PhpDocTextNode("<code>
new PhpDocTextNode("Finder allows searching through directory trees using iterator.
<code>
Finder::findFiles('*.php')
->size('> 10kB')
->from('.')
Expand Down Expand Up @@ -7563,8 +7563,8 @@ public function dataTextBetweenTagsBelongsToDescription(): iterable
' *' . PHP_EOL .
' */',
new PhpDocNode([
new PhpDocTextNode(''),
new PhpDocTextNode(
PHP_EOL .
'MultiLine' . PHP_EOL .
'description',
),
Expand Down

0 comments on commit 5d9ed08

Please sign in to comment.