diff --git a/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_objects_inside_array.php.inc b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_objects_inside_array.php.inc new file mode 100644 index 00000000000..6ba21685646 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector/Fixture/skip_objects_inside_array.php.inc @@ -0,0 +1,14 @@ +nodeTypeResolver->getNativeType($node->right); // objects can be different by content - if (! $leftStaticType->isObject()->no() || ! $rightStaticType->isObject()->no()) { + if ($this->hasObjectType($leftStaticType) || $this->hasObjectType($rightStaticType)) { return null; } @@ -96,6 +97,21 @@ public function refactor(Node $node): ?Node return $this->processIdenticalOrNotIdentical($node); } + private function hasObjectType(Type $type): bool + { + $hasObjecType = false; + TypeTraverser::map($type, function (Type $type, callable $traverseCallback) use (&$hasObjecType): Type { + // maybe has object type? mark as object type + if (! $type->isObject()->no()) { + $hasObjecType = true; + } + + return $traverseCallback($type); + }); + + return $hasObjecType; + } + private function normalizeScalarType(Type $type): Type { if ($type->isString()->yes()) {