rector-symfony
rector-symfony copied to clipboard
AddRouteAnnotationRector adds @Route when previous annotation is invalid
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).
pinging @malteschlueter as author
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.
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?
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
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")