rector-symfony
rector-symfony copied to clipboard
AddRouteAnnotationRector does not add multiple @Route
Consider this example:
route_name:
path: /some-path
defaults: { _controller: 'MyBundle:Customer:edit' }
route_name_2:
path: /some-path # same path
defaults: { _controller: 'MyBundle:Customer:edit' } # same defaults
AddRouteAnnotationRector results in
/**
* @Route(path="some-path", name="route_name")
*/
public function editAction()
{
}
AddRouteAnnotationRector should add two @Route
annotations.
pinging @malteschlueter as an author
@javaDeveloperKid I was already afraid that the question would come up at some point^^.
This behavior is I think quite difficult to handle, because we currently can't (maybe never) distinguish if the route Rector currently handles is from a YAML configuration or an existing route annotation (which must not be added again).
Because of that I skipped the route if a route annoation already exists.
I'm sorry that I can't help you :/
But give it a try maybe you can solve this issue :)
Hmm, that gives me 2 thoughts:
- should Rector have a feature to mark rectors as risky? Such information would be then documented and would show up in the
process
command output. -
which must not be added again
- will this break an application? Or the second one will just override the first one? If breaks then in my opinion this is still better to duplicate because we will see this in the git diff. Right know this second route just vanishes.
1. should Rector have a feature to mark rectors as risky? Such information would be then documented and would show up in the `process` command output.
I have no opinion to that.
2. `which must not be added again` - will this break an application? Or the second one will just override the first one? If breaks then in my opinion this is still better to duplicate because we will see this in the git diff. Right know this second route just vanishes.
You may add an option to configure which allows Rector to add an annotation even one exists?
You may add an option to configure which allows Rector to add an annotation even one exists?
I'll see.
Because of that I skipped the route if a route annoation already exists.
I have second thoughts on this. The first route annotation is different because the name is different. So AddRouteAnnotationRector may compare names and I think names are event more important because they are unique, i.e. you can have 2 routes with the same path but you can't have 2 routes with the same name.
@javaDeveloperKid I've added a fixture mimicking your example, there were no changes needed to the rule.
Can you confirm this issue is resolved?
Thanks @stefantalen :clap:
Handled in https://github.com/rectorphp/rector-symfony/pull/360/files