From c52faf901c15ac81456e245679c183951377e293 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 26 Dec 2022 14:25:41 +0100 Subject: [PATCH] Add Fully-Qualified class name in UnrecognizedField exception to ease debugging --- UPGRADE.md | 4 ++++ .../Entity/BasicEntityPersister.php | 6 +++--- .../Exception/UnrecognizedField.php | 7 +++++++ .../Exception/UnrecognizedFieldTest.php | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php diff --git a/UPGRADE.md b/UPGRADE.md index e8d5802d1cf..76c509af424 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.14 +## Deprecated `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byName($field)` method. + +It will be removed in 3.0. Use `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byFullyQualifiedName($className, $field)` instead. + ## Deprecated constants of `Doctrine\ORM\Internal\CommitOrderCalculator` The following public constants have been deprecated: diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 6e6877e8952..0b655254dfd 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -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); @@ -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); @@ -1757,7 +1757,7 @@ private function getSelectConditionStatementColumnSQL( return [$field]; } - throw UnrecognizedField::byName($field); + throw UnrecognizedField::byFullyQualifiedName($this->class->name, $field); } /** diff --git a/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php b/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php index dd89fde1a4b..34df446fbdd 100644 --- a/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php +++ b/lib/Doctrine/ORM/Persisters/Exception/UnrecognizedField.php @@ -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)); + } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php b/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php new file mode 100644 index 00000000000..6597b7ab8c3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Persisters/Exception/UnrecognizedFieldTest.php @@ -0,0 +1,20 @@ +