Pattern: Malformed concatenation spacing
Issue: -
This rule enforces padding around concatenation operators.
By default, the rule ensures there are zero spaces before and after the concatenation operator, as shown in the following code snippet:
$foo = $number.'-'.$letter;
Another common way of padding concatenation operators is to use a single space, as shown in the following code snippet:
$foo = $number . '-' . $letter;
If you prefer to write your code like this, you can set the spacing
property to 1
, or whatever padding you prefer.
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1" />
</properties>
</rule>
Sometimes long concatenation statements are broken over multiple lines to work within a maximum line length, but this rule will generate an error for these cases by default. Setting the ignoreNewlines
property to true
will allow newline characters before or after a concatenation operator, and any required padding for alignment.
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="ignoreNewlines" value="true" />
</properties>
</rule>