-
Notifications
You must be signed in to change notification settings - Fork 112
Open
Description
Can the following code work without manually defining the return type, i.e adding /** @var UserDto[] */?
final class Repository
{
public function __construct(
private EntityManagerInterface $em
) {
}
/**
* @return UserDto[]
*/
public function findAll(): array
{
$qb = $this->em->createQueryBuilder()
->select(\sprintf('NEW %s(u.id, u.email)', UserDto::class))
->from(User::class, 'u')
->getQuery();
/** @var UserDto[] */
return $qb->getResult();
}
public function findByEmail(string $email): ?UserDto
{
$qb = $this->em->createQueryBuilder()
->select(\sprintf('NEW %s(u.id, u.email)', UserDto::class))
->from(User::class, 'u')
->where('u.email = :email')
->setParameter('email', $email)
->getQuery();
/** @var UserDto|null */
return $qb->getOneOrNullResult();
}
}Metadata
Metadata
Assignees
Labels
No labels