{"record":{"id":"66f79ef4eeaa6cbe","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-it-creates-unreadable","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as it creates unreadable code with messy checks; refactor the value to a sole type instead","messagePattern":"\"(.+?)\" rule is deprecated, as it creates unreadable code with messy checks; refactor the value to a sole type instead","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php","lineNumber":65,"sourceCode":"        return $items === [];\n    }\n}\nCODE_SAMPLE\n, [self::TREAT_AS_NON_EMPTY => \\false])]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [Empty_::class, BooleanNot::class];\n    }\n    /**\n     * @param Empty_|BooleanNot $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as it creates unreadable code with messy checks; refactor the value to a sole type instead', self::class));\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":68,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php#L47-L68","documentation":"Rector\\Strict\\Rector\\Empty_\\DisallowedEmptyRuleFixerRector is deprecated: refactor() throws Rector\\Exception\\ShouldNotHappenException on the first Empty_ or BooleanNot node. The rule tried to satisfy the strict/rule 'no empty()' policy by replacing empty()/!empty() with explicit type checks, but the generated comparisons were messy and hard to read. The accepted answer is to refactor the value so it has a single unambiguous type, after which a plain comparison replaces empty().","triggerScenarios":"The rule is listed in rector.php (often via an old custom 'strict' rule list) and the analyzed code contains empty(...) or !empty(...) or negated expressions; refactor() throws on the first Empty_/BooleanNot match.","commonSituations":"Enabling a copied 'strict' rule bundle after a rector upgrade; CI failing as soon as it scans a file using empty(); teams trying to ban empty() project-wide via rector.","solutions":["Remove DisallowedEmptyRuleFixerRector from rector.php.","Refactor the offending value to a single concrete type (e.g. always an array), then replace empty($x) with an explicit comparison like $x === [].","Enforce the 'no empty()' policy in code review or a sniff that only reports, instead of an automated rewrite."],"exampleFix":"// before (rector.php)\n->withRules([DisallowedEmptyRuleFixerRector::class])\n\n// after (rector.php) - removed; fix types by hand\n\n// before\nif (empty($items)) {\n    return [];\n}\n\n// after - $items is guaranteed to be an array\nif ($items === []) {\n    return [];\n}","handlingStrategy":"validation","validationCode":"use Rector\\Strict\\Rector\\Empty_\\DisallowedEmptyRuleFixerRector;\n\n$rules = [/* your list */ DisallowedEmptyRuleFixerRector::class];\nif (in_array(DisallowedEmptyRuleFixerRector::class, $rules, true)) {\n    throw new InvalidArgumentException('Rule deprecated; refactor the value to a sole type instead of rewriting empty()');\n}","typeGuard":null,"tryCatchPattern":"try {\n    exit($rectorApplication->run());\n} catch (\\Rector\\Exception\\ShouldNotHappenException $e) {\n    if (str_contains($e->getMessage(), 'DisallowedEmptyRuleFixerRector')) {\n        fwrite(STDERR, 'Remove the rule; fix variable types so empty() can become an explicit comparison.' . PHP_EOL);\n        exit(1);\n    }\n    throw $e;\n}","preventionTips":["Enforce 'no empty()' with a detector (slevomat coding standard sniff) that only reports, instead of an automated rewriter.","Narrow variable types first (PHPStan), then replace empty() manually with the exact comparison.","After rector upgrades, remove 'strict' bundle rules that now throw instead of rewriting."],"tags":["rector","php","strict","empty","code-quality","deprecated-rule"],"backgroundTag":"deprecated-api-invoked","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}