File tree Expand file tree Collapse file tree 2 files changed +36
-13
lines changed
rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture
rules/CodeQuality/Rector/Equal Expand file tree Collapse file tree 2 files changed +36
-13
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \CodeQuality \Rector \Equal \UseIdenticalOverEqualWithSameTypeRector \Fixture ;
4+
5+ /**
6+ * @see https://3v4l.org/I3GQS
7+ */
8+ final class SkipBoolEqualFloat
9+ {
10+ public function equal ()
11+ {
12+ // maybe compare to numeric string
13+ $ value = rand (0 , 1 ) ? 1.0 : null ;
14+
15+ var_dump (true == $ value );
16+ var_dump ($ value == true );
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -103,28 +103,33 @@ public function refactor(Node $node): ?Node
103103
104104 private function shouldSkipCompareBoolToNumeric (Type $ leftStaticType , Type $ rightStaticType ): bool
105105 {
106- // use ! ->no() as to verify both yes and maybe
107106 if ($ leftStaticType instanceof BooleanType) {
108- if (! $ rightStaticType ->isNumericString ()->no ()) {
109- return true ;
110- }
111-
112- return ! $ rightStaticType ->isInteger ()
113- ->no ();
107+ return $ this ->shouldSkipNumericType ($ rightStaticType );
114108 }
115109
116110 if ($ rightStaticType instanceof BooleanType) {
117- if (! $ leftStaticType ->isNumericString ()->no ()) {
118- return true ;
119- }
120-
121- return ! $ leftStaticType ->isInteger ()
122- ->no ();
111+ return $ this ->shouldSkipNumericType ($ leftStaticType );
123112 }
124113
125114 return false ;
126115 }
127116
117+ private function shouldSkipNumericType (Type $ type ): bool
118+ {
119+ // use ! ->no() as to verify both yes and maybe
120+ if (! $ type ->isNumericString ()->no ()) {
121+ return true ;
122+ }
123+
124+ if (! $ type ->isInteger ()
125+ ->no ()) {
126+ return true ;
127+ }
128+
129+ return ! $ type ->isFloat ()
130+ ->no ();
131+ }
132+
128133 private function processIdenticalOrNotIdentical (Equal |NotEqual $ node ): Identical |NotIdentical
129134 {
130135 if ($ node instanceof Equal) {
You can’t perform that action at this time.
0 commit comments