Precedence Checks

Assignments in Conditions

If you make use of assignments in conditions, it sometimes happens that you add a new condition and forget to take precedence into account. As a result, you might easily change the result of the assignment to something that you did not intend:

if ($foo = $this->getFoo()) { }

// is extended to
if ($foo = $this->getFoo() && $foo->isEnabled()) { }

This pass verifies that all assignments in conditions which involve &&, ||, and, or have explicit parentheses set, or flags them if not.

For the above example that means that this check would suggest to change the assignment to one of the following versions:

// Accepted Version 1
if (($foo = $this->getFoo()) && $foo->isEnabled()) { }

// Accepted Version 2
if ($foo = ($this->getFoo() && $foo->isEnabled())) { }

Comparison Involving the Result of Bit Operations

If you compare the result of a bitwise operations and place it on the right side of a comparison operator, the resulting expression is likely not intended, but might go unnoticed:

// Returns always int(0).
return 0 === $foo & 4;
return (0 === $foo) & 4;

// More likely intended return: true/false
return 0 === ($foo & 4);