Skip to content

Commit 79f98ea

Browse files
committed
DoctrineIdentityExtractor: Fix typ mixing
1 parent 3e22316 commit 79f98ea

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/DoctrineIdentityExtractor.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ public function extractIdentitiesMany(iterable $entities, bool $allowMixing = fa
5555
);
5656
}
5757

58-
$className = get_class($entity);
59-
60-
if (!$className) {
61-
throw new LogicException('Cannot get class name');
62-
}
63-
6458
if (!$allowMixing) {
6559
if (!$type) {
66-
$type = $className;
60+
$type = $this->getClassNameFromEntity($entity);
6761
} else {
68-
$this->checkType($className, $type);
62+
$this->checkType($entity, $type);
6963
}
7064
}
7165

@@ -93,11 +87,7 @@ public function extractIdentityMany(iterable $entities, bool $allowMixing = fals
9387

9488
if (!$allowMixing) {
9589
if (!$type) {
96-
$type = get_class($entity);
97-
98-
if (!$type) {
99-
throw new LogicException('Cannot get class name');
100-
}
90+
$type = $this->getClassNameFromEntity($entity);
10191
} else {
10292
$this->checkType($entity, $type);
10393
}
@@ -109,11 +99,20 @@ public function extractIdentityMany(iterable $entities, bool $allowMixing = fals
10999
return $ids;
110100
}
111101

102+
private function getClassNameFromEntity(object $entity): string
103+
{
104+
if ($entity instanceof Proxy) {
105+
return get_parent_class($entity);
106+
}
107+
108+
return get_class($entity);
109+
}
110+
112111
private function checkType(object $entity, string $type): void
113112
{
114-
if (get_class($entity) !== $type && !$entity instanceof Proxy && get_parent_class($entity) !== $type) {
113+
if (!$entity instanceof $type) {
115114
throw new InvalidArgumentException(
116-
sprintf('Given array must be an array of %s, %s contained in array', $type, $entity)
115+
sprintf('Given array must be an array of %s, %s contained in array', $type, $this->getClassNameFromEntity($entity))
117116
);
118117
}
119118
}

0 commit comments

Comments
 (0)