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

  1. Remove WrapEncapsedVariableInCurlyBracesRector::class from rector.php and all imported sets, then re-run dry-run
  2. Enforce {$var} style with a coding-standard fixer (PHP-CS-Fixer) if the team still wants it
  3. Apply braces manually in the few places where they disambiguate, e.g. "{$prefix}s"
  4. 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

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


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