phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Query result type is not recognized if create the query builder on a trait

Open IndraGunawan opened this issue 11 months ago • 3 comments

this commit https://github.com/phpstan/phpstan-doctrine/commit/149cf71c3b470f815ad8ad658606e9217db22d9f makes the correct getResult return type if the method within the class, but it does not work if the query builder comes from a trait

trait MyTrait
{
	protected function getCustomQueryBuilder() {
		return $this->createQueryBuilder('t')
			->andWhere('t.enabled = true');
	}
}

class MyRepository
{
	use MyTrait;

	public function findBySomething(): array
	{
		$qb = $this->getCustomQueryBuilder()
			->andWhere('t.someInt = 1');
		return $qb->getQuery()->getResult();
	}

getting this error

 Method App\Repository\MyRepository::findBySomething() should return
         array<App\Entity\MyEntity> but returns mixed.

IndraGunawan avatar Nov 11 '24 09:11 IndraGunawan