Skip to content

Commit

Permalink
Add Fully-Qualified class name in UnrecognizedField exception to ease…
Browse files Browse the repository at this point in the history
… debugging
  • Loading branch information
Kern046 committed Dec 30, 2022
1 parent 27df173 commit 2de8a96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ final protected function updateTable(
$targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em);

if ($targetType === []) {
throw UnrecognizedField::byName($targetMapping->identifier[0]);
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $targetMapping->identifier[0]);
}

$types[] = reset($targetType);
Expand Down Expand Up @@ -1199,7 +1199,7 @@ final protected function getOrderBySQL(array $orderBy, string $baseTableAlias):
continue;
}

throw UnrecognizedField::byName($fieldName);
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $fieldName);
}

return ' ORDER BY ' . implode(', ', $orderByList);
Expand Down Expand Up @@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL(
return [$field];
}

throw UnrecognizedField::byName($field);
throw UnrecognizedField::byFullyQualifiedName($this->class->name, $field);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@

final class UnrecognizedField extends PersisterException
{
/** @deprecated This method is deprecated and will be removed in Doctrine ORM 3.0. Use {@see byFullyQualifiedName} instead */
public static function byName(string $field): self
{
return new self(sprintf('Unrecognized field: %s', $field));
}

/** @param class-string $className */
public static function byFullyQualifiedName(string $className, string $field): self
{
return new self(sprintf('Unrecognized field: %s::%s', $className, $field));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Persisters\Exception;

use Doctrine\ORM\Persisters\Exception\UnrecognizedField;
use Doctrine\Tests\Models\Taxi\Car;
use PHPUnit\Framework\TestCase;

class UnrecognizedFieldTest extends TestCase
{
public function testByFullyQualifiedName(): void
{
static::expectException(UnrecognizedField::class);
static::expectExceptionMessage('Unrecognized field: Doctrine\Tests\Models\Taxi\Car::color');

throw UnrecognizedField::byFullyQualifiedName(Car::class, 'color');
}
}

0 comments on commit 2de8a96

Please sign in to comment.