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
- Remove BinaryOpStandaloneAssignsToDirectRector::class from rector.php and every imported set, then re-run dry-run
- Let your IDE or PHP-CS-Fixer handle $x = $x + 1 -> $x += 1 style nits if the team wants them
- If the rewrite matters to you, write a small custom Rector rule scoped to your codebase
- 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
- Leave += / -= conversion to IDE quick-fixes or a CS fixer
- Drop rules with 'very specific shape' semantics from configs on upgrade
- Keep your rule list minimal: import sets, do not enumerate cosmetic rules
- Dry-run on a small fixture in CI to detect tombstone rules cheaply
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
- "%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
- "%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/6217cf04fc55ff2e.
Report an issue: GitHub.