function PhpDocParser::parseText
1 call to PhpDocParser::parseText()
- PhpDocParser::parseChild in vendor/
phpstan/ phpdoc-parser/ src/ Parser/ PhpDocParser.php - @phpstan-impure
File
-
vendor/
phpstan/ phpdoc-parser/ src/ Parser/ PhpDocParser.php, line 223
Class
- PhpDocParser
- @phpstan-import-type ValueType from Doctrine\DoctrineArgument as DoctrineValueType
Namespace
PHPStan\PhpDocParser\ParserCode
private function parseText(TokenIterator $tokens) : Ast\PhpDoc\PhpDocTextNode {
$text = '';
$endTokens = [
Lexer::TOKEN_PHPDOC_EOL,
Lexer::TOKEN_CLOSE_PHPDOC,
Lexer::TOKEN_END,
];
if ($this->textBetweenTagsBelongsToDescription) {
$endTokens = [
Lexer::TOKEN_CLOSE_PHPDOC,
Lexer::TOKEN_END,
];
}
$savepoint = false;
// if the next token is EOL, everything below is skipped and empty string is returned
while ($this->textBetweenTagsBelongsToDescription || !$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;
}
if ($this->textBetweenTagsBelongsToDescription) {
if (!$savepoint) {
$tokens->pushSavePoint();
$savepoint = true;
}
elseif ($tmpText !== '') {
$tokens->dropSavePoint();
$tokens->pushSavePoint();
}
}
$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";
}
if ($savepoint) {
$tokens->rollback();
$text = rtrim($text, $tokens->getDetectedNewline() ?? "\n");
}
return new Ast\PhpDoc\PhpDocTextNode(trim($text, " \t"));
}