Skip to content

[CodingStyle] Deprecate NestedTernaryToMatchRector - #8241

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-nested-ternary-to-match
Jul 31, 2026
Merged

[CodingStyle] Deprecate NestedTernaryToMatchRector#8241
TomasVotruba merged 1 commit into
mainfrom
deprecate-nested-ternary-to-match

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

NestedTernaryToMatchRector is not part of any set - it only runs when registered by hand.

Beyond that, the output is rarely an improvement. match (true) over nested conditions reads as a lookup table while it is really a chain of unrelated boolean tests, so the intent gets less obvious, not more:

-$value = $input > 100 ? 'more than 100' : ($input > 5 ? 'more than 5' : 'less');
+$value = match (true) {
+    $input > 100 => 'more than 100',
+    $input > 5 => 'more than 5',
+    default => 'less',
+};

Both versions hide the same problem. The useful refactoring is explicit intent - early returns or a named method - which no rule can decide for you.

Standard deprecation shape: implements DeprecatedInterface, refactor() throws, tests removed. The ConditionAndResult value object goes with it, it had no other use.

The rule is not part of any set, so it only runs when registered by
hand. On top of that, match(true) over nested conditions is often less
readable and more confusing than the ternary it replaces - explicit
intent, e.g. early returns or a named method, is the better refactoring.
@TomasVotruba
TomasVotruba merged commit 7df5a9a into main Jul 31, 2026
65 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-nested-ternary-to-match branch July 31, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant