Skip to content

Commit d926470

Browse files
committed
Fix
1 parent c8d2299 commit d926470

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPStan\Type\MixedType;
1717
use PHPStan\Type\StringType;
1818
use PHPStan\Type\Type;
19+
use PHPStan\Type\TypeTraverser;
1920
use Rector\Rector\AbstractRector;
2021
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2122
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -78,7 +79,7 @@ public function refactor(Node $node): ?Node
7879
$rightStaticType = $this->nodeTypeResolver->getNativeType($node->right);
7980

8081
// objects can be different by content
81-
if (! $leftStaticType->isObject()->no() || ! $rightStaticType->isObject()->no()) {
82+
if ($this->hasObjectType($leftStaticType) || $this->hasObjectType($rightStaticType)) {
8283
return null;
8384
}
8485

@@ -96,6 +97,21 @@ public function refactor(Node $node): ?Node
9697
return $this->processIdenticalOrNotIdentical($node);
9798
}
9899

100+
private function hasObjectType(Type $type): bool
101+
{
102+
$hasObjecType = false;
103+
TypeTraverser::map($type, function (Type $type, callable $traverseCallback) use (&$hasObjecType): Type {
104+
// maybe has object type? mark as object type
105+
if (! $type->isObject()->no()) {
106+
$hasObjecType = true;
107+
}
108+
109+
return $traverseCallback($type);
110+
});
111+
112+
return $hasObjecType;
113+
}
114+
99115
private function normalizeScalarType(Type $type): Type
100116
{
101117
if ($type->isString()->yes()) {

0 commit comments

Comments
 (0)