rectorphp/rector · error · ShouldNotHappenException
"%s" is deprecated, as simplifying regex ranges is a persona
Error message
"%s" is deprecated, as simplifying regex ranges is a personal preference that can worsen readability
What it means
SimplifyRegexPatternRector used to shorten regex character ranges inside preg_* pattern strings, e.g. [0-9] to \d. It is deprecated because such simplification is a personal preference that can worsen readability (\d is Unicode-aware in some contexts, and [A-Za-z] is more self-documenting than [a-zA-Z] rewrites). refactor() now throws ShouldNotHappenException for every String_ node matched; the rule transforms nothing and exists only to break stale configs loudly.
Source
Thrown at rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php:52
preg_match('#[\w\d+]#', $value);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [String_::class];
}
/**
* @param String_ $node
*/
public function refactor(Node $node): ?String_
{
throw new ShouldNotHappenException(sprintf('"%s" is deprecated, as simplifying regex ranges is a personal preference that can worsen readability', self::class));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Remove SimplifyRegexPatternRector::class from rector.php and all imported set files, then re-run vendor/bin/rector dry-run
- If you want regex hygiene, review preg_ patterns manually or lint them with a dedicated regex tool
- Write a small custom rule if your team mandates [0-9] -> \d
- grep -r SimplifyRegexPatternRector . to catch indirect registrations
Example fix
// before (rector.php)
->withRules([
\Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector::class,
])
// after
// rule removed; regexes untouched:
preg_match('/[0-9]+/', $value); // stays as is Defensive patterns
Strategy: validation
Validate before calling
$deprecated = ['SimplifyRegexPatternRector'];
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
- Review regex style manually instead of automating range simplification
- Drop deprecated rules from rector.php before upgrading Rector
- Validate configs in CI with a dry-run against a fixture file
- Avoid String_-matching style rules; they touch nearly every file and fail loudly
When it happens
Trigger: Registering rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php and running rector over any file — the rule matches every String_ node, so the first string literal anywhere triggers the throw at rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php:52.
Common situations: Old configs with fine-grained CodeQuality rule lists or copied rule sets from tutorials still contain SimplifyRegexPatternRector after upgrading. Because String_ matches nearly every file, the crash occurs on the first analysed file and is often mistaken for a corrupted installation.
Related errors
- "%s" is deprecated as depends on context and personal prefer
- "%s" rule is deprecated, as it is a personal preference that
- "%s" rule is deprecated, as it is a personal preference that
- "%s" rule is deprecated, as it covers a very specific shape
- "%s" is deprecated as noisy change with little value. Use ma
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/216e7b5f26e47437.
Report an issue: GitHub.