Repository navigation
Allow SortDirection in EntityRepository::findBy() and findOneBy() - #12613
Conversation
SortDirection in EntityRepository::findBy() and findOneBy()
583cc15 to
dc62639
Compare
|
Since this contains a breaking change, maybe we should mute the issue on 3.7.x, and this PR should target 3.8.x? On the other hand, it's just phpdoc/static analysis. I'm on the fence… |
Repository methods must keep accepting 'asc'/'desc' strings without a deprecation because the ObjectRepository interface of doctrine/persistence 3.x and 4.x documents strings as the only order values. As an implementer, EntityRepository can still widen its documented parameter type, so \SortDirection is now accepted and documented there as well. This makes the new SortDirection guidance usable on the most common repository API. The persister interface load() is aligned to the same widened type. Add functional tests (with and without second level cache), static analysis coverage, and clarify the deprecation scope in UPGRADE.md and the reference docs.
Address review feedback on doctrine#12613: - drop the ambiguous "assumed" and the PHPStan-specific argument.type identifier; reword the BC break to match the QueryBuilder wording - note that doctrine/persistence 5.0 will accept SortDirection in ObjectRepository
dc62639 to
6b77782
Compare
|
Thanks @GromNaN ! |
I would go in favor for muting the deprecation on 3.7 for the reason that it's not fully supported and it's disturbing having half the method supporting SortDirection (with a deprecation) and half not. In the same context the QueryBuilder from Dbal does not support it yet |
EntityRepository::findBy()andfindOneBy()now accept and document\SortDirectionvalues for$orderBy, while'asc'/'desc'strings keep working without a deprecation.The
ObjectRepositoryinterface ofdoctrine/persistence3.x and 4.x documents strings as the only valid order values, so the string form stays accepted on the repository API. As an implementer of the interface,EntityRepositorycan widen its documented parameter type, so passing\SortDirection::Ascendingor\SortDirection::Descendingis now allowed and documented there, matching whatQueryBuilder,Expr\OrderByand the mapping API already accept. Native signatures are unchanged.Breaking change
This is a static-analysis BC break for custom repositories that override
findBy()orfindOneBy()and forward$orderBytoparent::*(): the documented$orderBytype now also accepts\SortDirection, so an override whose docblock reproduces the previous type (theObjectRepositorystring union forfindBy(), orarray<string, string>forfindOneBy()) is reported as incompatible by static analysis. Widen the override docblock accordingly.ObjectRepositoryitself is unchanged.Static analysis only allows
SortDirectionwhen the repository is typed asEntityRepository(or a subclass), not asDoctrine\Persistence\ObjectRepository, untildoctrine/persistence5 is required. The deprecation scope is clarified inUPGRADE.mdaccordingly.Changes:
$orderByphpdoc ofEntityRepository::findBy()andfindOneBy(), and ofEntityPersister::load()UPGRADE.mdand the reference docs