diff --git a/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_bool_equal_integer.php.inc b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_bool_equal_integer.php.inc new file mode 100644 index 00000000000..78e249f481f --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_bool_equal_integer.php.inc @@ -0,0 +1,18 @@ +nodeTypeResolver->getNativeType($node->left); $rightStaticType = $this->nodeTypeResolver->getNativeType($node->right); - if ($this->shouldSkipCompareNumericString($leftStaticType, $rightStaticType)) { + if ($this->shouldSkipCompareBoolToNumeric($leftStaticType, $rightStaticType)) { return null; } @@ -101,15 +101,25 @@ public function refactor(Node $node): ?Node return $this->processIdenticalOrNotIdentical($node); } - private function shouldSkipCompareNumericString(Type $leftStaticType, Type $rightStaticType): bool + private function shouldSkipCompareBoolToNumeric(Type $leftStaticType, Type $rightStaticType): bool { - // use ! ->no() as to support both yes and maybe + // use ! ->no() as to verify both yes and maybe if ($leftStaticType instanceof BooleanType) { - return ! $rightStaticType->isNumericString()->no(); + if (! $rightStaticType->isNumericString()->no()) { + return true; + } + + return ! $rightStaticType->isInteger() + ->no(); } if ($rightStaticType instanceof BooleanType) { - return ! $leftStaticType->isNumericString()->no(); + if (! $leftStaticType->isNumericString()->no()) { + return true; + } + + return ! $leftStaticType->isInteger() + ->no(); } return false;