-
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
The rule ImproveDoctrineCollectionDocTypeInEntityRector
does not keep Intersection types
#342
Comments
I experience the same, also with fully typed - /** @var Collection<int, Equipment>&Selectable<int, Equipment> */
+ /** @var Collection<int, Equipment> */
#[ORM\ManyToMany(targetEntity: Equipment::class, mappedBy: 'technologies', fetch: 'EXTRA_LAZY')]
private Collection&Selectable $equipment; // Default in constructor This is caused by #339, before that merge this rule was not run for properties with attributes. |
This seem like a fix in wrong place. See #343 (comment) |
@TomasVotruba I believe you misinterpreted the issue. The issue is that Rector is changing the doc block while it shouldn't. The var type is either already fully correct (my example), or it removes an intersection that should be kept (the first example). Both matched with the actual PHP type ( Doctrine and/or PHPStan can't fix a broken Rector... |
@TomasVotruba using - /** @var Collection<int, Equipment>&Selectable<int, Equipment> */
+ /** @var Collection<int, Equipment> */ which should be kept as is. |
This rule purpose is to turn all collections types into single style. Still, this seems like wrong use of annotation to make single tool happy. |
The rule description disagrees with your point of view: From the Doctrine documentation we can see that some collection implementations also implement the See https://phpstan.org/r/608d3b24-8f23-4861-90ad-787763b5e878 for an analysis example.
The only tool that is not happy here is Rector, which expresses itself by removing useful static analysis information. We want to make sure PHPStorm and PHPStan know that Anyways, I have disabled this rule now for my configurations, works for me 🤷🏻♂️ |
Description is correct, just view is different :) IMO this should be fixed in Doctrine itself, as some methods are missing in the interface. |
I do not agree on the way that this issue is closed. If a collection is typed in PHP with some intersection types, I expect rector to keep all the types in the docblock. For instance: /**
+ * @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User\UserScopeHistory>&SomethingElse
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserScopeHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection&SomethingElse $scopeHistories; and not: /**
+ * @var \Doctrine\Common\Collections\Collection<int, \Chill\MainBundle\Entity\User\UserScopeHistory>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserScopeHistory::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection&SomethingElse $scopeHistories; (IMO, I don't think that there is an issue with Doctrine and the separation of the Collection and Selectable interface. Collection gather the minimal methods required for a readable and writable collection of objects, and Selectable add some features, which are not required everywhere. But I admit that gathering both would ease the usage. This should be discussed on the doctrine's issue tracker, but as I am not convinced that this should change, I don't find the motivation to open an issue there.) |
@TomasVotruba I created PR #344 if you want to consider |
When running the rule ImproveDoctrineCollectionDocTypeInEntityRector, the diff produced is this one:
The problem is that the docblock does not keep the
Selectable
type. It causes other tools like PHPStan to complaints that some methods are missing inCollection
classes.The text was updated successfully, but these errors were encountered: