{"record":{"id":"5bf9569073ed2148","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-splitting-a-single-ret","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as splitting a single return into multiple early returns makes the code longer and harder to read","messagePattern":"\"(.+?)\" rule is deprecated, as splitting a single return into multiple early returns makes the code longer and harder to read","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php","lineNumber":52,"sourceCode":"        if ($this->something()) {\n            return true;\n        }\n        return (bool) $this->somethingElse();\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return NodeGroup::STMTS_AWARE;\n    }\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as splitting a single return into multiple early returns makes the code longer and harder to read', self::class));\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/EarlyReturn/Rector/Return_/ReturnBinaryOrToEarlyReturnRector.php#L34-L55","documentation":"Thrown when the deprecated ReturnBinaryOrToEarlyReturnRector rule executes. Its refactor() unconditionally throws ShouldNotHappenException: splitting a single `return $a || $b;` into multiple early returns was judged to make code longer and harder to read, so the transformation was withdrawn while the class stays behind to make stale configs fail fast.","triggerScenarios":"`rector process` with a config that still registers `\\Rector\\EarlyReturn\\Rector\\Return_\\ReturnBinaryOrToEarlyReturnRector::class`. Like its siblings it matches NodeGroup::STMTS_AWARE, so the very first function/method/loop body visited triggers the throw.","commonSituations":"Long-lived rector.php files carried across Rector major upgrades; configs assembled from copied snippets that enumerate EarlyReturn rules; CI failing after `composer update` because the rule now throws ShouldNotHappenException instead of rewriting returns.","solutions":["Remove the `ReturnBinaryOrToEarlyReturnRector::class` registration from your rector config and re-run.","Remove the sibling deprecated EarlyReturn rules (ChangeNestedIfsToEarlyReturnRector, ChangeOrIfContinueToMultiContinueRector) in the same cleanup.","If the early-return shape is wanted somewhere, refactor those returns manually or via a project-local custom rule.","Short-term fallback: pin the last Rector release where this rule still worked."],"exampleFix":"// before - rector.php\n$rectorConfig->rule(\\Rector\\EarlyReturn\\Rector\\Return_\\ReturnBinaryOrToEarlyReturnRector::class);\n\n// after - no registration; keep `return $a || $b;` or split manually","handlingStrategy":"validation","validationCode":"$config = file_get_contents('rector.php');\nif (strpos($config, 'ReturnBinaryOrToEarlyReturnRector') !== false) {\n    exit(\"Remove deprecated ReturnBinaryOrToEarlyReturnRector from rector.php before running rector.\\n\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use set-based configuration (UP_TO_PHP_xx level sets) rather than explicit deprecated EarlyReturn rules.","Add a CI check that fails when rector.php contains any class name ending in a known-deprecated rule.","Review the Rector changelog's 'removed/deprecated rules' section on every major upgrade."],"tags":["rector","php","deprecated-rule","static-analysis","config"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}