From a13dbf45f349feca1d9a44c96d1e8c849d11f03f Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 5 Feb 2026 15:09:40 +0700 Subject: [PATCH 1/2] [DeadCode] Handle multiply to parenthesized on RemoveDeadZeroAndOneOperationRector --- .../Fixture/with_parentheses.php.inc | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector/Fixture/with_parentheses.php.inc diff --git a/rules-tests/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector/Fixture/with_parentheses.php.inc b/rules-tests/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector/Fixture/with_parentheses.php.inc new file mode 100644 index 00000000000..1a2fc7268c4 --- /dev/null +++ b/rules-tests/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector/Fixture/with_parentheses.php.inc @@ -0,0 +1,27 @@ + +----- + From 6bc315ffabc3793155a204ae92cf34d9881c652c Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 5 Feb 2026 15:10:06 +0700 Subject: [PATCH 2/2] fix --- .../Plus/RemoveDeadZeroAndOneOperationRector.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php b/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php index 0cf1c2f05a1..de8f0d0f620 100644 --- a/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php +++ b/rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php @@ -18,8 +18,10 @@ use PhpParser\Node\Expr\BinaryOp\Plus; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\UnaryMinus; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; +use Rector\ValueObject\Application\File; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -172,6 +174,14 @@ private function processBinaryPlusAndMinus(Plus | Minus $binaryOp): ?Expr return $binaryOp->left; } + private function isMulParenthesized(File $file, Mul $mul): bool + { + $oldTokens = $file->getOldTokens(); + $endTokenPost = $mul->getEndTokenPos(); + + return isset($oldTokens[$endTokenPost]) && (string) $oldTokens[$endTokenPost] === ')'; + } + private function processBinaryMulAndDiv(Mul | Div $binaryOp): ?Expr { if ($binaryOp->left instanceof ClassConstFetch || $binaryOp->right instanceof ClassConstFetch) { @@ -186,6 +196,10 @@ private function processBinaryMulAndDiv(Mul | Div $binaryOp): ?Expr $binaryOp->left, 1 ) && $this->nodeTypeResolver->isNumberType($binaryOp->right)) { + if ($this->isMulParenthesized($this->file, $binaryOp)) { + $binaryOp->right->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true); + } + return $binaryOp->right; }