-
Notifications
You must be signed in to change notification settings - Fork 56
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
DOCTRINE_CODE_QUALITY + DOCTRINE_COLLECTION_22 breaks ORM\OrderBy attribute usage #315
Comments
I didn't look the whole version by version class yet, but that maybe a class on specific version, and enum on next version, @julienfastre could you verify? the possible way to do is verify if thats a Class, with custom rule, or check the Class on |
I can reproduce this issue, but it's quite unclear to me on how to solve this.
I think that there are multiple doctrine projects which use the same concept, but differently: doctrine/collections introduced this enum
Reading the links provided by @j-dobr, keeping the I am not sure of this, but I think that we should replace the string
|
@julienfastre i see it might be a problem in php 8.1 to do the enum with I just tested a project with entity ordering and querybuilder ordering using |
@julienfastre now it works as expected. Strings are left intact. Thanks a lot! |
Setting default order for collection inside entity, ORM\OrderBy is used like this:
#[OrderBy(["name" => "ASC"])]
(docs)When using
DoctrineSetList::DOCTRINE_CODE_QUALITY
, above is replaced with#[OrderBy(["name" => \Doctrine\Common\Collections\Criteria::ASC])]
which, while not according to docs, still works.But the \Doctrine\Common\Collections\Criteria::ASC is deprecated and thus the
DoctrineSetList::DOCTRINE_COLLECTION_22
further replaces it with#[OrderBy(["name" => \Doctrine\Common\Collections\Order::Ascending])]
. And that breaks as the string is expected there, not enum.PHPStan:
Parameter #1 $value of attribute class Doctrine\ORM\Mapping\OrderBy constructor expects array<string>, array<string,Doctrine\Common\Collections\Order::Ascending> given.
Manually adding value like this
#[OrderBy(["name" => \Doctrine\Common\Collections\Order::Ascending->value])]
makes it work again (although it still breaks for me on PHP 8.1 and works only with PHP 8.2 (not sure why, might be my setup)). There is still an ongoing discussion regarding the whole \Doctrine\Common\Collections\Order stuff. Main issue being probably this and there are few others touching the topic too, so the situation will probably evolve in future.Seeing all this, I would suggest to stick to the docs here and avoid replacing the
"ASC"
/"DESC"
inDoctrineSetList::DOCTRINE_CODE_QUALITY
as the constants in\Doctrine\Common\Collections\Criteria
were never meant to be used for that (source).The text was updated successfully, but these errors were encountered: