rectorphp/rector · error · ShouldNotHappenException

"%s" rule is deprecated, as it covers a very specific shape

Error message

"%s" rule is deprecated, as it covers a very specific shape of code with unclear purpose

What it means

BinaryOpStandaloneAssignsToDirectRector used to rewrite $count = $count + 1 into $count += 1 (and similar binary-op self-assignments) inside class methods, functions and closures. It is deprecated because it covers one very specific code shape with unclear purpose — a narrow cosmetic rewrite that does not belong in an upgrade/quality tool. refactor() now throws ShouldNotHappenException on every matched ClassMethod/Function_/Closure node.

Source

Thrown at rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php:51

{
    return 100 <=> 200;
}
CODE_SAMPLE
)]);
    }
    /**
     * @return array<class-string<Node>>
     */
    public function getNodeTypes(): array
    {
        return [ClassMethod::class, Function_::class, Closure::class];
    }
    /**
     * @param ClassMethod|Function_|Closure $node
     */
    public function refactor(Node $node): ?Node
    {
        throw new ShouldNotHappenException(sprintf('"%s" rule is deprecated, as it covers a very specific shape of code with unclear purpose', self::class));
    }
}

View on GitHub (pinned to 408fcb0ff1)

Solutions

  1. Remove BinaryOpStandaloneAssignsToDirectRector::class from rector.php and every imported set, then re-run dry-run
  2. Let your IDE or PHP-CS-Fixer handle $x = $x + 1 -> $x += 1 style nits if the team wants them
  3. If the rewrite matters to you, write a small custom Rector rule scoped to your codebase
  4. Search all of .php config files for the deprecated class name to catch indirect imports

Example fix

// before (rector.php)
->withRules([
    \Rector\CodingStyle\Rector\ClassMethod\BinaryOpStandaloneAssignsToDirectRector::class,
])
// code:
$total = $total + $amount;

// after (rector.php)
// rule removed
// code adjusted manually (or by IDE):
$total += $amount;
Defensive patterns

Strategy: validation

Validate before calling

$deprecated = ['BinaryOpStandaloneAssignsToDirectRector'];
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/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php and running rector over any file containing a class method, function or closure — i.e. virtually every PHP file. The throw fires from rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php:51 immediately.

Common situations: Legacy rector.php files or set bundles that enumerated this cosmetic rule keep referencing it after a rector/rector-prefixed upgrade. The crash appears on the first analysed file, which misleads developers into debugging Rector itself rather than their rule list.

Related errors


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