Skip to content

Commit 460fdc9

Browse files
committed
Store TypeRegistry in property in SqlWalker instead of private helper methods
Replace getType()/hasType() helpers with a $typeRegistry property initialized in the constructor, avoiding repeated getConfiguration()->getTypeRegistry() chain calls.
1 parent ca76af4 commit 460fdc9

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

src/Query/SqlWalker.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Doctrine\DBAL\Connection;
99
use Doctrine\DBAL\LockMode;
1010
use Doctrine\DBAL\Platforms\AbstractPlatform;
11-
use Doctrine\DBAL\Types\Type;
11+
use Doctrine\DBAL\Types\TypeRegistry;
1212
use Doctrine\Deprecations\Deprecation;
1313
use Doctrine\ORM\EntityManagerInterface;
1414
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -140,6 +140,8 @@ class SqlWalker
140140
*/
141141
private readonly QuoteStrategy $quoteStrategy;
142142

143+
private readonly TypeRegistry $typeRegistry;
144+
143145
/** @phpstan-param array<string, QueryComponent> $queryComponents The query components (symbol table). */
144146
public function __construct(
145147
private readonly Query $query,
@@ -151,6 +153,7 @@ public function __construct(
151153
$this->conn = $this->em->getConnection();
152154
$this->platform = $this->conn->getDatabasePlatform();
153155
$this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
156+
$this->typeRegistry = $this->em->getConfiguration()->getTypeRegistry();
154157
}
155158

156159
/**
@@ -177,16 +180,6 @@ public function getEntityManager(): EntityManagerInterface
177180
return $this->em;
178181
}
179182

180-
private function getType(string $name): Type
181-
{
182-
return $this->em->getConfiguration()->getTypeRegistry()->get($name);
183-
}
184-
185-
private function hasType(string $name): bool
186-
{
187-
return $this->em->getConfiguration()->getTypeRegistry()->has($name);
188-
}
189-
190183
/**
191184
* Gets the information about a single query component.
192185
*
@@ -1300,7 +1293,7 @@ public function walkSelectExpression(AST\SelectExpression $selectExpression): st
13001293
$columnAlias = $this->getSQLColumnAlias($fieldMapping->columnName);
13011294
$col = $sqlTableAlias . '.' . $columnName;
13021295

1303-
$type = $this->getType($fieldMapping->type);
1296+
$type = $this->typeRegistry->get($fieldMapping->type);
13041297
$col = $type->convertToPHPValueSQL($col, $this->conn->getDatabasePlatform());
13051298

13061299
$sql .= $col . ' AS ' . $columnAlias;
@@ -1348,7 +1341,7 @@ public function walkSelectExpression(AST\SelectExpression $selectExpression): st
13481341
break;
13491342
}
13501343

1351-
$this->rsm->addScalarResult($columnAlias, $resultAlias, $this->em->getConfiguration()->getTypeRegistry()->lookupName($expr->getReturnType()));
1344+
$this->rsm->addScalarResult($columnAlias, $resultAlias, $this->typeRegistry->lookupName($expr->getReturnType()));
13521345

13531346
break;
13541347

@@ -1426,7 +1419,7 @@ public function walkObjectExpression(string $dqlAlias, array $partialFieldSet, s
14261419

14271420
$col = $sqlTableAlias . '.' . $quotedColumnName;
14281421

1429-
$type = $this->getType($mapping->type);
1422+
$type = $this->typeRegistry->get($mapping->type);
14301423
$col = $type->convertToPHPValueSQL($col, $this->platform);
14311424

14321425
$sqlParts[] = $col . ' AS ' . $columnAlias;
@@ -1461,7 +1454,7 @@ public function walkObjectExpression(string $dqlAlias, array $partialFieldSet, s
14611454

14621455
$col = $sqlTableAlias . '.' . $quotedColumnName;
14631456

1464-
$type = $this->getType($mapping->type);
1457+
$type = $this->typeRegistry->get($mapping->type);
14651458
$col = $type->convertToPHPValueSQL($col, $this->platform);
14661459

14671460
$sqlParts[] = $col . ' AS ' . $columnAlias;
@@ -1566,7 +1559,7 @@ public function walkNewObject(AST\NewObjectExpression $newObjectExpression, stri
15661559
$fieldType = $fieldMapping->type;
15671560
$col = trim($e->dispatch($this));
15681561

1569-
$type = $this->getType($fieldType);
1562+
$type = $this->typeRegistry->get($fieldType);
15701563
$col = $type->convertToPHPValueSQL($col, $this->platform);
15711564

15721565
$sqlSelectExpressions[] = $col . ' AS ' . $columnAlias;
@@ -2199,8 +2192,8 @@ public function walkInputParameter(AST\InputParameter $inputParam): string
21992192

22002193
if ($parameter) {
22012194
$type = $parameter->getType();
2202-
if (is_string($type) && $this->hasType($type)) {
2203-
return $this->getType($type)->convertToDatabaseValueSQL('?', $this->platform);
2195+
if (is_string($type) && $this->typeRegistry->has($type)) {
2196+
return $this->typeRegistry->get($type)->convertToDatabaseValueSQL('?', $this->platform);
22042197
}
22052198
}
22062199

0 commit comments

Comments
 (0)