Skip to content

QueryBuilder->getQuery->getResult() does not work properly when $indexBy is provided to ->from() #301

@arderyp

Description

@arderyp

I am not sure if this is a problem with phpstan itself, or this repo.

This throws no error:

/** @return Users[] **/
 public function findCustom(string $type, string): array
{
    return $this->getEntityManager()->createQueryBuilder()
        ->select("user")
        ->from(Users::class, "user")
        ->where("user.type = :type")
        ->setParameter("type", $type)
        ->getQuery()
        ->getResult();
}

This throws findCustom() should return array<App\Entity\Users> but returns mixed.

/** @return Users[] **/
 public function findCustom(string $type, string, $indexBy = "user.uid"): array
{
    return $this->getEntityManager()->createQueryBuilder()
        ->select("user")
        ->from(Users::class, "user", $indexBy)
        ->where("user.type = :type")
        ->setParameter("type", $type)
        ->getQuery()
        ->getResult();
}

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