@@ -214,21 +214,27 @@ private function parseText(TokenIterator $tokens): Ast\PhpDoc\PhpDocTextNode
214214 {
215215 $ text = '' ;
216216
217+ // if the next token is EOL, everything below is skipped and empty string is returned
217218 while (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
218219 $ text .= $ tokens ->getSkippedHorizontalWhiteSpaceIfAny () . $ tokens ->joinUntil (Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END );
219220
221+ // stop if we're not at EOL - meaning it's the end of PHPDoc
220222 if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
221223 break ;
222224 }
223225
224226 $ tokens ->pushSavePoint ();
225227 $ tokens ->next ();
226228
229+ // if we're at EOL, check what's next
230+ // if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
227231 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END )) {
228232 $ tokens ->rollback ();
229233 break ;
230234 }
231235
236+ // otherwise if the next is text, continue building the description string
237+
232238 $ tokens ->dropSavePoint ();
233239 $ text .= $ tokens ->getDetectedNewline () ?? "\n" ;
234240 }
@@ -241,9 +247,11 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
241247 {
242248 $ text = '' ;
243249
250+ // if the next token is EOL, everything below is skipped and empty string is returned
244251 while (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
245252 $ text .= $ tokens ->getSkippedHorizontalWhiteSpaceIfAny () . $ tokens ->joinUntil (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END );
246253
254+ // stop if we're not at EOL - meaning it's the end of PHPDoc
247255 if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
248256 if (!$ tokens ->isPrecededByHorizontalWhitespace ()) {
249257 return trim ($ text . $ this ->parseText ($ tokens )->text , " \t" );
@@ -281,11 +289,15 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
281289 $ tokens ->pushSavePoint ();
282290 $ tokens ->next ();
283291
292+ // if we're at EOL, check what's next
293+ // if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
284294 if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END )) {
285295 $ tokens ->rollback ();
286296 break ;
287297 }
288298
299+ // otherwise if the next is text, continue building the description string
300+
289301 $ tokens ->dropSavePoint ();
290302 $ text .= $ tokens ->getDetectedNewline () ?? "\n" ;
291303 }
0 commit comments