Skip to content

Symfony route doc block comments get removed by AnnotationToAttributeRector #9786

Description

@emilychestertonhunt

Bug Report

Subject Details
Rector version 2.4

When converting Symfony routes from annotations to attributes using withAttributesSets, comments are being removed in addition to the route annotation when they appear after the route.

Minimal PHP Code Causing Issue

I am not sure how to get this to work in the demo but here is what I tried and below is a diff of running the rule with the comment before and after the route.
https://getrector.com/demo/eeb66d58-4507-41bb-bec2-1c814fadc3b1

    ---------- begin diff ----------
@@ Line 17 @@
        /**
-        * This is an example comment
-        *
-        * @Route("/test", name="test_route")
-        */
-       public function test(): Response
+     * This is an example comment
+     */
+    #[Route(path: '/test', name: 'test_route')]
+    public function test(): Response
        {

                return $this->render("test.html.twig", []);
    ----------- end diff -----------

Applied rules:
 * AnnotationToAttributeRector
    ---------- begin diff ----------
@@ Line 16 @@
 {
-       /**
-        * @Route("/test", name="test_route")
-        * This is an example comment
-       */
-       public function test(): Response
+       #[Route(path: '/test', name: 'test_route')]
+    public function test(): Response
        {

                return $this->render("test.html.twig", []);
    ----------- end diff -----------

Applied rules:
 * AnnotationToAttributeRector

Expected Behaviour

Rector should not delete the comment.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions