{"record":{"id":"67ae4d9e53891b76","repo":"rectorphp/rector","slug":"s-is-deprecated-as-match-true-with-nested-con","errorCode":null,"errorMessage":"\"%s\" is deprecated, as match(true) with nested conditions is often less readable than the original ternary","messagePattern":"\"(.+?)\" is deprecated, as match\\(true\\) with nested conditions is often less readable than the original ternary","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodingStyle/Rector/Assign/NestedTernaryToMatchRector.php","lineNumber":56,"sourceCode":"        };\n    }\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [Assign::class];\n    }\n    /**\n     * @param Assign $node\n     */\n    public function refactor(Node $node): ?Assign\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" is deprecated, as match(true) with nested conditions is often less readable than the original ternary', self::class));\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":59,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodingStyle/Rector/Assign/NestedTernaryToMatchRector.php#L38-L59","documentation":"NestedTernaryToMatchRector used to rewrite assignments containing nested ternaries into match (true) expressions. It is deprecated because match(true) with nested conditions is often LESS readable than the original ternary chain, especially for non-trivial conditions. refactor() now throws ShouldNotHappenException on every Assign node; the class was kept as a placeholder so deprecated registrations abort loudly.","triggerScenarios":"Registering rules/CodingStyle/Rector/Assign/NestedTernaryToMatchRector.php in config and running rector over any file with an assignment statement (the rule matches all Assign nodes, so effectively every file). The throw comes from rules/CodingStyle/Rector/Assign/NestedTernaryToMatchRector.php:56.","commonSituations":"A rector.php with a hand-tuned CodingStyle rule list, or an imported set package, still names NestedTernaryToMatchRector after upgrading Rector. Because Assign matches almost every PHP file, the exception surfaces on the first file processed and is frequently misread as a Rector internals bug.","solutions":["Remove NestedTernaryToMatchRector::class from rector.php and imported sets, then re-run vendor/bin/rector dry-run","Convert genuinely hairy nested ternaries to match (true) manually, only where it improves clarity","Alternatively flatten deep ternaries into if/elseif or a lookup map, case by case","grep -r NestedTernaryToMatchRector across configs to eliminate every registration"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodingStyle\\Rector\\Assign\\NestedTernaryToMatchRector::class,\n]);\n// code:\n$level = $score > 90 ? 'high' : ($score > 50 ? 'mid' : 'low');\n\n// after (rector.php)\n// rule removed\n// code rewritten by hand where it helps:\n$level = match (true) {\n    $score > 90 => 'high',\n    $score > 50 => 'mid',\n    default => 'low',\n};","handlingStrategy":"validation","validationCode":"$deprecated = ['NestedTernaryToMatchRector'];\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":["Convert nested ternaries to match (true) by hand, case by case","Delete rules from rector.php when the upstream version deprecates them","Avoid rules matching broad node types like Assign unless clearly valuable","Gate rector dry-run in CI so config rot is caught early"],"tags":["rector","php","deprecated-rule","ternary","match-expression","readability"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}