Skip to content

Latest commit

 

History

History
66 lines (48 loc) · 1.93 KB

Squiz.Functions.FunctionDeclarationArgumentSpacing.md

File metadata and controls

66 lines (48 loc) · 1.93 KB

Pattern: Malformed function argument spacing

Issue: -

Description

Checks that arguments in function declarations are spaced correctly.

Configuration

By default, the rule ensures there are zero spaces before and after the equals sign, as shown in the following code snippet:

function foo($a='a', $b='b') {
    // Body.
}

Another common way of defining default values is to use a single space, as shown in the following code snippet:

function foo($a = 'a', $b = 'b') {
    // Body.
}

If you prefer to write your code like this, you can set the equalsSpacing property to 1, or whatever padding you prefer.

<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
    <properties>
        <property name="equalsSpacing" value="1" />
    </properties>
</rule>

Another of the rules this rule enforces is that functions have the correct padding inside their bracketed list of arguments. 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:

function foo($a, $b) {
    // Body.
}

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

function foo( $a, $b ) {
    // 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.Functions.FunctionDeclarationArgumentSpacing">
    <properties>
        <property name="requiredSpacesAfterOpen" value="1" />
        <property name="requiredSpacesBeforeClose" value="1" />
    </properties>
</rule>

Further Reading