rectorphp/rector-doctrine

Check for attribute before ANNOTATIONS_TO_ATTRIBUTES applied

Closed this issue · 4 comments

While working on one open source tool when Entity has both Annotation and Attributes for B/C.

Executed rector and it created dublicate Attributes.

It would be great to validate attributes before rule is applied and if Attributes alter exists, just remove the Annotation.

Thank you for your report!

We'll need an isolated failing demo link from: http://getrector.com/demo,
that way we can reproduce the bug.

@TomasVotruba I've tried but looks like playground does not know anything about ORM.
https://getrector.com/demo/f036c205-89f7-423d-81eb-16ed5dfcab6d thus does not produce any results.

@oleg-andreyev could you create sample reproducible repo then? Thank you.

@oleg-andreyev There is no need to double the attribute class itself.

This will do: https://getrector.com/demo/42f878a5-b211-4140-9eca-8a5360879ef8

This would require completelety new rule, as in some cases annotatoins can repeate and both are loaded. In other cases, they're unique and should be removed. Also what should happen if annotation and attribute have different keys.

That would be also related to your internal metadata loader - does it prefer annotations or attributes?
Saying that, this can't be automated safely and you should clean the data you want to remove yourself. There is php-cs-fixer rule that automates it actually.