1.2.1286. Unused Enumeration Case

Those are enumeration cases which are defined, yet not used.

The error message when the case is missing mentions the class constant : this is because enumeration cases and class constants use the same configuration. They are only distinguished by their definition, which, here, does not exists.

<?php

enum x {
    case A;
    case C;

    const F = 1;
}

function foo(x $a) {}

foo(x::A);

?>

1.2.1286.1. Suggestions

  • Use the case in the code

  • Remove the case in the code

  • Fix the name of the case

  • Turn the case in a constant

1.2.1286.2. Specs

Short name

Enums/UnusedEnumCase

Rulesets

All, Analyze, Dead code

Exakat since

2.4.0

PHP Version

With PHP 8.1 and more recent

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

enum

Related rule

Undefined Enumcase

Available in

Entreprise Edition, Exakat Cloud