-
Notifications
You must be signed in to change notification settings - Fork 99
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
Handle all hydration mode in QueryResultDynamicReturnTypeExtension #412
Conversation
01000d4
to
d92cfc3
Compare
I understand it's not an easy PR to review/try, but if you find time to take a new look it would be great @ondrejmirtes. Specifically because you reported in #404 (comment)
was reported as an error ; and I believe there might be an error in your code base rather than in my PR So I would need a confirmation from you Thanks. |
phpstan is able to infer this types without additional magic required
Use PHPStan's static reflection instead of runtime reflection.
This reverts commit 8c22f24.
Alright, I'm gonna merge this, try it on a few real-world projects, and either release it, or report back the errors. Thank you! |
Thanks ! :) |
One more failure: /**
* @return array{id: int, x: mixed, y: string, z: int, zz: string}|null
*/
private function b(): ?array
{
return $this->getEntityManager()->createQueryBuilder()
->from(xyz::class, 'abc')
->select('abc')
->getQuery()
->getOneOrNullResult(Query::HYDRATE_ARRAY);
} Here PHPStan complains: 157 Method
a::b()
should return array{id: int, x: mixed, y: string, z: int,
zz: string}|null but returns array|null. PHPStan should be able to look at entity fields and figure out that array shape is returned. |
This is kinda "tested" with 03741b4#diff-28394df5dba3e85fe86f9c8d9b05d6087fe897d0efa1d0c0ad3533a1f0252b99R158 I don't master enough this lib to look at entity fields in order to transform the object to an array shape (thanks to doctrine and object manager). Does something like this already exists in this plugin ? I understand
Is there ? This could be useful here... |
I don't know what the logic is in Doctrine to transform entity into an array with array hydration. But you can get all there is to know about an entity with |
Thanks, I find a solution with #443 Until I find a solution, if you prefer, I provided a general fix #444 which just revert this PR in the special case of getArrayResult with entities in the select. I'll prioritize fixing all the false-positive before improving the QueryResult analysis. |
I tried multiple times on my project similar queries and:
With
(Notice a bigint is returned as a string by Doctrine and not an int). With
I get
Is it a custom type @ondrejmirtes ? |
Good news - the problem with nullable primary key is project-specific problem that I was able to fix. I'm gonna try to reproduce another problem I'm seeing. |
See #446 |
Follow up of #404
Fix SingleScalarResult: to fix
Fix ArrayResult: to fix
For the last issue @ondrejmirtes,
I wonder if it couldn't be a bug in your codebase.