How to ignore error for a query wich is defined in several lines
I have to write a query like that
$sep = "";
$query = "SELECT * FROM `my_table` WHERE `id` IN(";
foreach ($my_array as $item_id) { $query .= $sep . $item_id;
$sep = ',';}
$query .= ")";
The final $query is OK, but phpstorm mark an error on the IN( -expression expect-
I tried with /** @codeCoverageIgnoreStart */
and /** @codeCoverageIgnoreEnd */
but the "error" is not ignored
Please sign in to leave a comment.
Hi there,
Why not prepare that part of the query in advance and then simply use the variable inside the string? This kind of approach:
codeCoverage has nothing to do here.
If anything, it's suppressing a specific inspection for the line (or the whole file) by using
https://www.jetbrains.com/help/phpstorm/disabling-and-enabling-inspections.html#suppress-inspections
Andriy: in this case I know that the query can be fixed... it just an example. I search solution for more complex situations like that
seam to be the solution, but how I know the "
InspectionNameHere
"@Ernesto Aides
The link I gave in the previous comment shows with animated pictures how it can be added via context menu: the IDE will add such a comment with the right name for you.
This is how it can be done in your code sample for undefined $my_array variable (assuming that's the only code in a file):
The thing is: if the error comes from a (lower) Lexer/Parser level, then it's about actual language syntax... and these kinds of errors cannot be suppressed ("this part is broken/incomplete and I may not continue there" kind of overall message -- sadly you cannot just say to the IDE "ignore broken syntax and treat it as a correct/valid").
AFAIK this is the case here (you are ending your SQL with `... IN(` -- there is no closing `)`)
The only way here would be telling the IDE that it's not an SQL in the string but an ordinary plain text:
(hurray, no SQL error any more)
Thanks, Andriy Bazanov, the
is OK for my issue
Thanks a lot!