Skip to content

Commit

Permalink
Merge branch '2.15.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.15.x:
  Shorter deprecation message (doctrine#10357)
  Add Fully-Qualified class name in UnrecognizedField exception to ease debugging (doctrine#10342)
  Include parameter types in hydration cache key generation (doctrine#10355)
  Allow doctrine/instantiator 2 (doctrine#10351)
  • Loading branch information
derrabus committed Dec 31, 2022
2 parents 9062af4 + 515a3d8 commit 8b35dae
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ Use `toIterable()` instead.

# Upgrade to 2.14

## Deprecated `Doctrine\ORM\Persisters\Exception\UnrecognizedField::byName($field)` method.

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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"doctrine/deprecations": "^0.5.3 || ^1",
"doctrine/event-manager": "^1.2 || ^2",
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/instantiator": "^1.3",
"doctrine/instantiator": "^1.3 || ^2",
"doctrine/lexer": "^2.1 || ^3",
"doctrine/persistence": "^3.1.1",
"psr/cache": "^1 || ^2 || ^3",
Expand All @@ -39,7 +39,7 @@
"doctrine/coding-standard": "^11.0",
"phpbench/phpbench": "^1.0 || dev-master",
"phpstan/phpstan": "1.9.4",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.5.28@dev",
"psr/log": "^1 || ^2 || ^3",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^5.4 || ^6.0",
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 @@ -444,7 +444,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 @@ -1154,7 +1154,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 @@ -1673,7 +1673,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 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 8b35dae

Please sign in to comment.