Skip to content

Commit 6bc315f

Browse files
committed
fix
1 parent a13dbf4 commit 6bc315f

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

rules/DeadCode/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
use PhpParser\Node\Expr\BinaryOp\Plus;
1919
use PhpParser\Node\Expr\ClassConstFetch;
2020
use PhpParser\Node\Expr\UnaryMinus;
21+
use Rector\NodeTypeResolver\Node\AttributeKey;
2122
use Rector\PhpParser\Node\Value\ValueResolver;
2223
use Rector\Rector\AbstractRector;
24+
use Rector\ValueObject\Application\File;
2325
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2426
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2527

@@ -172,6 +174,14 @@ private function processBinaryPlusAndMinus(Plus | Minus $binaryOp): ?Expr
172174
return $binaryOp->left;
173175
}
174176

177+
private function isMulParenthesized(File $file, Mul $mul): bool
178+
{
179+
$oldTokens = $file->getOldTokens();
180+
$endTokenPost = $mul->getEndTokenPos();
181+
182+
return isset($oldTokens[$endTokenPost]) && (string) $oldTokens[$endTokenPost] === ')';
183+
}
184+
175185
private function processBinaryMulAndDiv(Mul | Div $binaryOp): ?Expr
176186
{
177187
if ($binaryOp->left instanceof ClassConstFetch || $binaryOp->right instanceof ClassConstFetch) {
@@ -186,6 +196,10 @@ private function processBinaryMulAndDiv(Mul | Div $binaryOp): ?Expr
186196
$binaryOp->left,
187197
1
188198
) && $this->nodeTypeResolver->isNumberType($binaryOp->right)) {
199+
if ($this->isMulParenthesized($this->file, $binaryOp)) {
200+
$binaryOp->right->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, true);
201+
}
202+
189203
return $binaryOp->right;
190204
}
191205

0 commit comments

Comments
 (0)