Php_codesniffer: Question: is there a sniff which enforces `&&` over `and`, etc.?

Created on 12 Sep 2016  路  3Comments  路  Source: squizlabs/PHP_CodeSniffer

  • Is there a sniff which enforces && over and, || over or, etc.?
Question

All 3 comments

Include the Squiz.Operators.ValidLogicalOperators sniff in your ruleset to have it ban those operators. The errors look like this:

Logical operator "and" is prohibited; use "&&" instead (Squiz.Operators.ValidLogicalOperators.NotAllowed)
Logical operator "or" is prohibited; use "||" instead (Squiz.Operators.ValidLogicalOperators.NotAllowed)

I see there is no PHPCBF fix for this sniff - safer not to use PHPCBF for this?

The 'and' and '&&' operators (and the OR ones) don't execute code in the same way, so PHPCBF can't just replace those tokens and expect it to work in all cases. PHPCBF only corrects formatting errors as it knows the code will execute the same way after the changes.

Was this page helpful?
0 / 5 - 0 ratings