rectorphp/rector · error · ShouldNotHappenException
"%s" rule is deprecated, as it is a coding standard preferen
Error message
"%s" rule is deprecated, as it is a coding standard preference with no real value
What it means
WrapEncapsedVariableInCurlyBracesRector used to rewrite "Value: $var" into "Value: {$var}" inside interpolated strings. It is deprecated because it is a coding-standard preference with no real value — both forms are semantically identical. refactor() now throws ShouldNotHappenException on every InterpolatedString node; the class remains only so deprecated configs fail fast.
Source
Thrown at rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php:46
{
echo "Hello {$world}!";
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [InterpolatedString::class];
}
/**
* @param InterpolatedString $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf('"%s" rule is deprecated, as it is a coding standard preference with no real value', self::class));
}
}
View on GitHub (pinned to 408fcb0ff1)
Solutions
- Remove WrapEncapsedVariableInCurlyBracesRector::class from rector.php and all imported sets, then re-run dry-run
- Enforce {$var} style with a coding-standard fixer (PHP-CS-Fixer) if the team still wants it
- Apply braces manually in the few places where they disambiguate, e.g. "{$prefix}s"
- grep -r WrapEncapsedVariableInCurlyBracesRector to catch every config reference
Example fix
// before (rector.php)
->withRules([
\Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector::class,
])
// code:
echo "Hello $name!";
// after (rector.php)
// rule removed
// code unchanged, or braced manually where needed:
echo "Hello {$name}s!"; Defensive patterns
Strategy: validation
Validate before calling
$deprecated = ['WrapEncapsedVariableInCurlyBracesRector'];
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
- Enforce brace style with a coding-standard fixer, not Rector
- Add {$var} manually only where adjacency demands it ("{$prefix}s")
- Delete deprecated rules from rector.php before upgrading
- Keep configs importing curated sets rather than exhaustive rule lists
When it happens
Trigger: Registering rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php and running rector over any file with a double-quoted interpolated string. The throw comes from rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php:46.
Common situations: Teams that standardised on {$var} style added this rule to rector.php years ago; after upgrading rector/rector-prefixed the rule throws instead of rewriting. Set packages copied between projects propagate the stale registration.
Related errors
- "%s" is deprecated, as converting string interpolation to sp
- "%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
- "%s" rule is deprecated, as it is a personal preference that
AI-assisted analysis of rectorphp/rector@408fcb0ff1 (2026-08-21).
Data as JSON: /api/errors/183b2bf365863297.
Report an issue: GitHub.