@@ -214,21 +214,27 @@ private function parseText(TokenIterator $tokens): Ast\PhpDoc\PhpDocTextNode
214
214
{
215
215
$ text = '' ;
216
216
217
+ // if the next token is EOL, everything below is skipped and empty string is returned
217
218
while (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
218
219
$ text .= $ tokens ->getSkippedHorizontalWhiteSpaceIfAny () . $ tokens ->joinUntil (Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END );
219
220
221
+ // stop if we're not at EOL - meaning it's the end of PHPDoc
220
222
if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
221
223
break ;
222
224
}
223
225
224
226
$ tokens ->pushSavePoint ();
225
227
$ tokens ->next ();
226
228
229
+ // if we're at EOL, check what's next
230
+ // if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
227
231
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END )) {
228
232
$ tokens ->rollback ();
229
233
break ;
230
234
}
231
235
236
+ // otherwise if the next is text, continue building the description string
237
+
232
238
$ tokens ->dropSavePoint ();
233
239
$ text .= $ tokens ->getDetectedNewline () ?? "\n" ;
234
240
}
@@ -241,9 +247,11 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
241
247
{
242
248
$ text = '' ;
243
249
250
+ // if the next token is EOL, everything below is skipped and empty string is returned
244
251
while (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
245
252
$ text .= $ tokens ->getSkippedHorizontalWhiteSpaceIfAny () . $ tokens ->joinUntil (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END );
246
253
254
+ // stop if we're not at EOL - meaning it's the end of PHPDoc
247
255
if (!$ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_EOL )) {
248
256
if (!$ tokens ->isPrecededByHorizontalWhitespace ()) {
249
257
return trim ($ text . $ this ->parseText ($ tokens )->text , " \t" );
@@ -281,11 +289,15 @@ private function parseOptionalDescriptionAfterDoctrineTag(TokenIterator $tokens)
281
289
$ tokens ->pushSavePoint ();
282
290
$ tokens ->next ();
283
291
292
+ // if we're at EOL, check what's next
293
+ // if next is a PHPDoc tag, EOL, or end of PHPDoc, stop
284
294
if ($ tokens ->isCurrentTokenType (Lexer::TOKEN_PHPDOC_TAG , Lexer::TOKEN_DOCTRINE_TAG , Lexer::TOKEN_PHPDOC_EOL , Lexer::TOKEN_CLOSE_PHPDOC , Lexer::TOKEN_END )) {
285
295
$ tokens ->rollback ();
286
296
break ;
287
297
}
288
298
299
+ // otherwise if the next is text, continue building the description string
300
+
289
301
$ tokens ->dropSavePoint ();
290
302
$ text .= $ tokens ->getDetectedNewline () ?? "\n" ;
291
303
}
0 commit comments