[PR #1244] Change $this return type to static in AbstractQuery #9302

Open
opened 2026-01-22 16:03:53 +01:00 by admin · 0 comments
Owner

Original Pull Request: https://github.com/doctrine/orm/pull/1244

State: closed
Merged: Yes


This allows IDEs and static code analysis tools to properly understand the return type when chaining methods, for example when using the QueryBuilder:

$query = $this->em->createQueryBuilder()
    ->select('u')
    ->from(User::class, 'u')
    ->where('u.email = :email')
    ->getQuery()
    ->setParameter('email', $email)
    ->setMaxResults(10);

In this example, my IDE (PHPStorm) reports:

Method 'setMaxResults' not found in class \Doctrine\ORM\AbstractQuery

With a static return type, the IDE now understands the chaining and knows that $query is a Query, not just an AbstractQuery.

**Original Pull Request:** https://github.com/doctrine/orm/pull/1244 **State:** closed **Merged:** Yes --- This allows IDEs and static code analysis tools to properly understand the return type when chaining methods, for example when using the QueryBuilder: ``` $query = $this->em->createQueryBuilder() ->select('u') ->from(User::class, 'u') ->where('u.email = :email') ->getQuery() ->setParameter('email', $email) ->setMaxResults(10); ``` In this example, my IDE (PHPStorm) reports: > Method 'setMaxResults' not found in class \Doctrine\ORM\AbstractQuery With a `static` return type, the IDE now understands the chaining and knows that `$query` is a `Query`, not just an `AbstractQuery`.
admin added the pull-request label 2026-01-22 16:03:53 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#9302