Skip to content

Commit 302d60f

Browse files
committed
fix
1 parent a52676b commit 302d60f

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_equal_numeric_string.php.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ final class SkipIdenticalNumericString
1010
return 'yes';
1111
}
1212

13+
if ('1' == $this->getValue()) {
14+
return 'yes 2';
15+
}
16+
1317
return 'no';
1418
}
1519

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
1313
use PHPStan\Type\BooleanType;
1414
use PHPStan\Type\MixedType;
15+
use PHPStan\Type\Type;
1516
use Rector\Rector\AbstractRector;
1617
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1718
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -73,6 +74,10 @@ public function refactor(Node $node): ?Node
7374
$leftStaticType = $this->nodeTypeResolver->getNativeType($node->left);
7475
$rightStaticType = $this->nodeTypeResolver->getNativeType($node->right);
7576

77+
if ($this->shouldSkipCompareNumericString($leftStaticType, $rightStaticType)) {
78+
return null;
79+
}
80+
7681
// objects can be different by content
7782
if (! $leftStaticType->isObject()->no() || ! $rightStaticType->isObject()->no()) {
7883
return null;
@@ -96,6 +101,15 @@ public function refactor(Node $node): ?Node
96101
return $this->processIdenticalOrNotIdentical($node);
97102
}
98103

104+
private function shouldSkipCompareNumericString(Type $leftStaticType, Type $rightStaticType): bool
105+
{
106+
if ($leftStaticType->isString()->yes() && $rightStaticType->isNumericString()->yes()) {
107+
return true;
108+
}
109+
110+
return $rightStaticType->isString()->yes() && $leftStaticType->isNumericString()->yes();
111+
}
112+
99113
private function processIdenticalOrNotIdentical(Equal|NotEqual $node): Identical|NotIdentical
100114
{
101115
if ($node instanceof Equal) {

0 commit comments

Comments
 (0)