Comments (17)
this error occurs while checking this class: shopware/shopware@
5.7
/engine/Shopware/Core/sBasket.php (yes, it is a monster 🙈 )
I thinkt this monster should be fixed with #152
from phpstan-dba.
- Another one is this with DBAL shopware/shopware@
5.7
/tests/Functional/Controllers/Backend/OrderTest.php#L390-L410
should be fixed by #153
from phpstan-dba.
One question regarding DBAL. having this code:
$test = $myDbalConnection->executeQuery('SELECT name, active FROM s_articles')->fetchAllAssociative(); $id = $test[0]['id'];
Shouldn't the plugin detect, that
id
cannot be part of the result? 🤔
@mitelg with todays release this should work
from phpstan-dba.
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::query
returns\Doctrine\DBAL\Driver\Statement
and notDoctrine\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 returnfalse
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 - Another one is this with DBAL https://github.com/shopware/shopware/blob/5.7/tests/Functional/Controllers/Backend/OrderTest.php#L390-L410
- it seems to be case while using
this error occurs while checking this class: https://github.com/shopware/shopware/blob/5.7/engine/Shopware/Core/sBasket.php (yes, it is a monster 🙈 )
Uncaught staabm\PHPStanDba\DbaException: Unexpected expression type PHPStan\Type\ArrayType in /home/mt/www/5.7dev/vendor/staabm/phpstan-dba/src/QueryReflection/QuerySimulation.php:72
#0 /home/mt/www/5.7dev/vendor/staabm/phpstan-dba/src/QueryReflection/QueryReflection.php(181): staabm\PHPStanDba\QueryReflection\QuerySimulation::simulateParamValueType()
#1 /home/mt/www/5.7dev/vendor/staabm/phpstan-dba/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php(100): staabm\PHPStanDba\QueryReflection\QueryReflection->resolveParameters()
#2 /home/mt/www/5.7dev/vendor/staabm/phpstan-dba/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php(80): staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule->checkErrors()
#3 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(94): staabm\PHPStanDba\Rules\SyntaxErrorInPreparedStatementMethodRule->processNode()
#4 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Node/ClassStatementsGatherer.php(95): PHPStan\Analyser\FileAnalyser->PHPStan\Analyser\{closure}()
#5 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(436): PHPStan\Node\ClassStatementsGatherer->__invoke()
#6 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2316): PHPStan\Analyser\NodeScopeResolver::PHPStan\Analyser\{closure}()
#7 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1369): PHPStan\Analyser\NodeScopeResolver->callNodeCallbackWithExpression()
#8 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1385): PHPStan\Analyser\NodeScopeResolver->processExprNode()
#9 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(2563): PHPStan\Analyser\NodeScopeResolver->PHPStan\Analyser\{closure}()
#10 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(1393): PHPStan\Analyser\NodeScopeResolver->processAssignVar()
#11 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(488): PHPStan\Analyser\NodeScopeResolver->processExprNode()
#12 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(289): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#13 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(451): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#14 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(289): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#15 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(535): PHPStan\Analyser\NodeScopeResolver->processStmtNodes()
#16 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/NodeScopeResolver.php(260): PHPStan\Analyser\NodeScopeResolver->processStmtNode()
#17 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/FileAnalyser.php(181): PHPStan\Analyser\NodeScopeResolver->processNodes()
#18 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Analyser/Analyser.php(69): PHPStan\Analyser\FileAnalyser->analyseFile()
#19 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyserRunner.php(62): PHPStan\Analyser\Analyser->analyse()
#20 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(163): PHPStan\Command\AnalyserRunner->runAnalyser()
#21 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseApplication.php(95): PHPStan\Command\AnalyseApplication->runAnalyser()
#22 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/src/Command/AnalyseCommand.php(173): PHPStan\Command\AnalyseApplication->analyse()
#23 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Command/Command.php(259): PHPStan\Command\AnalyseCommand->execute()
#24 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(848): _PHPStan_13047ff22\Symfony\Component\Console\Command\Command->run()
#25 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(259): _PHPStan_13047ff22\Symfony\Component\Console\Application->doRunCommand()
#26 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/vendor/symfony/console/Application.php(157): _PHPStan_13047ff22\Symfony\Component\Console\Application->doRun()
#27 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(94): _PHPStan_13047ff22\Symfony\Component\Console\Application->run()
#28 phar:///home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan.phar/bin/phpstan(95): _PHPStan_13047ff22\{closure}()
#29 /home/mt/www/5.7dev/vendor/phpstan/phpstan/phpstan(8): require('...')
#30 /home/mt/www/5.7dev/vendor/bin/phpstan(97): include('...')
#31 {main}
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:
from phpstan-dba.
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
from phpstan-dba.
because the debug mode does not really says which code place is causing an exception.
with #164 we added new phpstan errors which get reported when a query cannot be analyzed because the involved types are not known.
from phpstan-dba.
Hi.
thx for the feedback.
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
$queryBuilder
->select('id', 'name')
->from('users')
->where('email = ?')
->setParameter(0, $userInputEmail)
;
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/redaxo#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.
from phpstan-dba.
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 execute
is giving back.
I will try your extension, once I will find some time 😁
from phpstan-dba.
just implemented this idea with zend framework 1 query builder:
https://twitter.com/markusstaab/status/1482999683911987201
from phpstan-dba.
thx for the feedback @mitelg
\Doctrine\DBAL\Connection::query
returns\Doctrine\DBAL\Driver\Statement
and notDoctrine\DBAL\Result
hmm the sources tell me a different story 🤔
- is it intentional that
\PDOStatement::fetch
does not returnfalse
anymore?
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 false
returns.
- it seems to be case while using
\PDO::prepare
, then\PDOStatement::bindValue
and then\PDOStatement::execute
without parameter
hmm could you create a small reproducing example ? bindValue
is not yet supported though.. but maybe it false-positives atm
One downside is that the minimum requirement is PHP8, while we are still on PHP7.4 (on which the PHPStan check is running).
maybe 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
And of course the the exceptions while checking some classes
these should be fixed of course. reproducing examples would be awesome.
thank you so much
from phpstan-dba.
I tried it out too, no error reported (except for #156), but also no type inference for this code here for example:
I would have expected some type inference to happen for the result, but \PHPStan\dumpType
of $stmt
and $result
outputs:
Dumped type: Doctrine\DBAL\Result
Dumped type: array<int, array<string, mixed>>
Maybe I missed something dumb, I am not sure, I had a long day :)
In second thought I suppose
Line 11 in 06e607a
from phpstan-dba.
thank you for the early feedback
I would have expected some type inference to happen for the result
Doctrine Type inference atm works only for the cases mentioned in https://github.com/staabm/phpstan-dba/blob/main/tests/data/doctrine-dbal.php
is only checking input query/args, and not about the output. So probably this is normal and just not done yet.
correct
from phpstan-dba.
I tried it out too, no error reported (except for #156
this should now be possible on the main branch with #191
from phpstan-dba.
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
from phpstan-dba.
I just tested version 0.2.6
and it worked well 👌
the bindValue
thing still occurs, for example here: https://github.com/shopware/shopware/blob/5.7/engine/Shopware/Components/Session/PdoSessionHandler.php#L326
One question regarding DBAL. having this code:
$test = $myDbalConnection->executeQuery('SELECT name, active FROM s_articles')->fetchAllAssociative();
$id = $test[0]['id'];
Shouldn't the plugin detect, that id
cannot be part of the result? 🤔
from phpstan-dba.
I just tested version
0.2.6
and it worked well
really cool, thx for the feedback.
the
bindValue
thing still occurs, for example here: shopware/shopware@5.7
/engine/Shopware/Components/Session/PdoSessionHandler.php#L326
just opened #199 so you can subscribe the issue and get notified when its supported (and I will not forget)
Shouldn't the plugin detect, that
id
cannot be part of the result?
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.
from phpstan-dba.
Nice, thank you 👍
I will close this issue, so we can talk about dedicated problems in own issues 😉 👍
from phpstan-dba.
Related Issues (20)
- Unexpected query error
- Unexpected query error
- Inconsistency for string in query check between Record and Replay HOT 4
- `PDO::FETCH_KEY_PAIR` errors when selecting not exactly 2 columns
- SqlAst: throw when used with pgsql
- Argument expects a literal string, got literal-string HOT 5
- Connection::insert data inference does not use indicated Types HOT 4
- mysqli: error on invalid escaping HOT 5
- Query AST analysis? HOT 2
- Get AST data from `$queryReflection->getResultType` HOT 15
- AST doubts regarding null/not-null HOT 4
- AST: inconsistent behavior with functions and aliases HOT 4
- Analyzing multiple connections HOT 6
- Right vs left join HOT 2
- AST: generic operator support HOT 2
- pgsql support for AST HOT 2
- give up sql based narrowing in case sqlftw cannot parse the query
- pgsql support for uuid type
- Support for (PDO->prepare())->execute() HOT 6
- generic type mysqli_result error with phpstan v1.10.36 and v1.10.37 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpstan-dba.