rector-doctrine
rector-doctrine copied to clipboard
DOCTRINE_CODE_QUALITY + DOCTRINE_COLLECTION_22 breaks ORM\OrderBy attribute usage
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"
in DoctrineSetList::DOCTRINE_CODE_QUALITY
as the constants in \Doctrine\Common\Collections\Criteria
were never meant to be used for that (source).