{"record":{"id":"6217cf04fc55ff2e","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-it-covers-a-very-speci","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as it covers a very specific shape of code with unclear purpose","messagePattern":"\"(.+?)\" rule is deprecated, as it covers a very specific shape of code with unclear purpose","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php","lineNumber":51,"sourceCode":"{\n    return 100 <=> 200;\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [ClassMethod::class, Function_::class, Closure::class];\n    }\n    /**\n     * @param ClassMethod|Function_|Closure $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as it covers a very specific shape of code with unclear purpose', self::class));\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":54,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodingStyle/Rector/ClassMethod/BinaryOpStandaloneAssignsToDirectRector.php#L33-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodingStyle\\Rector\\ClassMethod\\BinaryOpStandaloneAssignsToDirectRector::class,\n])\n// code:\n$total = $total + $amount;\n\n// after (rector.php)\n// rule removed\n// code adjusted manually (or by IDE):\n$total += $amount;","handlingStrategy":"validation","validationCode":"$deprecated = ['BinaryOpStandaloneAssignsToDirectRector'];\nforeach (glob(__DIR__ . '/rector*.php') as $config) {\n    $src = file_get_contents($config);\n    foreach ($deprecated as $rule) {\n        if (str_contains($src, $rule)) {\n            fwrite(STDERR, \"Remove deprecated rule {$rule} from {$config}\\n\");\n            exit(1);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["rector","php","deprecated-rule","compound-assignment","code-style"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}