{"record":{"id":"66c93166d1ce1363","repo":"rectorphp/rector","slug":"s-rule-is-deprecated-as-risky-the-and","errorCode":null,"errorMessage":"\"%s\" rule is deprecated, as risky. The \"??\" and \"?:\" operators are not interchangeable and a regression has to be fixed manually","messagePattern":"\"(.+?)\" rule is deprecated, as risky\\. The \"\\?\\?\" and \"\\?:\" operators are not interchangeable and a regression has to be fixed manually","errorType":"exception","errorClass":"ShouldNotHappenException","httpStatus":null,"severity":"error","filePath":"rules/CodeQuality/Rector/Coalesce/CoalesceToTernaryRector.php","lineNumber":48,"sourceCode":"{\n\treturn $a ?: 'foo';\n}\nCODE_SAMPLE\n)]);\n    }\n    /**\n     * @return array<class-string<Node>>\n     */\n    public function getNodeTypes(): array\n    {\n        return [Coalesce::class];\n    }\n    /**\n     * @param Coalesce $node\n     */\n    public function refactor(Node $node): ?Node\n    {\n        throw new ShouldNotHappenException(sprintf('\"%s\" rule is deprecated, as risky. The \"??\" and \"?:\" operators are not interchangeable and a regression has to be fixed manually', self::class));\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":51,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/rules/CodeQuality/Rector/Coalesce/CoalesceToTernaryRector.php#L30-L51","documentation":"CoalesceToTernaryRector used to rewrite $a ?? $b into an equivalent ternary with isset(). It is deprecated because ?? (null coalescing) and ?: (elvis) are NOT interchangeable — ?? checks isset/null while ?: casts to bool — so automated rewriting caused regressions that had to be fixed by hand. The rule's refactor() now throws ShouldNotHappenException on every Coalesce node it visits; the class remains only as a tombstone so stale configs fail loudly instead of rewriting code.","triggerScenarios":"Registering rules/CodeQuality/Rector/Coalesce/CoalesceToTernaryRector.php in the Rector config and running process/dry-run over any PHP file containing a ?? (Coalesce) expression. The throw happens at rules/CodeQuality/Rector/Coalesce/CoalesceToTernaryRector.php:48 on the first coalesce expression encountered.","commonSituations":"A rector.php or imported set carried over from an older Rector version still lists CoalesceToTernaryRector; after upgrading the dependency, the first dry-run on any file with ?? crashes with this exception. Teams that kept a 'code quality' rule whitelist in a shared package hit it across many repositories at once.","solutions":["Delete CoalesceToTernaryRector::class from rector.php / the imported set and re-run vendor/bin/rector dry-run","If a specific ?? must become a ternary, rewrite that site manually and double-check isset vs falsy semantics","Keep ?? — it is the idiomatic modern form; there is no upgrade path requiring its removal","Search all config files (grep -r CoalesceToTernaryRector) to catch set files that import it indirectly"],"exampleFix":"// before (rector.php)\n->withRules([\n    \\Rector\\CodeQuality\\Rector\\Coalesce\\CoalesceToTernaryRector::class,\n])\n\n// after\n// rule removed; if truly needed, hand-convert:\n//   $name = $user->name ?? 'guest';  stays as is (preferred)\n//   $x = $a ?: $b;  only if you really mean falsy-check, write it yourself","handlingStrategy":"validation","validationCode":"$deprecated = ['CoalesceToTernaryRector'];\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":["Prune rector.php of deprecated rules before every Rector upgrade","Never mass-rewrite ?? to ?: — their null-vs-falsy semantics differ","Run dry-run in CI on a scratch branch so a guard throw never reaches main","Keep shared rule sets in version control and update them centrally when rules are removed"],"tags":["rector","php","deprecated-rule","coalesce","null-handling"],"backgroundTag":"rector-deprecated-rule","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}