1.2.1136. Single Use Variables¶
This is the list of variables that are written, then read, and only used once.
Single-use variables may be trimmed down, and the initial expression may be used instead.
Single-use variables may improve readability, when the final expression grows too much with the extra expression.
<?php
function foo($d) {
$a = 1; // $a is used twice
$b = $a + 2; // $b is used once
$c = $a + $b + $d; // $c is also used once
// $d is an argument, so it's OK.
retrun $c;
}
?>
1.2.1136.1. Connex PHP features¶
1.2.1136.1.1. Suggestions¶
Merge the two expressions into one larger
Make a second use of the variable
Inline the code of the expression instead of the variable
1.2.1136.1.2. Specs¶
Short name |
Variables/UniqueUsage |
Rulesets |
|
Exakat since |
1.3.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |