1.2.1296. Unused Enumeration Case

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

The error message when the case is missing mentions a 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.1296.2. Connex PHP features

1.2.1296.2.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.1296.2.2. Specs

Short name

Enums/UnusedEnumCase

Rulesets

All, Analyze, Changed Behavior, 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

Related rule

Undefined Enumcase

Available in

Entreprise Edition, Exakat Cloud