Comments (5)
thanks for reporting. could you please provide a concrete code sample?
from phpstan-dba.
I have some code that clone a user with all its data.
- So I got an hardcoded list of known tables.
- Foreach on the list.
- SELECT * FROM each table
- Change some of the data (replace the userId used as a foreign key, ...)
- INSERT the new data in the same table
For the insert, I use a function that add backquote around column and table name.
/**
* @param literal-string $tableExpression
* @param array<string, mixed> $data
*/
private function insert(string $tableExpression, array $data): void
{
$backquotedTableExpression = "`$tableExpression`";
$backquotedData = [];
foreach ($data as $key => $value) {
$backquotedData["`$key`"] = $value;
}
$this->dbal->insert($backquotedTableExpression, $backquotedData);
}
So my real error message is
Argument#0 expects a literal string, got literal-string&non-falsy-string
But the error stay the same if I remove the backquote and pass $tableExpression
directly to dbal insert
Argument#0 expects a literal string, got literal-string
from phpstan-dba.
What is being checked in the DoctrineKeyValueStyleRule
is that the keys of the array passed to Doctrine\DBAL\Connection::insert
correspond to columns in the database. In your insert
function, PHPStan doesn't know the literal values of the keys of $data
, and therefore it cannot check that they are columns in the database.
Similarly for the table name, if PHPStan doesn't know the literal value of the string, it can't check that the table exists in the database.
If you are wrapping calls to Doctrine\DBAL\Connection
in your own class, e.g. My\Connection
, then you should probably be declaring its function in your PHPStan configuration instead of the Doctrine ones. For example:
services:
-
class: staabm\PHPStanDba\Rules\DoctrineKeyValueStyleRule
tags: [phpstan.rules.rule]
arguments:
classMethods:
- 'My\Connection::insert#1'
(Note: technically this rule checks for a constant string, so maybe the error message should be revised to replace "literal" -> "constant"?)
from phpstan-dba.
(Note: technically this rule checks for a constant string, so maybe the error message should be revised to replace "literal" -> "constant"?)
ohh I did not see that. we should not talk about literal
strings when we expect constant
strings and vice versa.
these are 2 different things - please fix that
from phpstan-dba.
@hemberger the code example mentioned in #560 (comment) should be concluded as not analyzable and we should not error (as long as we are not in debug mode)
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
- 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.