1.2.541. If With Same Conditions

Successive If / then structures that have the same condition may be either merged or have one of the condition changed.

Note that if the values used in the condition have been modified in the first if/then structure, the two distinct conditions may be needed.

<?php

if ($a == 1) {
    doSomething();
}

if ($a == 1) {
    doSomethingElse();
}

// May be replaced by
if ($a == 1) {
    doSomething();
    doSomethingElse();
}

?>

1.2.541.1. Suggestions

  • Merge the two conditions so the condition is used once.

  • Change one of the condition, so they are different

  • Make it obvious that the first condition is a try, preparing the normal conditions.

1.2.541.2. Specs

Short name

Structures/IfWithSameConditions

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

High

Examples

phpMyAdmin, Phpdocumentor

Available in

Entreprise Edition, Community Edition, Exakat Cloud