1.2.1128. 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.1128.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.1128.2. Specs

Short name

Variables/UniqueUsage

Rulesets

All

Exakat since

1.3.0

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

variable

Available in

Entreprise Edition, Exakat Cloud