Skip to content

Files

Latest commit

 

History

History
77 lines (57 loc) · 2.09 KB

PEAR.Functions.FunctionCallSignature.md

File metadata and controls

77 lines (57 loc) · 2.09 KB

Pattern: Invalid function call signature

Issue: -

Description

Ensures function calls are formatted correctly.

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:

$foo = getValue($a, $b, $c);

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

$foo = getValue( $a, $b, $c );

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="PEAR.Functions.FunctionCallSignature">
    <properties>
        <property name="requiredSpacesAfterOpen" value="1" />
        <property name="requiredSpacesBeforeClose" value="1" />
    </properties>
</rule>

This rule also enforces the formatting of multi-line function calls. By default, multiple arguments can appear on each line, as shown in the following code snippet:

$returnValue = foo(
    $a, $b, $c,
    $d, $e
);

Another common way of defining multi-line function calls is to have one argument per line, as shown in the following code snippet:

$returnValue = foo(
    $a,
    $b,
    $c,
    $d,
    $e
);

If you prefer to write your code like this, you can set the allowMultipleArguments property to false.

<rule ref="PEAR.Functions.FunctionCallSignature">
    <properties>
        <property name="allowMultipleArguments" value="false" />
    </properties>
</rule>

By default, this rule ensures that each line in a multi-line function call is indented 4 spaces, but you can change the size of the indent by setting the indent property.

<rule ref="PEAR.Functions.FunctionCallSignature">
    <properties>
        <property name="indent" value="2" />
    </properties>
</rule>

Further Reading