Skip to content

Files

Latest commit

 

History

History
47 lines (32 loc) · 1.24 KB

Generic.Strings.UnnecessaryStringConcat.md

File metadata and controls

47 lines (32 loc) · 1.24 KB

Pattern: Unnecessary string concatenation

Issue: -

Description

Catches concatenation of two string literals on the same line. These can be safely joined.

Example

Example of incorrect code:

echo '/..' . '/path/to/file.php';

Example of correct code:

echo '/../path/to/file.php';

Configuration

Sometimes long strings 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 allowMultiline property to true will get the rule to allow string concatenation if the string covers multiple lines.

<rule ref="Generic.Strings.UnnecessaryStringConcat">
    <properties>
        <property name="allowMultiline" value="true" />
    </properties>
</rule>

If the error property is set to false, a warning will be thrown for violations instead of an error.

<rule ref="Generic.Strings.UnnecessaryStringConcat">
    <properties>
        <property name="error" value="false" />
    </properties>
</rule>

Further Reading