1.2.788. No Choice

A conditional structure is being used, and both alternatives are the same, leading to the illusion of choice.

Either the condition is useless, and may be removed, or the alternatives need to be distinguished.

<?php

if ($condition == 2) {
    doSomething();
} else {
    doSomething();
}

$condition == 2 ?     doSomething() :     doSomething();

?>

1.2.788.1. Suggestions

  • Remove the conditional, and call the expression directly

  • Replace one of the alternative with a distinct call

  • Remove the whole conditional : it may end up being useless

  • Extract the common elements of the condition to make them obvious

1.2.788.2. Specs

Short name

Structures/NoChoice

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior, Rector, Top10

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

High

Examples

NextCloud, Zencart

Available in

Entreprise Edition, Community Edition, Exakat Cloud