1.2.743. Multiples Identical Case

Some cases are defined multiple times, but only one will be processed. Check the list of cases, and remove the extra one.

Exakat finds the value of the cases as much as possible, and ignore any dynamic cases (using variables). It is also possible to write a valid switch statement, with all identical cases, and yet, different meaning each time. This is considered an edge case, and shall be manually removed.

<?php

const A = 1;

case ($x) {
    case 1 :
        break;
    case true:    // This is a duplicate of the previous
        break;
    case 1 + 0:   // This is a duplicate of the previous
        break;
    case 1.0 :    // This is a duplicate of the previous
        break;
    case A :      // The A constant is actually 1
        break;
    case $y  :    // This is not reported.
        break;
    default:

}
?>

1.2.743.1. Suggestions

  • Remove the double case

  • Change the case to another and rightful value

1.2.743.2. Specs

Short name

Structures/MultipleDefinedCase

Rulesets

All, Analyze, CE, CI-checks, Rector

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

switch

ClearPHP

no-duplicate-case

Examples

SugarCrm, ExpressionEngine

Available in

Entreprise Edition, Community Edition, Exakat Cloud