1.2.532. Identical Case In Switch

In a switch() or match() statement, when there are identical cases, it means that multiple case labels that have the same code block.

This can happen by mistake or design. They may be merged together.

<?php

switch($a) {
     case 1:
             $b = 2;
             break;

     case 2:
             $b = 12;
             break;

     // Identical to case 1
     case 3:
             $b = 2;
             break;
}

?>

1.2.532.1. Suggestions

  • Merge the cases and reduce the size of code

  • Review the cases code and make them different

1.2.532.2. Specs

Short name

Structures/IdenticalCase

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.5.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Features

dry

Available in

Entreprise Edition, Exakat Cloud