Skip to content

QueryBuilder->getQuery() return type conflicts with Psalm #377

@annuh

Description

@annuh

Since a recent release of the Psalm-doctrine plugin (psalm/psalm-plugin-doctrine#115) the following code conflicts with Phpstan.

Can the new TKey parameter also be supported by the phpstan-docrine plugin? It looks like Psalm is more correct here.

Code:

/** @var Query<array-key, Country> $query */
$query = $this->createQueryBuilder('country')->getQuery();

Without TKey (/** @var Query<Country> $query */) produces the following error in Psalm:

psalm: InvalidTemplateParam: Extended template param TKey of Doctrine\ORM\Query<App\Entity\Country\Country> expects type array-key, type App\Entity\Country\Country given
psalm: MissingTemplateParam: Doctrine\ORM\Query has missing template params, expecting 2

With TKey (/** @var Query<array-key, Country> $query */) procesed the following error in PHPStan:

phpstan: Generic type Doctrine\ORM\Query<(int|string), App\Entity\Country\Country> in PHPDoc tag @var for variable $query specifies 2 template types, but class Doctrine\ORM\Query supports only 1: TResult

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions