Skip to content

Commit

Permalink
Deprecate passing null to ClassMetadata::fullyQualifiedClassName()
Browse files Browse the repository at this point in the history
It can easily be avoided by the only caller.
  • Loading branch information
greg0ire committed Feb 24, 2024
1 parent 859e6af commit 3368c06
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade to 3.1

## Deprecate passing null to `ClassMetadata::fullyQualifiedClassName()`

Passing `null` to `Doctrine\ORM\ClassMetadata::fullyQualifiedClassName()` is
deprecated and will no longer be possible in 4.0.

## Deprecate array access

Using array access on instances of the following classes is deprecated:
Expand Down
12 changes: 12 additions & 0 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BackedEnum;
use BadMethodCallException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Deprecations\Deprecation;
use Doctrine\Instantiator\Instantiator;
use Doctrine\Instantiator\InstantiatorInterface;
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
Expand Down Expand Up @@ -2003,6 +2004,10 @@ protected function _storeAssociationMapping(AssociationMapping $assocMapping): v
*/
public function setCustomRepositoryClass(string|null $repositoryClassName): void
{
if ($repositoryClassName === null) {
$this->customRepositoryClassName = null;
}

$this->customRepositoryClassName = $this->fullyQualifiedClassName($repositoryClassName);
}

Expand Down Expand Up @@ -2475,6 +2480,13 @@ public function getAssociationMappedByTargetField(string $assocName): string
public function fullyQualifiedClassName(string|null $className): string|null
{
if ($className === null) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/11294',
'Passing null to %s is deprecated and will not be supported in Doctrine ORM 4.0',
__METHOD__,
);

return null;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Tests/ORM/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayObject;
use Doctrine\DBAL\Types\Types;
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Events;
use Doctrine\ORM\Mapping\ChainTypedFieldMapper;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -66,6 +67,8 @@

class ClassMetadataTest extends OrmTestCase
{
use VerifyDeprecations;

public function testClassMetadataInstanceSerialization(): void
{
$cm = new ClassMetadata(CmsUser::class);
Expand Down Expand Up @@ -1052,6 +1055,15 @@ public function testItAddingLifecycleCallbackOnEmbeddedClassIsIllegal(): void

$metadata->addLifecycleCallback('foo', 'bar');
}

public function testGettingAnFQCNForNullIsDeprecated(): void
{
$metadata = new ClassMetadata(self::class);

$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11294');

$metadata->fullyQualifiedClassName(null);
}
}

#[MappedSuperclass]
Expand Down

0 comments on commit 3368c06

Please sign in to comment.