Closed u01jmg3 closed 8 years ago
Your sample code doesn't produce any DoubleQuoteUsage errors in my testing. What are you seeing?
Apologies - the sample code wasn't complete. This is an extract from a custom footer for use with dompdf and in order that the inline PHP can be parsed by dompdf, you must use double quotes unescaped.
2 | ERROR | [x] String " " does not require double quotes; use
| | single quotes instead
2 | ERROR | [x] String "." does not require double quotes; use
| | single quotes instead
2 | ERROR | [ ] Inline shorthand IF statement requires brackets
| | around comparison
2 | ERROR | [x] String "..." does not require double quotes; use
| | single quotes instead
2 | ERROR | [x] String "(" does not require double quotes; use
| | single quotes instead
2 | ERROR | [x] String "-" does not require double quotes; use
| | single quotes instead
2 | ERROR | [x] String ")" does not require double quotes; use
| | single quotes instead
The problem is that PHPCS (and the PHP tokenizer) is not seeing any PHP code at all until you hit the <?php
token inside the string. From that point, you're going to potentially have problems because the PHP outside these tags is going to be ignored.
There isn't anything the sniff can do to detect that you are writing PHP outside of PHP tags, so you're just going to need to ignore these errors for this file.
Here is an extract from the annotated ruleset to help with that:
<!--
You can also hard-code ignore patterns for specific sniffs,
a feature not available on the command line. Please note that
all sniff-specific ignore patterns are checked using absolute paths.
The code here will hide all messages from the Squiz DoubleQuoteUsage
sniff for files that match either of the two exclude patterns.
-->
<rule ref="Squiz.Strings.DoubleQuoteUsage">
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/data/*</exclude-pattern>
</rule>
Is this a possible solution for you?
Thanks @gsherwood - I thought there would have to be some sort of exclusion to get around this. This will work
Good news. Thanks for getting back to me.
Is there any way to prevent the
DoubleQuoteUsage
rule from firing suggesting to use single quotes rather than double quotes when inline PHP is quoted?