Skip to content

[coding-style] Add NestedTernaryToMatchRector#7572

Merged
TomasVotruba merged 6 commits into
mainfrom
tv-match-null
Nov 6, 2025
Merged

[coding-style] Add NestedTernaryToMatchRector#7572
TomasVotruba merged 6 commits into
mainfrom
tv-match-null

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Oct 25, 2025

Kick of a rule https://x.com/GromNaN/status/1980916120623476893 from @GromNaN


image

Optional rule to allow use of match in verbose ternary conditions. Works best with 3+ nesting.

Now we're looking for edge cases :)

Comment thread rules/CodingStyle/Rector/Assign/NestedTernaryToMatchRector.php
@TomasVotruba TomasVotruba changed the title [coding-style] Add NestedTernaryToMatchTrueRector [coding-style] Add NestedTernaryToMatchRector Oct 25, 2025
@GromNaN
Copy link
Copy Markdown

GromNaN commented Oct 25, 2025

The ternary operator checks truthiness, while matches(true) checks strict true. You should cast to (bool) when the condition isn't guaranteed to be true.

@TomasVotruba
Copy link
Copy Markdown
Member Author

@GromNaN Could you share simple before/after code snippet?

@TomasVotruba
Copy link
Copy Markdown
Member Author

Let's ship first version to test in the wild 👍

@TomasVotruba TomasVotruba merged commit 3c8adb6 into main Nov 6, 2025
53 checks passed
@TomasVotruba TomasVotruba deleted the tv-match-null branch November 6, 2025 13:38
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants