-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use normal Collection<ClassName> when property has indexBy #359
Conversation
Fixed 🎉 /cc @AlexeyKosov @yguedidi |
All checks have passed 🎉 @TomasVotruba I am merging it ;) |
Thanks @samsonasik !! |
@yguedidi that's will be too much lookup :), using |
Then maybe at least skip changing if there is already an index in the type? |
that will be too much for that :) |
@samsonasik the thing is that I don't want Rector to change my |
Feel free to skip the rule. |
private $trainings = []; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<\Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Source\Training> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both values have to filled Collection<key, value>
, as first is key, next is value, see:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per @AlexeyKosov at issue rectorphp/rector#8791 (comment)
the key is not necessarily need to be defined, we use \Doctrine\Common\Collections\Collection<ClassName>
too in our project, and working well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for win win solution, skip php doc change is better if there is indexBy
key, since lookup target class -> property type defined by indexBy
may or may not work.
I will create new PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's possible, but I find it weird that Rector will break a more precise type (the one with key type define), and in order to avoid that, we have to make our config more complex to maintain by adding a skip configuration (either full rule, either specific to few files) |
It only change when it has unioned type as far as I see: |
in my case I have something like /**
* @var Collection<string, Training>
*/
#[ORM\OneToMany(targetEntity: Training::class, indexBy: "id", mappedBy: "trainer")]
private Collection $trainings; that got transformed to /**
* @var Collection<int, Training>
*/
#[ORM\OneToMany(targetEntity: Training::class, indexBy: "id", mappedBy: "trainer")]
private Collection $trainings; |
@yguedidi that's correctly skipped, see PR fixture |
Avoid using
<int>
index when property has indexBy.Fixes rectorphp/rector#8791
Fixes #357