Skip to content

Commit

Permalink
Drop support for Persistence 3 (#11729)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire authored Nov 24, 2024
1 parent ee9dd47 commit 350597b
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 212 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"doctrine/inflector": "^1.4 || ^2.0",
"doctrine/instantiator": "^1.3 || ^2",
"doctrine/lexer": "^3",
"doctrine/persistence": "^3.3.1 || ^4",
"doctrine/persistence": "^4",
"psr/cache": "^1 || ^2 || ^3",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/var-exporter": "^6.3.9 || ^7.0"
Expand Down
2 changes: 0 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>src/Mapping/Driver/LoadMappingFileImplementation.php</exclude-pattern>
<exclude-pattern>src/Mapping/GetReflectionClassImplementation.php</exclude-pattern>
<exclude-pattern>tests/*</exclude-pattern>
</rule>

Expand Down
20 changes: 1 addition & 19 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@
<code><![CDATA[$parentReflFields[$embeddedClass->declaredField]]]></code>
</PossiblyNullArgument>
<PossiblyNullReference>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getProperty]]></code>
<code><![CDATA[getValue]]></code>
<code><![CDATA[getValue]]></code>
<code><![CDATA[getValue]]></code>
Expand All @@ -323,6 +320,7 @@
</PossiblyUndefinedArrayOffset>
<PropertyNotSetInConstructor>
<code><![CDATA[$idGenerator]]></code>
<code><![CDATA[$reflClass]]></code>
<code><![CDATA[$table]]></code>
</PropertyNotSetInConstructor>
<RedundantCondition>
Expand Down Expand Up @@ -442,14 +440,6 @@
<code><![CDATA[new ReflectionClass($metadata->name)]]></code>
</TypeDoesNotContainNull>
</file>
<file src="src/Mapping/Driver/LoadMappingFileImplementation.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[array]]></code>
</LessSpecificImplementedReturnType>
<MissingParamType>
<code><![CDATA[$file]]></code>
</MissingParamType>
</file>
<file src="src/Mapping/Driver/SimplifiedXmlDriver.php">
<MissingParamType>
<code><![CDATA[$fileExtension]]></code>
Expand Down Expand Up @@ -502,14 +492,6 @@
<code><![CDATA[$metadata]]></code>
</MoreSpecificImplementedParamType>
</file>
<file src="src/Mapping/GetReflectionClassImplementation.php">
<ImplementedReturnTypeMismatch>
<code><![CDATA[ReflectionClass]]></code>
</ImplementedReturnTypeMismatch>
<InvalidNullableReturnType>
<code><![CDATA[ReflectionClass]]></code>
</InvalidNullableReturnType>
</file>
<file src="src/Mapping/ManyToManyInverseSideMapping.php">
<PropertyNotSetInConstructor>
<code><![CDATA[ManyToManyInverseSideMapping]]></code>
Expand Down
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
<referencedClass name="Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand"/>
<referencedClass name="Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper"/>
<referencedClass name="Doctrine\ORM\Tools\Console\EntityManagerProvider\HelperSetManagerProvider"/>
<referencedClass name="Doctrine\Persistence\Mapping\StaticReflectionService"/>
</errorLevel>
</DeprecatedClass>
<DocblockTypeContradiction>
Expand Down
16 changes: 8 additions & 8 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
*/
class ClassMetadata implements PersistenceClassMetadata, Stringable
{
use GetReflectionClassImplementation;

/* The inheritance mapping types */
/**
* NONE means the class does not participate in an inheritance hierarchy
Expand Down Expand Up @@ -519,9 +517,9 @@ class ClassMetadata implements PersistenceClassMetadata, Stringable
/**
* The ReflectionClass instance of the mapped class.
*
* @var ReflectionClass<T>|null
* @var ReflectionClass<T>
*/
public ReflectionClass|null $reflClass = null;
public ReflectionClass $reflClass;

/**
* Is this entity marked as "read-only"?
Expand Down Expand Up @@ -934,6 +932,11 @@ public function validateLifecycleCallbacks(ReflectionService $reflService): void
}
}

public function getReflectionClass(): ReflectionClass
{
return $this->reflClass;
}

/** @psalm-param array{usage?: mixed, region?: mixed} $cache */
public function enableCache(array $cache): void
{
Expand Down Expand Up @@ -1098,8 +1101,7 @@ public function getFieldName(string $columnName): string
*/
private function isTypedProperty(string $name): bool
{
return isset($this->reflClass)
&& $this->reflClass->hasProperty($name)
return $this->reflClass->hasProperty($name)
&& $this->reflClass->getProperty($name)->hasType();
}

Expand Down Expand Up @@ -2579,8 +2581,6 @@ public function inlineEmbeddable(string $property, ClassMetadata $embeddable): v
if (! empty($this->embeddedClasses[$property]->columnPrefix)) {
$fieldMapping['columnName'] = $this->embeddedClasses[$property]->columnPrefix . $fieldMapping['columnName'];
} elseif ($this->embeddedClasses[$property]->columnPrefix !== false) {
assert($this->reflClass !== null);
assert($embeddable->reflClass !== null);
$fieldMapping['columnName'] = $this->namingStrategy
->embeddedFieldToColumnName(
$property,
Expand Down
5 changes: 0 additions & 5 deletions src/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ protected function doLoadMetadata(
*/
protected function validateRuntimeMetadata(ClassMetadata $class, ClassMetadataInterface|null $parent): void
{
if (! $class->reflClass) {
// only validate if there is a reflection class instance
return;
}

$class->validateIdentifier();
$class->validateAssociations();
$class->validateLifecycleCallbacks($this->getReflectionService());
Expand Down
35 changes: 0 additions & 35 deletions src/Mapping/Driver/LoadMappingFileImplementation.php

This file was deleted.

10 changes: 6 additions & 4 deletions src/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
*/
class XmlDriver extends FileDriver
{
use LoadMappingFileImplementation;

public const DEFAULT_FILE_EXTENSION = '.dcm.xml';

/**
Expand Down Expand Up @@ -880,8 +878,12 @@ private function getCascadeMappings(SimpleXMLElement $cascadeElement): array
return $cascades;
}

/** @return array<class-string, SimpleXMLElement> */
private function doLoadMappingFile(string $file): array
/**
* {@inheritDoc}
*
* @return array<class-string, SimpleXMLElement>
*/
protected function loadMappingFile(string $file): array
{
$this->validateMapping($file);
$result = [];
Expand Down
33 changes: 0 additions & 33 deletions src/Mapping/GetReflectionClassImplementation.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public function validateClass(ClassMetadata $class): array
if (
! $class->isInheritanceTypeNone()
&& ! $class->isRootEntity()
&& ($class->reflClass !== null && ! $class->reflClass->isAbstract())
&& ! $class->reflClass->isAbstract()
&& ! $class->isMappedSuperclass
&& array_search($class->name, $class->discriminatorMap, true) === false
) {
Expand Down
24 changes: 9 additions & 15 deletions tests/Tests/ORM/Functional/Ticket/DDC2359Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;

Expand All @@ -28,12 +28,13 @@ class DDC2359Test extends TestCase
public function testIssue(): void
{
$mockDriver = $this->createMock(MappingDriver::class);
$mockMetadata = $this->createMock(ClassMetadata::class);
$entityManager = $this->createMock(EntityManager::class);

$metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class)
->onlyMethods(['newClassMetadataInstance', 'wakeupReflection'])
$metadataFactory = $this->getMockBuilder(ClassMetadataFactory::class)
->onlyMethods(['wakeupReflection', 'validateRuntimeMetadata'])
->getMock();
$reflectionService = new RuntimeReflectionService();
$metadataFactory->expects(self::once())->method('wakeupReflection');

$configuration = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getMetadataDriverImpl'])
Expand All @@ -45,29 +46,22 @@ public function testIssue(): void
->method('getMetadataDriverImpl')
->willReturn($mockDriver);

$entityManager->expects(self::any())->method('getConfiguration')->willReturn($configuration);
$entityManager->expects(self::any())->method('getConnection')->willReturn($connection);
$entityManager->method('getConfiguration')->willReturn($configuration);
$entityManager->method('getConnection')->willReturn($connection);
$entityManager
->method('getEventManager')
->willReturn($this->createMock(EventManager::class));

$metadataFactory->method('newClassMetadataInstance')->willReturn($mockMetadata);
$metadataFactory->expects(self::once())->method('wakeupReflection');

$metadataFactory->setEntityManager($entityManager);

$mockMetadata->method('getName')->willReturn(DDC2359Foo::class);

self::assertSame($mockMetadata, $metadataFactory->getMetadataFor(DDC2359Foo::class));
$metadataFactory->getMetadataFor(DDC2359Foo::class);
}
}

#[Entity]
class DDC2359Foo
{
/** @var int */
#[Id]
#[Column(type: 'integer')]
#[GeneratedValue]
public $id;
public int $id;
}
55 changes: 0 additions & 55 deletions tests/Tests/ORM/Functional/Ticket/DDC3103Test.php

This file was deleted.

Loading

0 comments on commit 350597b

Please sign in to comment.