diff --git a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php index e5c252105fe..542864bc2bc 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php +++ b/packages/BetterPhpDocParser/PhpDocParser/DoctrineAnnotationDecorator.php @@ -157,15 +157,18 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes( foreach ($phpDocNode->children as $key => $phpDocChildNode) { // the @\FQN use case if ($phpDocChildNode instanceof PhpDocTextNode) { - $spacelessPhpDocTagNode = $this->resolveFqnAnnotationSpacelessPhpDocTagNode( + $spacelessPhpDocTagNodes = $this->resolveFqnAnnotationSpacelessPhpDocTagNode( $phpDocChildNode, $currentPhpNode ); - if (! $spacelessPhpDocTagNode instanceof SpacelessPhpDocTagNode) { + + if ($spacelessPhpDocTagNodes === []) { continue; } - $phpDocNode->children[$key] = $spacelessPhpDocTagNode; + unset($phpDocNode->children[$key]); + array_splice($phpDocNode->children, $key, 0, $spacelessPhpDocTagNodes); + continue; } @@ -304,28 +307,36 @@ private function combineStartAndEnd( return new StartAndEnd($currentStartAndEnd->getStart(), $nextStartAndEnd->getEnd()); } + /** + * @return SpacelessPhpDocTagNode[] + */ private function resolveFqnAnnotationSpacelessPhpDocTagNode( PhpDocTextNode $phpDocTextNode, Node $currentPhpNode - ): ?SpacelessPhpDocTagNode { - $match = Strings::match($phpDocTextNode->text, self::LONG_ANNOTATION_REGEX); - $fullyQualifiedAnnotationClass = $match['class_name'] ?? null; + ): array { + $matches = Strings::matchAll($phpDocTextNode->text, self::LONG_ANNOTATION_REGEX); + $spacelessPhpDocTagNodes = []; + foreach ($matches as $match) { + $fullyQualifiedAnnotationClass = $match['class_name'] ?? null; - if ($fullyQualifiedAnnotationClass === null) { - return null; - } + if ($fullyQualifiedAnnotationClass === null) { + continue; + } - $annotationContent = $match['annotation_content'] ?? null; - $tagName = '@\\' . $fullyQualifiedAnnotationClass; + $annotationContent = $match['annotation_content'] ?? null; + $tagName = '@\\' . $fullyQualifiedAnnotationClass; - $formerStartEnd = $phpDocTextNode->getAttribute(PhpDocAttributeKey::START_AND_END); + $formerStartEnd = $phpDocTextNode->getAttribute(PhpDocAttributeKey::START_AND_END); - return $this->createDoctrineSpacelessPhpDocTagNode( - $annotationContent, - $tagName, - $fullyQualifiedAnnotationClass, - $formerStartEnd, - $currentPhpNode - ); + $spacelessPhpDocTagNodes[] = $this->createDoctrineSpacelessPhpDocTagNode( + $annotationContent, + $tagName, + $fullyQualifiedAnnotationClass, + $formerStartEnd, + $currentPhpNode + ); + } + + return $spacelessPhpDocTagNodes; } } diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index 6a60eb3462e..88ef57acd07 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -257,7 +257,7 @@ private function printEnd(string $output): string } if ($lastTokenPosition === 0) { - $lastTokenPosition = 1; + return $output . "\n */"; } return $this->addTokensFromTo($output, $lastTokenPosition, $this->tokenCount, true); diff --git a/tests/Issues/AutoImport/Fixture/DocBlock/skip_two_routes_with_prev_doc.php.inc b/tests/Issues/AutoImport/Fixture/DocBlock/skip_two_routes_with_prev_doc.php.inc new file mode 100644 index 00000000000..67f6ff55f39 --- /dev/null +++ b/tests/Issues/AutoImport/Fixture/DocBlock/skip_two_routes_with_prev_doc.php.inc @@ -0,0 +1,16 @@ + +----- + diff --git a/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc.php.inc b/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc.php.inc new file mode 100644 index 00000000000..5c9c316ee7a --- /dev/null +++ b/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc.php.inc @@ -0,0 +1,38 @@ + +----- + diff --git a/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc_other_routes.php.inc b/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc_other_routes.php.inc new file mode 100644 index 00000000000..5a29821370e --- /dev/null +++ b/tests/Issues/AutoImport/Fixture/DocBlock/two_routes_with_next_doc_other_routes.php.inc @@ -0,0 +1,40 @@ + +----- + \ No newline at end of file