Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\Tests\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector\Fixture;

class SkipConstants
{
public const ONE = 1;

public function run()
{
$value = 5 * self::ONE;
$value = 5 / self::ONE;
$value = self::ONE * 5;
$value = self::ONE / 5;
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector\Fixture;

class SkipConstants
{
public const ONE = 1;

public function run()
{
$value = 5 * self::ONE;
$value = 5 / self::ONE;
$value = self::ONE * 5;
$value = self::ONE / 5;
}
}

?>
Comment on lines +17 to +37
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second part is unneeded for equal content

Suggested change
?>
-----
<?php
namespace Rector\Tests\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector\Fixture;
class SkipConstants
{
public const ONE = 1;
public function run()
{
$value = 5 * self::ONE;
$value = 5 / self::ONE;
$value = self::ONE * 5;
$value = self::ONE / 5;
}
}
?>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I'll get this merged and fixup as the main work is done 👍

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Expr\BinaryOp\Minus;
use PhpParser\Node\Expr\BinaryOp\Mul;
use PhpParser\Node\Expr\BinaryOp\Plus;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\UnaryMinus;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -169,6 +170,10 @@ private function processBinaryPlusAndMinus(Plus | Minus $binaryOp): ?Expr

private function processBinaryMulAndDiv(Mul | Div $binaryOp): ?Expr
{
if ($binaryOp->left instanceof ClassConstFetch || $binaryOp->right instanceof ClassConstFetch) {
return null;
}

if (! $this->areNumberType($binaryOp)) {
return null;
}
Expand Down