Skip to content

Commit 155b0f3

Browse files
authored
[CodeQuality] Skip mix equal and identical on RepeatedOrEqualToInArrayRector (#7403)
* [CodeQuality] Skip mix equal and identical on RepeatedOrEqualToInArrayRector * Fix * Fix * Fix
1 parent 73031f7 commit 155b0f3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\BooleanOr\RepeatedOrEqualToInArrayRector\Fixture;
4+
5+
final class SkipMixEqualAndIdentical
6+
{
7+
public function demo()
8+
{
9+
$a = false;
10+
var_dump($a == 'a' || $a == 'b' || $a === null);
11+
}
12+
}

rules/CodeQuality/Rector/BooleanOr/RepeatedOrEqualToInArrayRector.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ public function refactor(Node $node): ?FuncCall
106106
$identicals = $this->betterNodeFinder->findInstanceOf($node, Identical::class);
107107
$equals = $this->betterNodeFinder->findInstanceOf($node, Equal::class);
108108

109-
if ($identicals !== [] && $equals === []) {
109+
if ($identicals !== []) {
110+
if ($equals !== []) {
111+
// mix identical and equals, keep as is
112+
// @see https://3v4l.org/24cFl
113+
return null;
114+
}
115+
110116
$args[] = new Arg(new ConstFetch(new Name('true')));
111117
}
112118

0 commit comments

Comments
 (0)