Skip to content

New rector to update Doctrine ORM QueryBuilder arguments to use SortDirection #9919

Closed

Description

@stof

Feature Request

doctrine/orm 3.7 has deprecated the usage of strings in the second argument of \Doctrine\ORM\QueryBuilder::addOrderBy and \Doctrine\ORM\QueryBuilder::orderBy (asc or desc, case insensitive) in favor of the SortDirection enum of PHP.
A similar deprecation exists for \Doctrine\ORM\Query\Expr\OrderBy::__construct and \Doctrine\ORM\Query\Expr\OrderBy::add.

It would be great if Rector could migrate automatically the cases using literal values in calls.

Diff

-$qb->addOrderBy('u.name', 'DESC')
+$qb->addOrderBy('u.name', \SortDirection::Descending)

Activity

  1. stof commented on Oct 1, 2026

    @stof
    Author

    Beware that the ORM QueryBuilder has done this change, but the DBAL QueryBuilder does not support SortDirection (which is also what makes it hard to migrate with a dumb search&replace instead of a rector)

  2. TomasVotruba commented on Oct 1, 2026

    @TomasVotruba
    Member

    I think it's doable.

    The SortDirection is some internal PHP class? If its from Doctrine, can you share PR it was added there?

  3. stof commented on Oct 1, 2026

    @stof
    Author

    It is a new enum added in PHP 8.6, with symfony/polyfill-php86 providing it for older PHP versions (for PHP 8.1+).

    See doctrine/orm#11313 for the reference issue in the ORM (starting at doctrine/orm#11313 (comment) for the discussion part using the new PHP enum). Note that the first deprecated case (the OrderBy mapping attribute) is already covered by a rector added in rectorphp/rector-doctrine#525

  4. TomasVotruba commented on Oct 6, 2026

    @TomasVotruba
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions