Skip to content

Commit 28e98b3

Browse files
authored
Add Fully-Qualified class name in UnrecognizedField exception to ease debugging (#10342)
1 parent 99a37d8 commit 28e98b3

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

UPGRADE.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 2.14
22

3+
## Deprecated `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byName($field)` method.
4+
5+
It will be removed in 3.0. Use `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byFullyQualifiedName($className, $field)` instead.
6+
37
## Deprecated constants of `Doctrine\ORM\Internal\CommitOrderCalculator`
48

59
The following public constants have been deprecated:

lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ final protected function updateTable(
487487
$targetType = PersisterHelper::getTypeOfField($targetMapping->identifier[0], $targetMapping, $this->em);
488488

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

493493
$types[] = reset($targetType);
@@ -1199,7 +1199,7 @@ final protected function getOrderBySQL(array $orderBy, string $baseTableAlias):
11991199
continue;
12001200
}
12011201

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

12051205
return ' ORDER BY ' . implode(', ', $orderByList);
@@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL(
17571757
return [$field];
17581758
}
17591759

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

17631763
/**

lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php

+7
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010

1111
final class UnrecognizedField extends PersisterException
1212
{
13+
/** @deprecated This method is deprecated and will be removed in Doctrine ORM 3.0. Use {@see byFullyQualifiedName} instead */
1314
public static function byName(string $field): self
1415
{
1516
return new self(sprintf('Unrecognized field: %s', $field));
1617
}
18+
19+
/** @param class-string $className */
20+
public static function byFullyQualifiedName(string $className, string $field): self
21+
{
22+
return new self(sprintf('Unrecognized field: %s::$%s', $className, $field));
23+
}
1724
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Persisters\Exception;
6+
7+
use Doctrine\ORM\Persisters\Exception\UnrecognizedField;
8+
use Doctrine\Tests\Models\Taxi\Car;
9+
use PHPUnit\Framework\TestCase;
10+
11+
class UnrecognizedFieldTest extends TestCase
12+
{
13+
public function testByFullyQualifiedName(): void
14+
{
15+
static::expectException(UnrecognizedField::class);
16+
static::expectExceptionMessage('Unrecognized field: Doctrine\Tests\Models\Taxi\Car::$color');
17+
18+
throw UnrecognizedField::byFullyQualifiedName(Car::class, 'color');
19+
}
20+
}

0 commit comments

Comments
 (0)