From f3eabc42ee0491a063bb069f8b68498e680c8814 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 24 Feb 2026 22:29:49 +0700 Subject: [PATCH 1/2] [Php70] Handle keep right parentheses on ternary else is BinaryOp on TernaryToNullCoalescingRector --- .../keep_right_parentheses_binaryop.php.inc | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_binaryop.php.inc diff --git a/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_binaryop.php.inc b/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_binaryop.php.inc new file mode 100644 index 00000000000..c8623cb74e5 --- /dev/null +++ b/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_binaryop.php.inc @@ -0,0 +1,27 @@ + +----- + From de2983897f82a70f964ade2a99feb65f7f4a40ac Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 24 Feb 2026 22:30:20 +0700 Subject: [PATCH 2/2] fix --- rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php index 5ff9d513d0a..9b9ad83aafb 100644 --- a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php +++ b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; @@ -114,7 +115,7 @@ private function processTernaryWithIsset(Ternary $ternary, Isset_ $isset): ?Coal return null; } - if ($ternary->else instanceof Ternary && $this->isTernaryParenthesized($this->file, $ternary->cond, $ternary)) { + if (($ternary->else instanceof Ternary || $ternary->else instanceof BinaryOp) && $this->isTernaryParenthesized($this->file, $ternary->cond, $ternary)) { $ternary->else->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true); }