Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector\Fixture;

/**
* @see https://3v4l.org/qU0Ou
*/
class SkipObjectsInsideArray
{
public function run(\stdClass $firstValue, \stdClass $secondValue)
{
return [$firstValue] == [$secondValue];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeTraverser;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -78,7 +79,7 @@ public function refactor(Node $node): ?Node
$rightStaticType = $this->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;
}

Expand All @@ -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()) {
Expand Down