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

  1. Remove SimplifyRegexPatternRector::class from rector.php and all imported set files, then re-run vendor/bin/rector dry-run
  2. If you want regex hygiene, review preg_ patterns manually or lint them with a dedicated regex tool
  3. Write a small custom rule if your team mandates [0-9] -> \d
  4. 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

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


AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21). Data as JSON: /api/errors/216e7b5f26e47437. Report an issue: GitHub.