Code Inspection: Expression without clarifying parentheses
Configure inspections: Settings | Editor | Inspections
Show intention actions: AltEnter
Reports potentially ambiguous expressions and proposes enclosing them in clarifying parentheses.
By using parentheses, you can increase code readability by grouping operations explicitly rather than relying on the implicit operator precedence and associativity. For more information, refer to Operator Precedence (php.net).
In the following example, several potential ambiguities are eliminated by introducing parentheses inside expressions.
Before
$a = 1 - 2 + 3;$b = true && false || true && false && true;$c = true ? $a == 2 : $a + 1 == 3 ? $a : !$b;
After
$a = (1 - 2) + 3;$b = (true && false) || (true && false && true);$c = true ? ($a == 2) : ($a + 1 == 3 ? $a : !$b);
Place the caret at the highlighted line and press AltEnter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.