Skip to content

Commit a665458

Browse files
committed
[CodeQuality] Allow compare float type on UseIdenticalOverEqualWithSameTypeRector
1 parent 8ec94ef commit a665458

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;
4+
5+
final class IdenticalFloat
6+
{
7+
public function equal()
8+
{
9+
if ($this->getValue() == 1.0) {
10+
return 'yes';
11+
}
12+
13+
return 'no';
14+
}
15+
16+
/**
17+
* @return float<0, max>
18+
*/
19+
private function getValue(): float
20+
{
21+
return 1.0;
22+
}
23+
}
24+
25+
?>
26+
-----
27+
<?php
28+
29+
namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;
30+
31+
final class IdenticalFloat
32+
{
33+
public function equal()
34+
{
35+
if ($this->getValue() === 1.0) {
36+
return 'yes';
37+
}
38+
39+
return 'no';
40+
}
41+
42+
/**
43+
* @return float<0, max>
44+
*/
45+
private function getValue(): float
46+
{
47+
return 1.0;
48+
}
49+
}
50+
51+
?>

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function refactor(Node $node): ?Node
9393
return $this->processIdenticalOrNotIdentical($node);
9494
}
9595

96+
if ($leftStaticType->isFloat()->yes() && $rightStaticType->isFloat()->yes()) {
97+
return $this->processIdenticalOrNotIdentical($node);
98+
}
99+
96100
// different types
97101
if (! $leftStaticType->equals($rightStaticType)) {
98102
return null;

0 commit comments

Comments
 (0)