1212use PhpParser \Node \Expr \BinaryOp \NotIdentical ;
1313use PHPStan \Type \BooleanType ;
1414use PHPStan \Type \MixedType ;
15+ use PHPStan \Type \Type ;
1516use Rector \Rector \AbstractRector ;
1617use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
1718use 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,20 @@ public function refactor(Node $node): ?Node
96101 return $ this ->processIdenticalOrNotIdentical ($ node );
97102 }
98103
104+ private function shouldSkipCompareNumericString (Type $ leftStaticType , Type $ rightStaticType ): bool
105+ {
106+ // use ! ->no() as to support both yes and maybe
107+ if ($ leftStaticType instanceof BooleanType) {
108+ return ! $ rightStaticType ->isNumericString ()->no ();
109+ }
110+
111+ if ($ rightStaticType instanceof BooleanType) {
112+ return ! $ leftStaticType ->isNumericString ()->no ();
113+ }
114+
115+ return false ;
116+ }
117+
99118 private function processIdenticalOrNotIdentical (Equal |NotEqual $ node ): Identical |NotIdentical
100119 {
101120 if ($ node instanceof Equal) {
0 commit comments