Skip to content

findBy()/findOneBy() phpdoc doesn't allow SortDirection for $orderBy #12664

Closed

Description

@talhaamir2024

At runtime the ORM accepts a SortDirection enum case as an $orderBy value. BasicEntityPersister declares array<string, SortDirection|string>, and passing a string direction is deprecated. The public repository phpdoc does not allow the enum, so static analysis reports an error on correct, non-deprecated code.

Code

$repository->findBy(['company' => $company], ['name' => SortDirection::Ascending]);
$repository->findOneBy(['company' => $company], ['id' => SortDirection::Descending]);

PHPStan (level max) reports

findBy() expects array<string, 'ASC'|'asc'|'DESC'|'desc'>|null, array{id: SortDirection::Ascending} given.
findOneBy() expects array<string, string>|null, array<string, SortDirection::Descending> given.

Cause

  • EntityRepository::findOneBy() has @phpstan-param array<string, string>|null $orderBy (EntityRepository.php:118).
  • findBy() inherits @phpstan-param array<string, 'asc'|'desc'|'ASC'|'DESC'>|null $orderBy from Doctrine\Persistence\ObjectRepository (ObjectRepository.php:43).
  • BasicEntityPersister::getOrderBySQL() already uses array<string, SortDirection|string>.

Expected

The repository phpdoc matches the persister: array<string, 'asc'|'desc'|'ASC'|'DESC'|SortDirection>|null. This needs a change in doctrine/orm for findOneBy() and in doctrine/persistence for findBy().

Environment

doctrine/orm <version>, doctrine/persistence <version>, PHP 8.5, PHPStan level max.

Activity

  1. greg0ire commented on Oct 11, 2026

    @greg0ire
    Member

    Hi! Thanks for reporthing this. The fix is already done, and will ship in 3.8.0: #12613

  2. added this to the 3.8.0 milestone on Oct 15, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions