Skip to content

Commit 8ec94ef

Browse files
[CodeQuality] Allow compare int and int<0, max> on UseIdenticalOverEqualWithSameTypeRector (#7416)
* [CodeQuality] Allow compare int and int<0, max> on UseIdenticalOverEqualWithSameTypeRector * [ci-review] Rector Rectify * fixture fix --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent f8d4f97 commit 8ec94ef

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed
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 IdenticalInteger
6+
{
7+
public function equal()
8+
{
9+
if ($this->getValue() == 1) {
10+
return 'yes';
11+
}
12+
13+
return 'no';
14+
}
15+
16+
/**
17+
* @return int<0, max>
18+
*/
19+
private function getValue(): int
20+
{
21+
return 1;
22+
}
23+
}
24+
25+
?>
26+
-----
27+
<?php
28+
29+
namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;
30+
31+
final class IdenticalInteger
32+
{
33+
public function equal()
34+
{
35+
if ($this->getValue() === 1) {
36+
return 'yes';
37+
}
38+
39+
return 'no';
40+
}
41+
42+
/**
43+
* @return int<0, max>
44+
*/
45+
private function getValue(): int
46+
{
47+
return 1;
48+
}
49+
}
50+
51+
?>

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

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

92+
if ($leftStaticType->isInteger()->yes() && $rightStaticType->isInteger()->yes()) {
93+
return $this->processIdenticalOrNotIdentical($node);
94+
}
95+
9296
// different types
9397
if (! $leftStaticType->equals($rightStaticType)) {
9498
return null;

rules/TypeDeclaration/PhpDocParser/TypeExpressionFromVarTagResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function resolveTypeExpressionFromVarTag(TypeNode $typeNode, Variable $va
110110
private function generateOrExpression(array $unionExpressions)
111111
{
112112
$booleanOr = new BooleanOr($unionExpressions[0], $unionExpressions[1]);
113-
if (count($unionExpressions) == 2) {
113+
if (count($unionExpressions) === 2) {
114114
return $booleanOr;
115115
}
116116

@@ -125,7 +125,7 @@ private function generateOrExpression(array $unionExpressions)
125125
private function generateAndExpression(array $intersectionExpressions)
126126
{
127127
$booleanAnd = new BooleanAnd($intersectionExpressions[0], $intersectionExpressions[1]);
128-
if (count($intersectionExpressions) == 2) {
128+
if (count($intersectionExpressions) === 2) {
129129
return $booleanAnd;
130130
}
131131

src/Configuration/OnlyRuleResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function resolve(string $rule): string
4848
}
4949

5050
$matching = array_unique($matching);
51-
if (count($matching) == 1) {
51+
if (count($matching) === 1) {
5252
return $matching[0];
5353
}
5454

0 commit comments

Comments
 (0)