rector-symfony icon indicating copy to clipboard operation
rector-symfony copied to clipboard

AddRouteAnnotationRector adds @Route when previous annotation is invalid

Open javaDeveloperKid opened this issue 2 years ago • 3 comments

Consider this example:

    /**
     * @ParamConverter("param", class="App\MyEntity"))
     * @Route("/some-route", name="some_name")
     */

AddRouteAnnotationRector results in:

    /**
     * @ParamConverter("param", class="App\MyEntity"))
     * @Route("/some-route", name="some_name")
     * @Route("/some-route", name="some_name")
     */

@ParamConverter annotation has a typo - two closing brackets - but controller works just fine. When one bracket is removed then AddRouteAnnotationRector works fine (does not do anything).

javaDeveloperKid avatar Sep 14 '22 21:09 javaDeveloperKid

pinging @malteschlueter as author

javaDeveloperKid avatar Sep 14 '22 21:09 javaDeveloperKid

I wouldn't see this as a bug of Rector or the rule in a direct sense. The exsiting code should already not have a syntax error.

But this is my personal opinion.

Unfortunately, I don't know Rector's claims on how Rector should handle such faulty preconditions. Maybe a maintainer or a experienced contributer can help us if this issue must be fixed.

malteschlueter avatar Sep 15 '22 12:09 malteschlueter

I just wonder why it just can't add a new line with @Route annotaton. Why is the previous line with a typo affecting the behaviour?

javaDeveloperKid avatar Sep 15 '22 13:09 javaDeveloperKid

Probably because it cant be parsed, i would say if it works for Symfony as a valid converter then we should probably support it with rector? But i'm also no maintainer here

johanadivare avatar Nov 09 '22 08:11 johanadivare

Hi,

this needs a fix for annotation first, as we handle parser by expected tokens.

    /**
-     * @ParamConverter("param", class="App\MyEntity"))
+     * @ParamConverter("param", class="App\MyEntity")

TomasVotruba avatar Jun 24 '23 08:06 TomasVotruba