{"record":{"id":"8510b7560c1cfbb7","repo":"symfony/routing","slug":"s-s-is-not-a-case-of-s","errorCode":null,"errorMessage":"\"%s::%s\" is not a case of \"%s\".","messagePattern":"\"(.+?)::(.+?)\" is not a case of \"(.+?)\"\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Requirement/EnumRequirement.php","lineNumber":44,"sourceCode":"    {\n        if (\\is_string($cases)) {\n            if (!is_subclass_of($cases, \\BackedEnum::class, true)) {\n                throw new InvalidArgumentException(\\sprintf('\"%s\" is not a \"BackedEnum\" class.', $cases));\n            }\n\n            $cases = $cases::cases();\n        } else {\n            $class = null;\n\n            foreach ($cases as $case) {\n                if (!$case instanceof \\BackedEnum) {\n                    throw new InvalidArgumentException(\\sprintf('Case must be a \"BackedEnum\" instance, \"%s\" given.', get_debug_type($case)));\n                }\n\n                $class ??= $case::class;\n\n                if (!$case instanceof $class) {\n                    throw new InvalidArgumentException(\\sprintf('\"%s::%s\" is not a case of \"%s\".', get_debug_type($case), $case->name, $class));\n                }\n            }\n        }\n\n        $this->requirement = implode('|', array_map(static fn ($e) => preg_quote($e->value), $cases));\n    }\n\n    public function __toString(): string\n    {\n        return $this->requirement;\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":57,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Requirement/EnumRequirement.php#L26-L57","documentation":"When EnumRequirement receives an array of enum cases, it verifies all cases belong to the same enum class; the first case's class is captured and any case that is not an instanceof it triggers this error. It also fires for typed mismatch between different enums in one array.","triggerScenarios":"new EnumRequirement([Status::Active, OtherStatus::Pending]) mixing cases of two different enums, or a dynamically-built array that accidentally includes a case from another enum.","commonSituations":"Building a list of allowed cases programmatically from several enums, refactoring that renamed/moved cases, or copy-pasting case lists across enums.","solutions":["Ensure all cases in the array come from one enum class","Pass the enum class-string instead of an array of cases","Fix the dynamic case-list builder to only pull from the intended enum"],"exampleFix":"// before\n$req = new EnumRequirement([Status::Active, OtherStatus::Pending]);\n// after\n$req = new EnumRequirement([Status::Active, Status::Inactive]);","handlingStrategy":"validation","validationCode":"$classes = array_unique(array_map(fn($c) => $c::class, $cases));\nif (count($classes) > 1) throw new \\InvalidArgumentException('Cases must come from a single enum');","typeGuard":"function isSingleEnumCaseList(array $cases): bool {\n    return $cases !== [] && count(array_unique(array_map(fn($c) => $c::class, $cases))) === 1;\n}","tryCatchPattern":"try {\n    $requirement = new EnumRequirement($cases);\n} catch (\\InvalidArgumentException $e) {\n    // fall back to building the list from a single enum: EnumRequirement(Status::class)\n}","preventionTips":["Build case arrays from a single enum via SomeEnum::cases() or array_filter","Don't merge case lists from different enums","Prefer the class-string constructor form"],"tags":["php","routing","enum","requirements"],"backgroundTag":"invalid-enum-value","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}