Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query loses its result type when using setLockMode or setHint #393

Closed
noemi-salaun opened this issue Nov 17, 2022 · 3 comments
Closed

Query loses its result type when using setLockMode or setHint #393

noemi-salaun opened this issue Nov 17, 2022 · 3 comments

Comments

@noemi-salaun
Copy link

When using setLockMode() or setHint() on a Query, PHPStan stop inferring the result type.

GOOD TYPE

$user = $entityManager
    ->getRepository(User::class)
    ->createQueryBuilder('user')
    ->where('user.id = :userId')
    ->getQuery()
    ->getResult();

\PHPStan\dumpType($user); // -> Dumped type: array<App\User>

MIXED TYPE

$user = $entityManager
    ->getRepository(User::class)
    ->createQueryBuilder('user')
    ->where('user.id = :userId')
    ->getQuery()
    ->setLockMode(LockMode::PESSIMISTIC_READ) // <- Add this line
    ->getResult();

\PHPStan\dumpType($user); // -> Dumped type: mixed
@VincentLanglet
Copy link
Contributor

Hi @noemi-salaun, this can be fixed directly on doctrine/orm.

The return type is self but the phpdoc should be more precise.
https://github.com/doctrine/orm/blob/2.13.x/lib/Doctrine/ORM/Query.php#L775
Adding /** @return $this */ will solve the issue.

I opened the PR doctrine/orm#10238

@VincentLanglet
Copy link
Contributor

This will be fixed in 2.14 version of doctrine

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants