Skip to content

Files

Latest commit

 

History

History
40 lines (28 loc) · 1.17 KB

Squiz.ControlStructures.ForLoopDeclaration.md

File metadata and controls

40 lines (28 loc) · 1.17 KB

Pattern: Malformed space around for

Issue: -

Description

Verifies that for structures have the correct padding inside their bracketed statement.

Configuration

By default, the rule ensures there are zero spaces following the opening bracket, and zero spaces preceding the closing bracket, as shown in the following code snippet:

for ($i = 0; $i < 10; $i++) {
    // Body.
}

Another common way of padding control structures is to use a single space, as shown in the following code snippet:

for ( $i = 0; $i < 10; $i++ ) {
    // Body.
}

If you prefer to write your code like this, you can set the requiredSpacesAfterOpen and requiredSpacesBeforeClose properties to 1, or whatever padding you prefer.

<rule ref="Squiz.ControlStructures.ForLoopDeclaration">
    <properties>
        <property name="requiredSpacesAfterOpen" value="1" />
        <property name="requiredSpacesBeforeClose" value="1" />
    </properties>
</rule>

Further Reading