1.2.1396. Useless Switch

This switch has only one case. It may very well be replaced by a ifthen structure.

<?php
switch($a) {
    case 1:
        doSomething();
        break;
}

// Same as

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

1.2.1396.1. Suggestions

  • Turn the switch into a if/then for better readability

  • Add other cases to the switch, making it adapted to the situation

1.2.1396.2. Specs

Short name

Structures/UselessSwitch

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

switch

Examples

Phpdocumentor, Dolphin

Available in

Entreprise Edition, Exakat Cloud