Repository navigation
Support \Doctrine\DBAL\Connection->query() syntax error checking - #66
Conversation
2a71382 to
106fc8b
Compare
\Doctrine\DBAL\Connection->query() syntax error checking
| - 'PDO::query#0' | ||
| - 'PDO::prepare#0' | ||
| - 'mysqli::query#0' | ||
| - 'Doctrine\DBAL\Connection::query#0' |
There was a problem hiding this comment.
This is actually deprecated. executeQuery($sql, $params), executeCacheQuery($sql, $params), executeStatement($sql, $params) and prepare($sql) are the current methods available on Doctrine\DBAL\Connection, but executeUpdate, exec and query are still supported and widely used so probably I'd keep them in as well.
There's also fetchAllNumeric, fetchAllNumeric, fetchAllAssociative, fetchAllKeyValue, fetchAllAssociativeIndexed, fetchFirstColumn, iterateNumeric, iterateAssociative, iterateKeyValue, iterateAssociativeIndexed, iterateColumn which are all shorthands for calling these on the returned PDOStatement/Result.
I'm not sure if it's as easy as listing all of them here? I guess it'd do it for the query, but what about checking $params? This is currently only working for direct PDO statements via PdoStatementExecuteMethodRule above is that correct? I guess this is more involved and would require a new rule?
There was a problem hiding this comment.
for prepared-statement style methods which take a $params array there is a https://github.com/staabm/phpstan-dba/blob/main/src/Rules/SyntaxErrorInPreparedStatementMethodRule.php rule which can be configured.
this rule expects that the query is passed as a 1st arg and params as a 2nd. but this seems to fit for executeQuery($sql, $params), executeCacheQuery($sql, $params), executeStatement($sql, $params)
There's also
fetchAllNumeric,fetchAllNumeric,fetchAllAssociative,fetchAllKeyValue,fetchAllAssociativeIndexed,fetchFirstColumn,iterateNumeric,iterateAssociative,iterateKeyValue,iterateAssociativeIndexed,iterateColumnwhich are all shorthands for calling these on the returned PDOStatement/Result.
I think for these methods we need custom return type extensions similar to https://github.com/staabm/phpstan-dba/blob/main/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
I'm not sure if it's as easy as listing all of them here?
listing these methods in the config at least enables the syntax error checking parts.
to make the type inference work, we need the extensions.
There was a problem hiding this comment.
I think for these methods we need custom return type extensions similar to https://github.com/staabm/phpstan-dba/blob/main/src/Extensions/PdoStatementFetchDynamicReturnTypeExtension.php
Yes absolutely for the return types, I was more concerned about getting the SQL/params validated everywhere. I think these could also be added to SyntaxErrorInPreparedStatementMethodRule.php then? All of them have the same basic arg signature.
There was a problem hiding this comment.
Yes absolutely for the return types, I was more concerned about getting the SQL/params validated everywhere. I think these could also be added to SyntaxErrorInPreparedStatementMethodRule.php then? All of them have the same basic arg signature.
exactly. just add the rule to the dba.neon config and list them.
the rule is not yet listed in dba.neon, as there is not yet a builtin method for this rule.
I am using it in a closed project already though for a different api. so it should work.
Based on https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/data-retrieval-and-manipulation.html#data-retrieval-and-manipulation
refs #94