PHP_CodeSniffer
PHP_CodeSniffer copied to clipboard
False positive Generic.ControlStructures.DisallowYodaConditions
Repost from https://github.com/squizlabs/PHP_CodeSniffer/issues/2962:
The
Generic.ControlStructures.DisallowYodaConditions
reports aUsage of Yoda conditions is not allowed; switch the expression order
error for the below code, which IMO is incorrect (the error, not the code).$var = ( (string) function_call( 'text' ) ) === '0';
@umherirrender provided a second code sample:
Another one:
return ( $group && $pos ) ? ( $pos % $group ) === 0 && ( $pos < 0 === $group < 0 ) : !$pos;
It seems that a boolean condition with two < 0 is not handled correctly by the sniff.
Work around: Add () around each part of the condition
@jlherren provided a third:
I'm also experiencing this, here's a very short example:
$a = 1 * (1 + 1) !== 0;