Skip to content

Commit

Permalink
More QueryResultTypeWalker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 9, 2024
1 parent d1845c8 commit cad5050
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Type/Doctrine/Query/QueryResultTypeWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public function walkPathExpression($pathExpr): string

case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION:
if (isset($class->associationMappings[$fieldName]['inherited'])) {
/** @var class-string $newClassName */
$newClassName = $class->associationMappings[$fieldName]['inherited'];
$class = $this->em->getClassMetadata($newClassName);
}
Expand All @@ -255,6 +256,8 @@ public function walkPathExpression($pathExpr): string
}

$joinColumn = $assoc['joinColumns'][0];

/** @var class-string $assocClassName */
$assocClassName = $assoc['targetEntity'];

$targetClass = $this->em->getClassMetadata($assocClassName);
Expand Down Expand Up @@ -360,7 +363,7 @@ public function walkFunction($function): string
return $function->getSql($this);

case $function instanceof AST\Functions\AbsFunction:
$exprType = $this->unmarshalType($function->simpleArithmeticExpression->dispatch($this));
$exprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->simpleArithmeticExpression));

$type = TypeCombinator::union(
IntegerRangeType::fromInterval(0, null),
Expand Down Expand Up @@ -442,8 +445,8 @@ public function walkFunction($function): string
return $this->marshalType($type);

case $function instanceof AST\Functions\LocateFunction:
$firstExprType = $this->unmarshalType($function->firstStringPrimary->dispatch($this));
$secondExprType = $this->unmarshalType($function->secondStringPrimary->dispatch($this));
$firstExprType = $this->unmarshalType($this->walkStringPrimary($function->firstStringPrimary));
$secondExprType = $this->unmarshalType($this->walkStringPrimary($function->secondStringPrimary));

$type = IntegerRangeType::fromInterval(0, null);
if (TypeCombinator::containsNull($firstExprType) || TypeCombinator::containsNull($secondExprType)) {
Expand All @@ -465,8 +468,8 @@ public function walkFunction($function): string
return $this->marshalType($type);

case $function instanceof AST\Functions\ModFunction:
$firstExprType = $this->unmarshalType($function->firstSimpleArithmeticExpression->dispatch($this));
$secondExprType = $this->unmarshalType($function->secondSimpleArithmeticExpression->dispatch($this));
$firstExprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->firstSimpleArithmeticExpression));
$secondExprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->secondSimpleArithmeticExpression));

$type = IntegerRangeType::fromInterval(0, null);
if (TypeCombinator::containsNull($firstExprType) || TypeCombinator::containsNull($secondExprType)) {
Expand All @@ -481,7 +484,7 @@ public function walkFunction($function): string
return $this->marshalType($type);

case $function instanceof AST\Functions\SqrtFunction:
$exprType = $this->unmarshalType($function->simpleArithmeticExpression->dispatch($this));
$exprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->simpleArithmeticExpression));

$type = new FloatType();
if (TypeCombinator::containsNull($exprType)) {
Expand All @@ -492,10 +495,10 @@ public function walkFunction($function): string

case $function instanceof AST\Functions\SubstringFunction:
$stringType = $this->unmarshalType($function->stringPrimary->dispatch($this));
$firstExprType = $this->unmarshalType($function->firstSimpleArithmeticExpression->dispatch($this));
$firstExprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->firstSimpleArithmeticExpression));

if ($function->secondSimpleArithmeticExpression !== null) {
$secondExprType = $this->unmarshalType($function->secondSimpleArithmeticExpression->dispatch($this));
$secondExprType = $this->unmarshalType($this->walkSimpleArithmeticExpression($function->secondSimpleArithmeticExpression));
} else {
$secondExprType = new IntegerType();
}
Expand All @@ -514,6 +517,8 @@ public function walkFunction($function): string
assert(array_key_exists('metadata', $queryComp));
$class = $queryComp['metadata'];
$assoc = $class->associationMappings[$assocField];

/** @var class-string $assocClassName */
$assocClassName = $assoc['targetEntity'];
$targetClass = $this->em->getClassMetadata($assocClassName);

Expand Down Expand Up @@ -930,7 +935,7 @@ public function walkAggregateExpression($aggExpression): string
case 'AVG':
case 'SUM':
$type = $this->unmarshalType(
$aggExpression->pathExpression->dispatch($this)
$this->walkSimpleArithmeticExpression($aggExpression->pathExpression)
);

return $this->marshalType(TypeCombinator::addNull($type));
Expand Down Expand Up @@ -1159,7 +1164,7 @@ public function walkInputParameter($inputParam): string
public function walkArithmeticExpression($arithmeticExpr): string
{
if ($arithmeticExpr->simpleArithmeticExpression !== null) {
return $arithmeticExpr->simpleArithmeticExpression->dispatch($this);
return $this->walkSimpleArithmeticExpression($arithmeticExpr->simpleArithmeticExpression);
}

if ($arithmeticExpr->subselect !== null) {
Expand Down Expand Up @@ -1302,7 +1307,10 @@ private function getTypeOfField(ClassMetadata $class, string $fieldName): array

$metadata = $class->fieldMappings[$fieldName];

/** @var string $type */
$type = $metadata['type'];

/** @var class-string<BackedEnum>|null $enumType */
$enumType = $metadata['enumType'] ?? null;

if (!is_string($enumType) || !class_exists($enumType)) {
Expand Down

0 comments on commit cad5050

Please sign in to comment.