Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fully-Qualified class name in UnrecognizedField exception #10342

Merged
merged 1 commit into from
Dec 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
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 */
Kern046 marked this conversation as resolved.
Show resolved Hide resolved
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');
}
}