{"record":{"id":"61699d752634e5dc","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-it-is-a-personal-prefe-61699d","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as it is a personal preference that can move ternary values out of their logical order","messagePattern":"\"(.+?)\" rule is deprecated, as it is a personal preference that can move ternary values out of their logical order","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php","lineNumber":56,"sourceCode":"            : $name;\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [Ternary::class];\n    }\n    /**\n     * @param Ternary $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as it is a personal preference that can move ternary values out of their logical order', self::class));\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":59,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php#L38-L59","documentation":"SwitchNegatedTernaryRector used to reorder ternaries so the negated condition reads positively (swap $a ?: $b branches). It is deprecated because the reordering is a personal preference that can move the ternary's values out of their logical order and confuse readers. refactor() now throws ShouldNotHappenException on every Ternary node; the rule body is intentionally dead.","triggerScenarios":"Registering rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php in the config and running rector over any file containing a ternary expression (?: or ? :). The throw comes from rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php:56 on the first ternary encountered.","commonSituations":"Stale rector.php rule lists or shared 'team standard' set files that still enumerate SwitchNegatedTernaryRector after upgrading rector/rector-prefixed. Since ternaries are ubiquitous, the first analysed file usually crashes.","solutions":["Remove SwitchNegatedTernaryRector::class from rector.php and every imported set, then re-run vendor/bin/rector dry-run","If a specific !condition ternary reads badly, invert that one site by hand","Avoid mechanical branch swapping in team style — treat it as a review-time judgement","Verify no custom set file re-adds the rule via grep -r SwitchNegatedTernaryRector"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodeQuality\\Rector\\Ternary\\SwitchNegatedTernaryRector::class,\n])\n// code:\n$value = !$isOk ? 'fail' : 'pass';\n\n// after (rector.php)\n// rule removed\n// code left alone, or inverted manually where it reads better:\n$value = $isOk ? 'pass' : 'fail';","handlingStrategy":"validation","validationCode":"$deprecated = ['SwitchNegatedTernaryRector'];\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":["Treat ternary branch order as a review preference, never an automated rewrite","Prune the rule list in rector.php during every Rector upgrade","Keep a fixture run in CI so deprecation guards fail the pipeline, not developers","Do not re-add rules deleted from upstream sets into local configs"],"tags":["rector","php","deprecated-rule","ternary","code-style"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}