{"record":{"id":"ae804755ab7a9abd","repo":"rectorphp/rector","slug":"s-is-deprecated-as-noisy-change-with-little-val-ae8047","errorCode":null,"errorMessage":"\"%s\" is deprecated as noisy change with little value. Use manually or custom rule where needed instead","messagePattern":"\"(.+?)\" is deprecated as noisy change with little value\\. Use manually or custom rule where needed instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodingStyle/Rector/Closure/StaticClosureRector.php","lineNumber":52,"sourceCode":"\n    return 2;\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [Closure::class];\n    }\n    /**\n     * @param Closure $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" is deprecated as noisy change with little value. Use manually or custom rule where needed instead', self::class));\n    }\n}\n","sourceCodeStart":34,"sourceCodeEnd":55,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodingStyle/Rector/Closure/StaticClosureRector.php#L34-L55","documentation":"StaticClosureRector used to prepend static to closures (function () {...} -> static function () {...}) to prevent implicit $this binding. It is deprecated as a noisy change with little value — it rewrites every closure in a codebase for a micro-optimisation most projects never need. refactor() now throws ShouldNotHappenException on every Closure node; the rule is a tombstone that only exists to break configs that still enable it.","triggerScenarios":"Registering rules/CodingStyle/Rector/Closure/StaticClosureRector.php in config and running process/dry-run over any file containing a closure. The throw comes from rules/CodingStyle/Rector/Closure/StaticClosureRector.php:52 on the first closure visited.","commonSituations":"This rule was part of widely-copied CodingStyle setups, so many rector.php files and tutorial-derived set bundles still list it. After upgrading rector/rector-prefixed, the first dry-run over callback-heavy code (Collections, event dispatchers, array_map) crashes with this exception.","solutions":["Remove StaticClosureRector::class from rector.php and all imported set files, then re-run vendor/bin/rector dry-run","Mark only the closures that actually leak or hold references (long-lived listeners, queued callbacks) as static, manually","For blanket enforcement use PHP-CS-Fixer's static_lambda fixer, which is the appropriate tool for this style rule","grep -r StaticClosureRector across the repository to find every remaining registration"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodingStyle\\Rector\\Closure\\StaticClosureRector::class,\n])\n\n// after\n// rule removed; annotate hot/leak-prone closures by hand:\n$ids = array_map(static fn (Item $i) => $i->id, $items);","handlingStrategy":"validation","validationCode":"$deprecated = ['StaticClosureRector'];\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":["Use PHP-CS-Fixer static_lambda for blanket static-closure style","Annotate static manually on closures passed to long-lived consumers","Remove deprecated rules from rector.php before composer update","Keep a CI dry-run so stale registrations fail visibly"],"tags":["rector","php","deprecated-rule","closure","static","code-style"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}