diff --git a/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php b/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php new file mode 100644 index 00000000000..397ae423964 --- /dev/null +++ b/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php @@ -0,0 +1,21 @@ +getObjectClassNames(); + + if (count($objectClassNames) !== 1) { + return null; + } + + return $objectClassNames[0]; + } +} diff --git a/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php b/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php index 43db69006b3..9047d45f3da 100644 --- a/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php +++ b/src/StaticTypeMapper/ValueObject/Type/AliasedObjectType.php @@ -9,7 +9,7 @@ use PhpParser\Node\Stmt\UseUse; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; -use PHPStan\Type\TypeWithClassName; +use Rector\StaticTypeMapper\Resolver\ClassNameFromObjectTypeResolver; /** * @api @@ -55,13 +55,15 @@ public function areShortNamesEqual(self | FullyQualifiedObjectType $comparedObje public function equals(Type $type): bool { + $className = ClassNameFromObjectTypeResolver::resolve($type); + // compare with FQN classes - if ($type instanceof TypeWithClassName) { + if ($className !== null) { if ($type instanceof self && $this->fullyQualifiedClass === $type->getFullyQualifiedName()) { return true; } - if ($this->fullyQualifiedClass === $type->getClassName()) { + if ($this->fullyQualifiedClass === $className) { return true; } }