You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found your project on twitter the other day and after looking into it, it looks very interesting. 👍 good work so far
we are using the Doctrine/DBAL connection in our projects and not directly the PHP classes and functions. Is this somehow also supported? Or are your interfered types again replaced by the annotations and types of DBAL itself?
whats already possible today is re-using of SyntaxErrorInPreparedStatementMethodRule to get syntax error checking capabilities for queries which are known at analysis time - see readme
when time allows I am planning to add this by default with #66 (I don't use doctrine/dbal myself, so priorties are on other stuff)
what could be done on top of that is making phpstan aware of methods/functions/types involved while building query strings.
for example, if we would have phpstan extensions for the query builder api, queries like
could also be analyzable. to make this happen, phpstan needs to be able to resolve the following example
$query = $queryBuilder
->select('id', 'name')
->from('users')
->where('email = ?')->toString();
PHPStan\Testing\assertType('SELECT id, name FROM users WHERE email = ?', $query);
I am in the process of doing similar things for the REDAXO CMS and their rex_sql API in redaxo/core#4984
Or are your interfered types again replaced by the annotations and types of DBAL itself?
as phpstan-dba already works on the schema available in the database, I don't see value atm in reading the doctrine annotations. I think, if we would have the above mentioned steps implemented this might change though.
there were some issues found and also some errors during the execution 😁
I guess these things need to be fixed on your side:
\Doctrine\DBAL\Connection::query returns \Doctrine\DBAL\Driver\Statement and not Doctrine\DBAL\Result. I get errors like this: Call to an undefined method Doctrine\DBAL\Result<array<int|string, int>>::fetchColumn().
is it intentional that \PDOStatement::fetch does not return false anymore?
the counting of the query parameter is not correct sometimes
it seems to be case while using \PDO::prepare, then \PDOStatement::bindValue and then \PDOStatement::execute without parameter
I already found 2-3 things that really needs a fix on our side and that is a good thing 👍 nice work 💪
One downside is that the minimum requirement is PHP8, while we are still on PHP7.4 (on which the PHPStan check is running). And of course the the exceptions while checking some classes 😉
hmm the sources tell me a different story
oh, I forgot to mention that we use version 2.13 🙈 it is like this in version 3.x
✔️ for the result mode
I will have a look for some examples. for the errors I can not promise that, because the debug mode does not really says which code place is causing an exception. but once I have time again, I will have another look on that
@staabm Hey, it is kind of unclear from this issue to me if the Doctrine DBAL QueryBuilder is supported now or not. For me it is currently not working, but I am not sure if I screwed up the installation process or if it is not supported...
Activity
staabm commentedon Jan 12, 2022
Hi.
thx for the feedback.
whats already possible today is re-using of
SyntaxErrorInPreparedStatementMethodRuleto get syntax error checking capabilities for queries which are known at analysis time - see readmewhen time allows I am planning to add this by default with #66 (I don't use doctrine/dbal myself, so priorties are on other stuff)
what could be done on top of that is making phpstan aware of methods/functions/types involved while building query strings.
for example, if we would have phpstan extensions for the query builder api, queries like
could also be analyzable. to make this happen, phpstan needs to be able to resolve the following example
I am in the process of doing similar things for the REDAXO CMS and their
rex_sqlAPI in redaxo/core#4984as phpstan-dba already works on the schema available in the database, I don't see value atm in reading the doctrine annotations. I think, if we would have the above mentioned steps implemented this might change though.
mitelg commentedon Jan 12, 2022
that looks promising 👍
just FYI: https://github.com/phpstan/phpstan-doctrine/blob/master/src/Type/Doctrine/DBAL/QueryBuilder/QueryBuilderExecuteMethodExtension.php
in the PHPStan doctrine plugin, there is already a small evaluation of the Querybuilder methods, but it is only about what is
executeis giving back.I will try your extension, once I will find some time 😁
staabm commentedon Jan 17, 2022
just implemented this idea with zend framework 1 query builder:
https://twitter.com/markusstaab/status/1482999683911987201
mitelg commentedon Jan 19, 2022
hey @staabm
I tried your current master on our project https://github.com/shopware/shopware
there were some issues found and also some errors during the execution 😁
I guess these things need to be fixed on your side:
\Doctrine\DBAL\Connection::queryreturns\Doctrine\DBAL\Driver\Statementand notDoctrine\DBAL\Result. I get errors like this:Call to an undefined method Doctrine\DBAL\Result<array<int|string, int>>::fetchColumn().\PDOStatement::fetchdoes not returnfalseanymore?\PDO::prepare, then\PDOStatement::bindValueand then\PDOStatement::executewithout parameterthis error occurs while checking this class: https://github.com/shopware/shopware/blob/5.7/engine/Shopware/Core/sBasket.php (yes, it is a monster 🙈 )
I already found 2-3 things that really needs a fix on our side and that is a good thing 👍 nice work 💪
One downside is that the minimum requirement is PHP8, while we are still on PHP7.4 (on which the PHPStan check is running). And of course the the exceptions while checking some classes 😉
So right now, we can not use your extension, but:
staabm commentedon Jan 19, 2022
thx for the feedback @mitelg
hmm the sources tell me a different story 🤔
thats a setting on the RuntimeConfiguration.
since php8 started throwing exceptions it no longer returns false.
with #148 you can explicitly opt-in that you want to handle
falsereturns.hmm could you create a small reproducing example ?
bindValueis not yet supported though.. but maybe it false-positives atmmaybe I can provide a php 7.4 built sometime in the future. nevertheless I feel static analysis should use the latest php version, but phpstan should be configured for a lower php version
these should be fixed of course. reproducing examples would be awesome.
thank you so much
mitelg commentedon Jan 19, 2022
✔️ for the result mode
I will have a look for some examples. for the errors I can not promise that, because the debug mode does not really says which code place is causing an exception. but once I have time again, I will have another look on that
staabm commentedon Jan 19, 2022
I thinkt this monster should be fixed with #152
staabm commentedon Jan 19, 2022
should be fixed by #153
Seldaek commentedon Jan 19, 2022
I tried it out too, no error reported (except for #156), but also no type inference for this code here for example:
https://github.com/composer/packagist/blob/e3f76f42980e6477e453f13526e33ed174318ff2/src/Entity/DownloadRepository.php#L25-L37
I would have expected some type inference to happen for the result, but
\PHPStan\dumpTypeof$stmtand$resultoutputs:Maybe I missed something dumb, I am not sure, I had a long day :)
In second thought I suppose
phpstan-dba/config/dba.neon
Line 11 in 06e607a
staabm commentedon Jan 19, 2022
thank you for the early feedback
Doctrine Type inference atm works only for the cases mentioned in https://github.com/staabm/phpstan-dba/blob/main/tests/data/doctrine-dbal.php
correct
staabm commentedon Jan 20, 2022
with #164 we added new phpstan errors which get reported when a query cannot be analyzed because the involved types are not known.
staabm commentedon Jan 23, 2022
this should now be possible on the main branch with #191
staabm commentedon Jan 23, 2022
today I landed a lot of type inferrence stuff for doctrine dbal. its not yet in a release though:
https://twitter.com/markusstaab/status/1485239838630715398
mitelg commentedon Jan 24, 2022
I just tested version
0.2.6and it worked well 👌the
bindValuething still occurs, for example here: https://github.com/shopware/shopware/blob/5.7/engine/Shopware/Components/Session/PdoSessionHandler.php#L326One question regarding DBAL. having this code:
Shouldn't the plugin detect, that
idcannot be part of the result? 🤔staabm commentedon Jan 24, 2022
really cool, thx for the feedback.
just opened #199 so you can subscribe the issue and get notified when its supported (and I will not forget)
correct. this will work in the future. you can see what works atm in https://github.com/staabm/phpstan-dba/blob/main/tests/data/doctrine-dbal.php
#197 lists all apis which are not yet supported in type inference.
mitelg commentedon Jan 24, 2022
Nice, thank you 👍
I will close this issue, so we can talk about dedicated problems in own issues 😉 👍
staabm commentedon Jan 25, 2022
@mitelg with todays release this should work
danrot commentedon Oct 17, 2024
@staabm Hey, it is kind of unclear from this issue to me if the Doctrine DBAL
QueryBuilderis supported now or not. For me it is currently not working, but I am not sure if I screwed up the installation process or if it is not supported...staabm commentedon Oct 17, 2024
@danrot please report a new issue with a reproducer of your problem