-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Autodetect driver setup for precise int/float/bool inference in expressions (stringified or not) #506
Autodetect driver setup for precise int/float/bool inference in expressions (stringified or not) #506
Conversation
What about auto-detecting this from PhpVersion, and also from objectManagerLoader if one is provided? |
Note: |
@VincentLanglet Jan already drowned dozens of hours to get this right, it's a very complex topic as you can see in here https://github.com/janedbal/php-database-drivers-fetch-test/. Don't rush this :) |
Sorry if my message was heard like this, wasn't my intention. I thought one of the issue with this big PR was to write tests for all the build-in method, and that maybe I could find and offer time to this. Anyway, it will take the time it need to take ! :) |
The green CI here is misleading, there is still ton of work awaiting ( |
@VincentLanglet Pushed the WIP so that you can check the direction I'm leaning towards. |
Thanks, can I help you on this ? I notice there was conflict with the 1.3.x branch, do you have time to solve them or do you want me to try ? :) |
@VincentLanglet I've some stuff in backlog to do first before returning to this. But the outline what needs to be done:
And maybe more stuff I already forgot. I think you can easily help with (3) as such test can be added in standalone MR and possibly merged beforehand. The rest is just digging in code. |
I would take the little step by little step approach: untested drivers will returns the same type than before.
And if a untested-drivers user complains about the type, he/we just have test this drivers and update the code to support it.
What about starting with only the existing implemented aggregate functions ?
It could be easier to first, make a PR with those aggregate functions and then adding other aggregate one by one ?
The options I see are
and passing the driver. In next major the param will be required. This is often done by Symfony.
and implementing the interface ; then the check
could be made. I think the decision is more on @ondrejmirtes about how he wants to proceed in order to evolve such method signature. |
6439355
to
6a5b8bd
Compare
6a5b8bd
to
d2af4bf
Compare
b7fceff
to
dfcde6b
Compare
557e1eb
to
f02c1f0
Compare
Thanks @janedbal for your continued work on making this smarter and smarter 💙 |
157f942
to
95c38cc
Compare
After discussion with @ondrejmirtes we decided to separate some stuff to other PRs:
To minimize conflicts upon rebase, I squashed this MR. Here is a link to old commits if I ever need to check the real history: https://github.com/phpstan/phpstan-doctrine/commits/8c333fe |
0bd7797
to
9e2583e
Compare
@ruudk, @arnaud-lb, @VincentLanglet Would you mind testing this in your codebases? It would be very helpful to have this verified by more real-world codebases. Thank you! {
"require-dev": {
"phpstan/phpstan-doctrine": "dev-option-not-to-stringify-numeric-types"
},
"repositories": [
{
"type": "git",
"url": "git@github.com:janedbal/phpstan-doctrine.git"
}
]
} |
I tested it out on our large application (182 repositories, 16k files) and it works. Unfortunately, it could only remove 3 ignored errors 😅. I guess we don't use that many expressions, or we used Assert. |
I won't be able to test on a meaningful code base, but maybe @KmeCnin can? |
It may remove more ignored errors with #520. I also tried the branch @janedbal and
It's mainly because we already typed our code with things like But this PR will help us to change the |
Thank you so much! Let's see how well this fares in real-world projects :) |
Yeah, because PHPStan generally allows type widening. In our case, we have:
Those two rules ensure that I fix the types at least near the source and I can verify that the changes I made here are valid all over our codebase. |
Currently, inferring expressions types (e.g. results of
AVG
,SUM
etc) is imperfect as it is currently implemented to serve all configurations resulting in union types likeint|numeric-string
. This is painful to work with in real codebase with some specific configuration where you know it is alwaysint
.This PR introduces autodetection of driver & PHP version & connection setup to properly infer types in DQL expressions:
AVG(e.cost)
is more precise nowe.cost
behaves as beforemysqli, pdo_mysqli, pgsql, pdo_pgsql, sqlite3, pdo_sqlite
mixed
or union with stringified type (depending where it failed and if driver is known or not)bleedingEdge
enabled, connection failure is propagated and breaks your PHPStan executionEDIT: real connection no more needed since #586