diff --git a/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_equal_numeric_string.php.inc b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_equal_numeric_string.php.inc new file mode 100644 index 00000000000..512336194c2 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_equal_numeric_string.php.inc @@ -0,0 +1,18 @@ +nodeTypeResolver->getNativeType($node->left); $rightStaticType = $this->nodeTypeResolver->getNativeType($node->right); + if ($this->shouldSkipCompareNumericString($leftStaticType, $rightStaticType)) { + return null; + } + // objects can be different by content if (! $leftStaticType->isObject()->no() || ! $rightStaticType->isObject()->no()) { return null; @@ -96,6 +101,20 @@ public function refactor(Node $node): ?Node return $this->processIdenticalOrNotIdentical($node); } + private function shouldSkipCompareNumericString(Type $leftStaticType, Type $rightStaticType): bool + { + // use ! ->no() as to support both yes and maybe + if ($leftStaticType instanceof BooleanType) { + return ! $rightStaticType->isNumericString()->no(); + } + + if ($rightStaticType instanceof BooleanType) { + return ! $leftStaticType->isNumericString()->no(); + } + + return false; + } + private function processIdenticalOrNotIdentical(Equal|NotEqual $node): Identical|NotIdentical { if ($node instanceof Equal) {