1.2.872. One Expression Brackets Consistency

Brackets around one-line expressions are not consistent.

PHP makes bracket optional when a control structure pilot only one expression. Both are semantically identical.

This analysis reports code that uses brackets while the vast majority of other expressions uses none. Or the contrary. Another analysis, [Structures/Bracketless], reports the absence of brackets as an error.

<?php

// One expression with brackets
for($i = 0; $i < 10; $i++) { $c++; }

// One expression without bracket
for($i2 = 0; $i2 < 10; $i2++)  $c++;

?>

1.2.872.1. Specs

Short name

Structures/OneExpressionBracketsConsistency

Rulesets

All, Preferences

Exakat since

0.9.5

PHP Version

All

Severity

Time To Fix

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud