Reputation: 139
How can I force to be handle just as a string and not be interpreted by the IDE as something that it is not?
Granted the following string is rather unusual and gets identified as SQL by the IDE.
'SELECT {$selectors} FROM `{$table}`{$where}{$order}{$limit}{$offset}'
As you probably guessed by now, the placeholders are seen as invalid SQL code, and give me a slew of error in the IDE.
Already attempted to "fix" those issues via @noinspection, but there are multiple warnings and errors detected in that one line of code, that it is not feasible to suppress those "issues" one by one.
Another drawback is that some errors require me to disable some really useful inspections and I really don't want that.
So, is there a way just force PhpStorm to treat that one string as an actual string and not, in this case, SQL?
Upvotes: 0
Views: 369
Reputation: 165118
You may disable SQL Language Injection into all strings. Downside: it affects whole project (or even ALL projects, considering the fact that it's a built-in rule and therefore it's an IDE-wide setting).
This can be done at Settings/Preferences | Editor | Language Injections
.
An option just for that string is to forcibly inject Plain Text
language by placing /** @lang Text */
just before the string:
$s2 = /** @lang Text */'SELECT {$selectors} FROM `{$table}`{$where}{$order}{$limit}{$offset}';
See the difference:
P.S. Notice the difference between interpolated string (HEREDOC in this case; but the same is for sting using ""
as delimiters) vs ''
(single quotes/NOWDOC). It still sees it as SQL but shows no warnings (which means that IDE understand that $table
is something dynamic). But it could be just my settings -- checking it in my few-years-old Test project...
Upvotes: 3
Reputation: 1021
You can customize SQL parameters from the settings under Tools | Databases. Just add your placeholder pattern. Then SQL analyzer should recognize this as valid.
Upvotes: 2