Skip to content

Commit

Permalink
Remove ClassMetadataInfo
Browse files Browse the repository at this point in the history
It has been deprecated for a long, long time.
  • Loading branch information
greg0ire committed May 2, 2022
1 parent b5610c2 commit 3f749bd
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 65 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 3.0

## BC BREAK: Remove `Doctrine\ORM\Mapping\ClassMetadataInfo`

Use `Doctrine\ORM\Mapping\ClassMetadata` instead.

## BC BREAK: Remove `Doctrine\ORM\Tools\DisconnectedClassMetadataFactory`

No replacement is provided.
Expand Down
24 changes: 3 additions & 21 deletions lib/Doctrine/ORM/Mapping/Builder/ClassMetadataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@

namespace Doctrine\ORM\Mapping\Builder;

use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;

use function get_class;

/**
* Builder Object for ClassMetadata
Expand All @@ -17,29 +13,15 @@
*/
class ClassMetadataBuilder
{
/** @var ClassMetadataInfo */
/** @var ClassMetadata */
private $cm;

public function __construct(ClassMetadataInfo $cm)
public function __construct(ClassMetadata $cm)
{
if (! $cm instanceof ClassMetadata) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/249',
'Passing an instance of %s to %s is deprecated, please pass a ClassMetadata instance instead.',
get_class($cm),
__METHOD__,
ClassMetadata::class
);
}

$this->cm = $cm;
}

/**
* @return ClassMetadataInfo
*/
public function getClassMetadata()
public function getClassMetadata(): ClassMetadata
{
return $this->cm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
use Doctrine\Persistence\Mapping\ReflectionService;
use InvalidArgumentException;
use LogicException;
Expand Down Expand Up @@ -71,7 +71,7 @@
* the serialized representation).
*
* @template-covariant T of object
* @template-implements ClassMetadata<T>
* @template-implements PersistenceClassMetadata<T>
* @psalm-type FieldMapping = array{
* type: string,
* fieldName: string,
Expand All @@ -96,7 +96,7 @@
* options?: array<string, mixed>
* }
*/
class ClassMetadataInfo implements ClassMetadata
class ClassMetadata implements PersistenceClassMetadata
{
/* The inheritance mapping types */
/**
Expand Down Expand Up @@ -1311,7 +1311,7 @@ public function getFieldMapping($fieldName)
/**
* Gets the mapping of an association.
*
* @see ClassMetadataInfo::$associationMappings
* @see ClassMetadata::$associationMappings
*
* @param string $fieldName The field name that represents the association in
* the object model.
Expand Down Expand Up @@ -1356,7 +1356,7 @@ public function getFieldName($columnName)
/**
* Gets the result set mapping.
*
* @see ClassMetadataInfo::$sqlResultSetMappings
* @see ClassMetadata::$sqlResultSetMappings
*
* @param string $name The result set mapping name.
*
Expand Down Expand Up @@ -1803,7 +1803,7 @@ protected function _validateAndCompleteOneToOneMapping(array $mapping)

if ($uniqueConstraintColumns) {
if (! $this->table) {
throw new RuntimeException('ClassMetadataInfo::setTable() has to be called before defining a one to one relationship.');
throw new RuntimeException('ClassMetadata::setTable() has to be called before defining a one to one relationship.');
}

$this->table['uniqueConstraints'][$mapping['fieldName'] . '_uniq'] = ['columns' => $uniqueConstraintColumns];
Expand Down Expand Up @@ -3312,7 +3312,7 @@ public function mapEmbedded(array $mapping)
*
* @return void
*/
public function inlineEmbeddable($property, ClassMetadataInfo $embeddable)
public function inlineEmbeddable($property, ClassMetadata $embeddable)
{
foreach ($embeddable->fieldMappings as $fieldMapping) {
$fieldMapping['originalClass'] ??= $embeddable->name;
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected function validateRuntimeMetadata(ClassMetadata $class, ?ClassMetadataI
}
}
} else {
assert($parent instanceof ClassMetadataInfo); // https://github.com/doctrine/orm/issues/8746
assert($parent instanceof ClassMetadata); // https://github.com/doctrine/orm/issues/8746
if (
! $class->reflClass->isAbstract()
&& ! in_array($class->name, $class->discriminatorMap, true)
Expand Down Expand Up @@ -477,7 +477,7 @@ private function addInheritedSqlResultSetMappings(ClassMetadata $subClass, Class
*
* @throws ORMException
*/
private function completeIdGeneratorMapping(ClassMetadataInfo $class): void
private function completeIdGeneratorMapping(ClassMetadata $class): void
{
$idGenType = $class->generatorType;
if ($idGenType === ClassMetadata::GENERATOR_TYPE_AUTO) {
Expand Down Expand Up @@ -612,7 +612,7 @@ private function truncateSequenceName(string $schemaElementName): string
/**
* Inherits the ID generator mapping from a parent class.
*/
private function inheritIdGeneratorMapping(ClassMetadataInfo $class, ClassMetadataInfo $parent): void
private function inheritIdGeneratorMapping(ClassMetadata $class, ClassMetadata $parent): void
{
if ($parent->isIdGeneratorSequence()) {
$class->setSequenceGeneratorDefinition($parent->sequenceGeneratorDefinition);
Expand Down
7 changes: 3 additions & 4 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
Expand Down Expand Up @@ -319,7 +318,7 @@ private function reverseEngineerMappingFromDatabase(): void
/**
* Build indexes from a class metadata.
*/
private function buildIndexes(ClassMetadataInfo $metadata): void
private function buildIndexes(ClassMetadata $metadata): void
{
$tableName = $metadata->table['name'];
$indexes = $this->tables[$tableName]->getIndexes();
Expand All @@ -342,7 +341,7 @@ private function buildIndexes(ClassMetadataInfo $metadata): void
/**
* Build field mapping from class metadata.
*/
private function buildFieldMappings(ClassMetadataInfo $metadata): void
private function buildFieldMappings(ClassMetadata $metadata): void
{
$tableName = $metadata->table['name'];
$columns = $this->tables[$tableName]->getColumns();
Expand Down Expand Up @@ -457,7 +456,7 @@ private function buildFieldMapping(string $tableName, Column $column): array
*
* @return void
*/
private function buildToOneAssociationMappings(ClassMetadataInfo $metadata)
private function buildToOneAssociationMappings(ClassMetadata $metadata)
{
$tableName = $metadata->table['name'];
$primaryKeys = $this->getTablePrimaryKeys($this->tables[$tableName]);
Expand Down
5 changes: 1 addition & 4 deletions lib/Doctrine/ORM/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ public function getOwner()
return $this->owner;
}

/**
* @return Mapping\ClassMetadata
*/
public function getTypeClass(): Mapping\ClassMetadataInfo
public function getTypeClass(): Mapping\ClassMetadata
{
return $this->typeClass;
}
Expand Down
16 changes: 1 addition & 15 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Doctrine\ORM\Tools;

use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo;

use function array_diff;
use function array_key_exists;
Expand All @@ -17,7 +15,6 @@
use function class_exists;
use function class_parents;
use function count;
use function get_class;
use function implode;
use function in_array;

Expand Down Expand Up @@ -70,19 +67,8 @@ public function validateMapping()
* @return string[]
* @psalm-return list<string>
*/
public function validateClass(ClassMetadataInfo $class)
public function validateClass(ClassMetadata $class)
{
if (! $class instanceof ClassMetadata) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/249',
'Passing an instance of %s to %s is deprecated, please pass a ClassMetadata instance instead.',
get_class($class),
__METHOD__,
ClassMetadata::class
);
}

$ce = [];
$cmf = $this->em->getMetadataFactory();

Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
<exclude-pattern>lib/Doctrine/ORM/AbstractQuery.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/Mapping/ClassMetadata.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/NativeQuery.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/Query.php</exclude-pattern>
<exclude-pattern>lib/Doctrine/ORM/Query/TreeWalkerAdapter.php</exclude-pattern>
Expand Down
9 changes: 2 additions & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,15 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Parameter \\#2 \\$class of method Doctrine\\\\ORM\\\\Mapping\\\\QuoteStrategy\\:\\:getSequenceName\\(\\) expects Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata, Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadataInfo given\\.$#"
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

-
message: "#^Method Doctrine\\\\ORM\\\\Mapping\\\\NamingStrategy\\:\\:joinColumnName\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 2
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
path: lib/Doctrine/ORM/Mapping/ClassMetadata.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
path: lib/Doctrine/ORM/Mapping/ClassMetadata.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:mapEmbedded\\(\\)\\.$#"
Expand Down
2 changes: 1 addition & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@
<code>$parent-&gt;idGenerator</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php">
<file src="lib/Doctrine/ORM/Mapping/ClassMetadata.php">
<DeprecatedProperty occurrences="4">
<code>$this-&gt;columnNames</code>
<code>$this-&gt;columnNames</code>
Expand Down
4 changes: 2 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<!-- Persistence 2 compatibility -->
<file name="lib/Doctrine/ORM/EntityManager.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php"/>
<file name="lib/Doctrine/ORM/Mapping/ClassMetadata.php"/>
</errorLevel>
</MissingParamType>
<RedundantCastGivenDocblockType>
Expand Down Expand Up @@ -105,7 +105,7 @@
<!-- DBAL 3.2 forward compatibility -->
<referencedClass name="Doctrine\DBAL\Platforms\PostgreSQLPlatform"/>
<referencedClass name="Doctrine\DBAL\Platforms\SQLServerPlatform"/>

<!-- Persistence 2 compatibility -->
<referencedClass name="Doctrine\Persistence\ObjectManagerAware"/>
</errorLevel>
Expand Down

0 comments on commit 3f749bd

Please sign in to comment.