1.2.55. Assigned In One Branch

Report variables that are assigned in one branch, and not in the other.

<?php

if ($condition) {
    // $assigned_in_this_branch is assigned in only one of the branches
    $assigned_in_this_branch = 1;
    $also_assigned = 1;
} else {
    // $also_assigned is assigned in the two branches
    $also_assigned = 1;
}

?>

1.2.55.1. Suggestions

  • Assign in the second branch

  • Assign outside the condition

1.2.55.2. Specs

Short name

Structures/AssignedInOneBranch

Rulesets

All

Exakat since

1.0.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

assignation

Available in

Entreprise Edition, Exakat Cloud