File tree Expand file tree Collapse file tree 3 files changed +94
-1
lines changed
rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture
rules/CodeQuality/Rector/Equal Expand file tree Collapse file tree 3 files changed +94
-1
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+ final class IdenticalBool
6+ {
7+ public function equal ()
8+ {
9+ if ($ this ->getValue () == true ) {
10+ return 'yes ' ;
11+ }
12+
13+ return 'no ' ;
14+ }
15+
16+ private function getValue (): bool
17+ {
18+ return true ;
19+ }
20+ }
21+
22+ ?>
23+ -----
24+ <?php
25+
26+ namespace Rector \Tests \CodeQuality \Rector \Equal \UseIdenticalOverEqualWithSameTypeRector \Fixture ;
27+
28+ final class IdenticalBool
29+ {
30+ public function equal ()
31+ {
32+ if ($ this ->getValue () === true ) {
33+ return 'yes ' ;
34+ }
35+
36+ return 'no ' ;
37+ }
38+
39+ private function getValue (): bool
40+ {
41+ return true ;
42+ }
43+ }
44+
45+ ?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \CodeQuality \Rector \Equal \UseIdenticalOverEqualWithSameTypeRector \Fixture ;
4+
5+ final class IdenticalString
6+ {
7+ public function equal ()
8+ {
9+ if ($ this ->getValue () == 'hi ' ) {
10+ return 'yes ' ;
11+ }
12+
13+ return 'no ' ;
14+ }
15+
16+ private function getValue (): string
17+ {
18+ return 'hello ' ;
19+ }
20+ }
21+
22+ ?>
23+ -----
24+ <?php
25+
26+ namespace Rector \Tests \CodeQuality \Rector \Equal \UseIdenticalOverEqualWithSameTypeRector \Fixture ;
27+
28+ final class IdenticalString
29+ {
30+ public function equal ()
31+ {
32+ if ($ this ->getValue () === 'hi ' ) {
33+ return 'yes ' ;
34+ }
35+
36+ return 'no ' ;
37+ }
38+
39+ private function getValue (): string
40+ {
41+ return 'hello ' ;
42+ }
43+ }
44+
45+ ?>
Original file line number Diff line number Diff line change 1010use PhpParser \Node \Expr \BinaryOp \Identical ;
1111use PhpParser \Node \Expr \BinaryOp \NotEqual ;
1212use PhpParser \Node \Expr \BinaryOp \NotIdentical ;
13+ use PHPStan \Type \BooleanType ;
1314use PHPStan \Type \MixedType ;
1415use Rector \Rector \AbstractRector ;
1516use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
@@ -86,7 +87,9 @@ public function refactor(Node $node): ?Node
8687 }
8788
8889 // different types
89- if (! $ leftStaticType ->equals ($ rightStaticType )) {
90+ if (! $ leftStaticType ->equals (
91+ $ rightStaticType
92+ ) && (! $ leftStaticType instanceof BooleanType && ! $ rightStaticType instanceof BooleanType)) {
9093 return null ;
9194 }
9295
You can’t perform that action at this time.
0 commit comments