Skip to content

Commit 0bd7797

Browse files
committed
Reuse code in ReflectionDescriptor
1 parent 95c38cc commit 0bd7797

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/Type/Doctrine/Descriptors/ReflectionDescriptor.php

+11-20
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,20 @@ public function getWritableToDatabaseType(): Type
7070

7171
public function getDatabaseInternalType(): Type
7272
{
73-
if (!$this->reflectionProvider->hasClass($this->type)) {
74-
return new MixedType();
75-
}
76-
77-
$registry = $this->container->getByType(DefaultDescriptorRegistry::class);
78-
$parents = $this->reflectionProvider->getClass($this->type)->getParentClassesNames();
79-
80-
foreach ($parents as $dbalTypeParentClass) {
81-
try {
82-
// this assumes that if somebody inherits from DecimalType,
83-
// the real database type remains decimal and we can reuse its descriptor
84-
return $registry->getByClassName($dbalTypeParentClass)->getDatabaseInternalType();
85-
86-
} catch (DescriptorNotRegisteredException $e) {
87-
continue;
88-
}
89-
}
90-
91-
return new MixedType();
73+
return $this->doGetDatabaseInternalType(null);
9274
}
9375

9476
public function getDatabaseInternalTypeForDriver(Connection $connection): Type
9577
{
78+
return $this->doGetDatabaseInternalType($connection);
79+
}
80+
81+
private function doGetDatabaseInternalType(?Connection $connection): Type
82+
{
83+
if (!$this->reflectionProvider->hasClass($this->type)) {
84+
return new MixedType();
85+
}
86+
9687
$registry = $this->container->getByType(DefaultDescriptorRegistry::class);
9788
$parents = $this->reflectionProvider->getClass($this->type)->getParentClassesNames();
9889

@@ -102,7 +93,7 @@ public function getDatabaseInternalTypeForDriver(Connection $connection): Type
10293
// the real database type remains decimal and we can reuse its descriptor
10394
$descriptor = $registry->getByClassName($dbalTypeParentClass);
10495

105-
return $descriptor instanceof DoctrineTypeDriverAwareDescriptor
96+
return $descriptor instanceof DoctrineTypeDriverAwareDescriptor && $connection !== null
10697
? $descriptor->getDatabaseInternalTypeForDriver($connection)
10798
: $descriptor->getDatabaseInternalType();
10899

0 commit comments

Comments
 (0)