feat: add support for converting is_null ternaries to null coalescing operator#7890
feat: add support for converting is_null ternaries to null coalescing operator#7890Soean wants to merge 3 commits intorectorphp:mainfrom
Conversation
|
This can wait for PR: to be merged first and need sync to add check parentheses fixture on the right side of ternary. |
|
Please rebase latest main branch, add fixture like in PR: and verify enhancement like in there to cover parentheses in the if ($ternary->else instanceof Ternary && $this->isTernaryParenthesized($this->file, $ternary->cond, $ternary)) {
$ternary->else->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true);
}Thank you. |
|
Could you add additional fixture with parentheses in Then apply the if patch if needed. Thank you. |
|
@samsonasik Just looking into this PR. |
|
@TomasVotruba I've just checked that this $w = !is_null($c = $x) ? ($c = $x) : $d; cause change to $w = $c = $x ?? $d;so it still needs improvement, I will continue to separate PR. |
still needs improvement on parentheses usage
|
@Soean I've cherry-picked your commits at PR: |
This pull request extends the
TernaryToNullCoalescingRectorto support converting ternary expressions usingis_nulland its negation to the null coalescing operator (??).Fixes: rectorphp/rector#9648