From 6b25b21a0d2abfd134bce59d12b9318dbc374448 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 16 Oct 2026 08:26:51 +0200 Subject: [PATCH] [Php70] Preserve fallback parentheses on Identical/NotIdentical path in TernaryToNullCoalescingRector --- ...ep_right_parentheses_not_identical.php.inc | 29 +++++++++++++++++++ .../Ternary/TernaryToNullCoalescingRector.php | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_not_identical.php.inc diff --git a/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_not_identical.php.inc b/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_not_identical.php.inc new file mode 100644 index 00000000000..8ae9a3eb16e --- /dev/null +++ b/rules-tests/Php70/Rector/Ternary/TernaryToNullCoalescingRector/Fixture/keep_right_parentheses_not_identical.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php index 30177cb6a9d..e17ae0362a4 100644 --- a/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php +++ b/rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php @@ -95,10 +95,12 @@ public function refactor(Node $node): ?Node $ternaryCompareNode = $node->cond; if ($this->isNullMatch($ternaryCompareNode->left, $ternaryCompareNode->right, $checkedNode)) { + $this->preserveWrappedFallback($fallbackNode); return $this->createCoalesce($checkedNode, $fallbackNode); } if ($this->isNullMatch($ternaryCompareNode->right, $ternaryCompareNode->left, $checkedNode)) { + $this->preserveWrappedFallback($fallbackNode); return $this->createCoalesce($checkedNode, $fallbackNode); }