rectorphp/rector · error · ShouldNotHappenException
"%s" is deprecated as risky change that does not handle enum
Error message
"%s" is deprecated as risky change that does not handle enum usage across the whole context. Handle it via IDE with full context, manually, or a custom rule instead
What it means
EnumCaseToPascalCaseRector used to rename enum cases and their usages to PascalCase. It is deprecated because the rename is risky when done by a rule that sees one file at a time — enum cases are referenced via Case-sensitive ::class-style fetches across the whole project, and Rector's file-local view cannot guarantee a complete, consistent rename. refactor() now throws ShouldNotHappenException on Enum_ and ClassConstFetch nodes; the rule does nothing but abort.
Source
Thrown at rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php:50
{
case Pending;
case Published;
case InReview;
case WaitingForApproval;
}
CODE_SAMPLE
)]);
}
public function getNodeTypes(): array
{
return [Enum_::class, ClassConstFetch::class];
}
/**
* @param Enum_|ClassConstFetch $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf('"%s" is deprecated as risky change that does not handle enum usage across the whole context. Handle it via IDE with full context, manually, or a custom rule instead', self::class));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Remove EnumCaseToPascalCaseRector::class from rector.php / imported sets and re-run vendor/bin/rector dry-run
- Rename enum cases in your IDE with full-project rename (Refactor -> Rename Symbol), which updates every usage safely
- If automation is required, write a custom rule that loads references project-wide, or run the rename in a dedicated commit verified by tests
- Audit shared set bundles for the deprecated rule name
Example fix
// before (rector.php)
->withRules([
\Rector\CodingStyle\Rector\Enum_\EnumCaseToPascalCaseRector::class,
]);
// code:
enum Status {
case in_progress;
}
// after (rector.php)
// rule removed; renamed via IDE full-project rename:
enum Status {
case InProgress;
}
// all Status::in_progress references updated to Status::InProgress by the IDE Defensive patterns
Strategy: validation
Validate before calling
$deprecated = ['EnumCaseToPascalCaseRector'];
foreach (glob(__DIR__ . '/rector*.php') as $config) {
$src = file_get_contents($config);
foreach ($deprecated as $rule) {
if (str_contains($src, $rule)) {
fwrite(STDERR, "Remove deprecated rule {$rule} from {$config}\n");
exit(1);
}
}
} Prevention
- Rename symbols with IDE project-wide refactor, never a file-local rule
- Decide enum case naming (PascalCase vs snake_case) before the first enum lands, in a coding standard
- Run tests after any enum rename to catch missed case references
- Remove deprecated rules from config on every Rector upgrade
When it happens
Trigger: Registering rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php and running rector over any file containing an enum declaration or a ClassConstFetch (any Foo::BAR constant/case access — extremely common). The throw fires at rules/CodingStyle/Rector/Enum_/EnumCaseToPascalCaseRector.php:50.
Common situations: Projects with snake_case enum cases (e.g. status enums like case in_progress) registered this rule to normalise naming, then upgraded rector/rector-prefixed and hit the guard. Because ClassConstFetch matches constant access everywhere, the crash triggers on nearly the first file analysed.
Related errors
- "%s" rule is deprecated, as turning a docblock type into a r
- "%s" rule is deprecated, as risky. The "??" and "?:" operato
- "%s" is deprecated as depends on context and personal prefer
- "%s" rule is deprecated, as it is a personal preference that
- "%s" is deprecated, as simplifying regex ranges is a persona
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/92df54b7aa3cdc60.
Report an issue: GitHub.