1.2.569. Inconsistent Concatenation¶
Concatenations happens within a string or using the dot operator. Using both is an inconsistent way of writing concatenations.
Switching methods of concatenation, sometimes in the same expression, is error prone. The reader gets confused, and may miss important information.
There are some situations where using concatenation are compulsory : when calling a constant, or a function, or make use of the escape sequence. Those are ignored in this analysis.
<?php
//Concatenation
$consistent = $a . 'b'. $c;
//Interpolation
$consistentToo = "{$a}b$c";
// Concatenation and interpolation
$inconsistent = $a . "b$c";
// Concatenation and interpolation too
$consistentThree = <<<CONSISTENT
{$a}b$c
CONSISTENT;
// Concatenation and interpolation collisions
$collision = theClass::CONSTANTE . "b{$c}".number_format($t, 2).' $CAD'."\n";
?>
1.2.569.1. Connex PHP features¶
1.2.569.1.1. Specs¶
Short name |
Structures/InconsistentConcatenation |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Examples |
|
Available in |