From 518d7f2ef1a1ffcd7e33c1db7663686db2d78bb4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 19 Jul 2022 08:13:42 +0200 Subject: [PATCH 1/6] Make EntityManager `@final` and its constructor public --- lib/Doctrine/ORM/EntityManager.php | 18 ++++++++++-------- .../Performance/EntityManagerFactory.php | 2 +- .../Doctrine/Tests/Mocks/EntityManagerMock.php | 2 +- .../Tests/ORM/Functional/SQLFilterTest.php | 7 ++++++- .../Tests/ORM/Functional/Ticket/GH7869Test.php | 3 +++ .../Tests/ORM/PersistentCollectionTest.php | 3 +++ .../Tests/ORM/Proxy/ProxyFactoryTest.php | 3 +++ .../ORM/Tools/ConvertDoctrine1SchemaTest.php | 6 +++--- .../Export/ClassMetadataExporterTestCase.php | 5 +++-- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 6 ++---- 10 files changed, 35 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index f0eb4caf20b..3cc13bfb50d 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -70,8 +70,10 @@ * is not a valid extension point for the EntityManager. Instead you * should take a look at the {@see \Doctrine\ORM\Decorator\EntityManagerDecorator} * and wrap your entity manager in a decorator. + * + * @final */ -/* final */class EntityManager implements EntityManagerInterface +class EntityManager implements EntityManagerInterface { /** * The used Configuration. @@ -154,11 +156,15 @@ * Creates a new EntityManager that operates on the given database connection * and uses the given Configuration and EventManager implementations. */ - protected function __construct(Connection $conn, Configuration $config, EventManager $eventManager) + public function __construct(Connection $conn, Configuration $config) { + if (! $config->getMetadataDriverImpl()) { + throw MissingMappingDriverImplementation::create(); + } + $this->conn = $conn; $this->config = $config; - $this->eventManager = $eventManager; + $this->eventManager = $conn->getEventManager(); $metadataFactoryClassName = $config->getClassMetadataFactoryName(); @@ -958,13 +964,9 @@ public function initializeObject($obj) */ public static function create($connection, Configuration $config, ?EventManager $eventManager = null) { - if (! $config->getMetadataDriverImpl()) { - throw MissingMappingDriverImplementation::create(); - } - $connection = static::createConnection($connection, $config, $eventManager); - return new EntityManager($connection, $config, $connection->getEventManager()); + return new EntityManager($connection, $config); } /** diff --git a/tests/Doctrine/Performance/EntityManagerFactory.php b/tests/Doctrine/Performance/EntityManagerFactory.php index e3bc443ca7c..be81291cacf 100644 --- a/tests/Doctrine/Performance/EntityManagerFactory.php +++ b/tests/Doctrine/Performance/EntityManagerFactory.php @@ -71,6 +71,6 @@ public function executeQuery(string $sql, array $params = [], $types = [], ?Quer } }; - return EntityManager::create($connection, $config); + return EntityManager::create($connection, $config, $connection->getEventManager()); } } diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index e5609451ee6..4168447eb93 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -65,7 +65,7 @@ public static function create($conn, ?Configuration $config = null, ?EventManage } if ($eventManager === null) { - $eventManager = new EventManager(); + $eventManager = $conn->getEventManager(); } return new EntityManagerMock($conn, $config, $eventManager); diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 5c767cca6e1..c4eac67d555 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Configuration; @@ -233,7 +234,11 @@ private function configureFilters(EntityManagerInterface $em): void */ private function getMockConnection(): Connection { - return $this->createMock(Connection::class); + $connection = $this->createMock(Connection::class); + $connection->method('getEventManager') + ->willReturn(new EventManager()); + + return $connection; } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php index 8a60355d7ff..faf3332b504 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\ORM\Decorator\EntityManagerDecorator; @@ -31,6 +32,8 @@ public function testDQLDeferredEagerLoad(): void $connection = $this->createMock(Connection::class); $connection->method('getDatabasePlatform') ->willReturn($platform); + $connection->method('getEventManager') + ->willReturn(new EventManager()); $em = new class (EntityManagerMock::create($connection)) extends EntityManagerDecorator { /** @var int */ diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index 01cbc2116b9..4b0663c8d8b 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Result; @@ -48,6 +49,8 @@ protected function setUp(): void $connection = $this->createMock(Connection::class); $connection->method('getDatabasePlatform') ->willReturn($platform); + $connection->method('getEventManager') + ->willReturn(new EventManager()); $connection->method('executeQuery') ->willReturn($this->createMock(Result::class)); diff --git a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php index d5ae6c841ca..0cd5ab42572 100644 --- a/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Proxy; use Closure; +use Doctrine\Common\EventManager; use Doctrine\Common\Proxy\AbstractProxyFactory; use Doctrine\Common\Proxy\Proxy; use Doctrine\DBAL\Connection; @@ -52,6 +53,8 @@ protected function setUp(): void $connection = $this->createMock(Connection::class); $connection->method('getDatabasePlatform') ->willReturn($platform); + $connection->method('getEventManager') + ->willReturn(new EventManager()); $this->emMock = EntityManagerMock::create($connection); $this->uowMock = new UnitOfWorkMock($this->emMock); diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index 414d3d6cf30..0b92773e2cb 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -38,15 +38,15 @@ protected function createEntityManager(MappingDriver $metadataDriver): EntityMan $connection = $this->createMock(Connection::class); $connection->method('getDatabasePlatform') ->willReturn($platform); + $connection->method('getEventManager') + ->willReturn(new EventManager()); $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $eventManager = new EventManager(); - $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($connection, $config, $eventManager); + return EntityManagerMock::create($connection, $config); } public function testTest(): void diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php b/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php index 2e3e60805c0..aee26d6e333 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/ClassMetadataExporterTestCase.php @@ -58,14 +58,15 @@ protected function createEntityManager($metadataDriver): EntityManagerMock $connection = $this->createMock(Connection::class); $connection->method('getDatabasePlatform') ->willReturn($platform); + $connection->method('getEventManager') + ->willReturn(new EventManager()); $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../Proxies'); $config->setProxyNamespace('Doctrine\Tests\Proxies'); - $eventManager = new EventManager(); $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($connection, $config, $eventManager); + return EntityManagerMock::create($connection, $config); } protected function createMetadataDriver(string $type, string $path): MappingDriver diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 22ec37ae87b..3d5985e3853 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -114,11 +114,9 @@ protected function setUp(): void $driver->method('connect') ->willReturn($driverConnection); - $connection = new Connection([], $driver); - - $this->_connectionMock = $connection; $this->eventManager = $this->getMockBuilder(EventManager::class)->getMock(); - $this->_emMock = EntityManagerMock::create($connection, null, $this->eventManager); + $this->_connectionMock = new Connection([], $driver, null, $this->eventManager); + $this->_emMock = EntityManagerMock::create($this->_connectionMock); // SUT $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); From 9b37541b3b4811ac66e3452750c81bcc647f5c6b Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 27 Jul 2022 23:23:43 +0200 Subject: [PATCH 2/6] Use a more precise phpdoc for ClassMetadataInfo::versionField than mixed (#9937) --- lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php | 2 ++ lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 4 ++-- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 3 ++- lib/Doctrine/ORM/UnitOfWork.php | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 384664fa5e6..5e8baf18b29 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -12,6 +12,7 @@ use Doctrine\ORM\Utility\IdentifierFlattener; use function array_merge; +use function assert; use function is_array; use function is_object; use function reset; @@ -57,6 +58,7 @@ public function buildCacheEntry(ClassMetadata $metadata, EntityCacheKey $key, $e if ($metadata->requiresFetchAfterChange) { if ($metadata->isVersioned) { + assert($metadata->versionField !== null); $data[$metadata->versionField] = $metadata->getFieldValue($entity, $metadata->versionField); } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 59108eb74e4..4998b1020a6 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -713,7 +713,7 @@ class ClassMetadataInfo implements ClassMetadata /** * READ-ONLY: The name of the field which is used for versioning in optimistic locking (if any). * - * @var mixed + * @var string|null */ public $versionField; @@ -3518,7 +3518,7 @@ public function setVersioned($bool) * Sets the name of the field that is to be used for versioning if this class is * versioned for optimistic locking. * - * @param string $versionField + * @param string|null $versionField * * @return void */ diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 7b74ea8bf9c..bb974993133 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -494,7 +494,8 @@ final protected function updateTable( } if ($versioned) { - $versionField = $this->class->versionField; + $versionField = $this->class->versionField; + assert($versionField !== null); $versionFieldType = $this->class->fieldMappings[$versionField]['type']; $versionColumn = $this->quoteStrategy->getColumnName($versionField, $this->class, $this->platform); diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 9e1533e625c..707706a217a 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -54,6 +54,7 @@ use function array_pop; use function array_sum; use function array_values; +use function assert; use function count; use function current; use function get_class; @@ -1612,6 +1613,8 @@ public function getEntityState($entity, $assume = null) case $class->isIdentifierNatural(): // Check for a version field, if available, to avoid a db lookup. if ($class->isVersioned) { + assert($class->versionField !== null); + return $class->getFieldValue($entity, $class->versionField) ? self::STATE_DETACHED : self::STATE_NEW; @@ -2061,6 +2064,7 @@ private function ensureVersionMatch( return; } + assert($class->versionField !== null); $reflField = $class->reflFields[$class->versionField]; $managedCopyVersion = $reflField->getValue($managedCopy); $entityVersion = $reflField->getValue($entity); @@ -2495,6 +2499,7 @@ public function lock($entity, int $lockMode, $lockVersion = null): void $entity->__load(); } + assert($class->versionField !== null); $entityVersion = $class->reflFields[$class->versionField]->getValue($entity); // phpcs:ignore SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedNotEqualOperator From 38a9a1c795e6691b5179b3506b99c352d330acb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 28 Jul 2022 18:47:04 +0200 Subject: [PATCH 3/6] Stop passing event manager to constructor (#9938) Co-authored-by: Alexander M. Turek --- tests/Doctrine/Tests/Mocks/EntityManagerMock.php | 6 +----- .../Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php | 2 +- tests/Doctrine/Tests/ORM/UnitOfWorkTest.php | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php index 4168447eb93..ec59144f2ac 100644 --- a/tests/Doctrine/Tests/Mocks/EntityManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/EntityManagerMock.php @@ -64,10 +64,6 @@ public static function create($conn, ?Configuration $config = null, ?EventManage $config->setMetadataDriverImpl(ORMSetup::createDefaultAnnotationDriver()); } - if ($eventManager === null) { - $eventManager = $conn->getEventManager(); - } - - return new EntityManagerMock($conn, $config, $eventManager); + return new EntityManagerMock($conn, $config); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index dd34430fe33..63694d43e8d 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -324,7 +324,7 @@ protected function createEntityManager(MappingDriver $metadataDriver, $conn = nu $config->setMetadataDriverImpl($metadataDriver); - return EntityManagerMock::create($conn, $config, $eventManager); + return EntityManagerMock::create($conn, $config); } protected function createTestFactory(): ClassMetadataFactoryTestSubject diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 3d5985e3853..df5c4f72875 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -851,7 +851,7 @@ public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturn $this->_connectionMock = $this->getMockBuilderWithOnlyMethods(ConnectionMock::class, ['commit']) ->setConstructorArgs([[], $driver]) ->getMock(); - $this->_emMock = EntityManagerMock::create($this->_connectionMock, null, $this->eventManager); + $this->_emMock = EntityManagerMock::create($this->_connectionMock); $this->_unitOfWork = new UnitOfWorkMock($this->_emMock); $this->_emMock->setUnitOfWork($this->_unitOfWork); From 8bfe20073b651213d134a35245d3a3a057141b81 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 28 Jul 2022 19:35:26 +0200 Subject: [PATCH 4/6] Psalm 4.25.0, PHPStan 1.8.2 (#9941) --- composer.json | 4 ++-- psalm-baseline.xml | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index de0f5e41eae..9ddd2078c19 100644 --- a/composer.json +++ b/composer.json @@ -42,13 +42,13 @@ "doctrine/annotations": "^1.13", "doctrine/coding-standard": "^9.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.8.0", + "phpstan/phpstan": "~1.4.10 || 1.8.2", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", "psr/log": "^1 || ^2 || ^3", "squizlabs/php_codesniffer": "3.7.1", "symfony/cache": "^4.4 || ^5.4 || ^6.0", "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.24.0" + "vimeo/psalm": "4.25.0" }, "conflict": { "doctrine/annotations": "<1.13 || >= 2.0" diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c7f28ff0d87..58637bf0b16 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + IterableResult @@ -264,13 +264,10 @@ - + $className $connection $entityName - ltrim($className, '\\') - ltrim($entityName, '\\') - ltrim($entityName, '\\') getMetadataCacheImpl @@ -651,8 +648,7 @@ $table $tableGeneratorDefinition - - $this->discriminatorMap + $this->entityListeners $this->fieldMappings $this->fullyQualifiedClassName($repositoryClassName) @@ -986,6 +982,10 @@ + + $className + $entityName + $className $className From c8025dc4f8c86a5812f17f57c5f6666871906ed3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 31 Jul 2022 14:53:31 +0200 Subject: [PATCH 5/6] Update branch info in README and .doctrine-project.json (#9943) --- .doctrine-project.json | 18 ++++++++++++------ README.md | 14 +++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.doctrine-project.json b/.doctrine-project.json index a79077189c3..70f63b8bd01 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -12,21 +12,27 @@ "upcoming": true }, { - "name": "2.12", - "branchName": "2.12.x", - "slug": "2.12", + "name": "2.13", + "branchName": "2.13.x", + "slug": "2.13", "upcoming": true }, { - "name": "2.11", - "branchName": "2.11.x", - "slug": "2.11", + "name": "2.12", + "branchName": "2.12.x", + "slug": "2.12", "current": true, "aliases": [ "current", "stable" ] }, + { + "name": "2.11", + "branchName": "2.11.x", + "slug": "2.11", + "maintained": false + }, { "name": "2.10", "branchName": "2.10.x", diff --git a/README.md b/README.md index 7a817e24d47..92b14b99ac0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -| [3.0.x][3.0] | [2.12.x][2.12] | [2.11.x][2.11] | +| [3.0.x][3.0] | [2.13.x][2.13] | [2.12.x][2.12] | |:----------------:|:----------------:|:----------:| -| [![Build status][3.0 image]][3.0] | [![Build status][2.12 image]][2.12] | [![Build status][2.11 image]][2.11] | -| [![Coverage Status][3.0 coverage image]][3.0 coverage]| [![Coverage Status][2.12 coverage image]][2.12 coverage] | [![Coverage Status][2.11 coverage image]][2.11 coverage] | +| [![Build status][3.0 image]][3.0] | [![Build status][2.13 image]][2.13] | [![Build status][2.12 image]][2.12] | +| [![Coverage Status][3.0 coverage image]][3.0 coverage]| [![Coverage Status][2.13 coverage image]][2.13 coverage] | [![Coverage Status][2.12 coverage image]][2.12 coverage] | [

πŸ‡ΊπŸ‡¦ UKRAINE NEEDS YOUR HELP NOW!

](https://www.doctrine-project.org/stop-war.html) @@ -22,11 +22,11 @@ without requiring unnecessary code duplication. [3.0]: https://github.com/doctrine/orm/tree/3.0.x [3.0 coverage image]: https://codecov.io/gh/doctrine/orm/branch/3.0.x/graph/badge.svg [3.0 coverage]: https://codecov.io/gh/doctrine/orm/branch/3.0.x + [2.13 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.13.x + [2.13]: https://github.com/doctrine/orm/tree/2.13.x + [2.13 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.13.x/graph/badge.svg + [2.13 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.13.x [2.12 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.12.x [2.12]: https://github.com/doctrine/orm/tree/2.12.x [2.12 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.12.x/graph/badge.svg [2.12 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.12.x - [2.11 image]: https://github.com/doctrine/orm/actions/workflows/continuous-integration.yml/badge.svg?branch=2.11.x - [2.11]: https://github.com/doctrine/orm/tree/2.11.x - [2.11 coverage image]: https://codecov.io/gh/doctrine/orm/branch/2.11.x/graph/badge.svg - [2.11 coverage]: https://codecov.io/gh/doctrine/orm/branch/2.11.x From 2ec2c585b085456a2e3173a3adff42f88b76a9da Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 1 Aug 2022 11:42:24 +0200 Subject: [PATCH 6/6] Deprecate QueryBuilder APIs exposing its internal state (#9945) Co-authored-by: Sergei Morozov --- UPGRADE.md | 14 ++++++++++++++ lib/Doctrine/ORM/QueryBuilder.php | 27 +++++++++++++++++++++++++-- psalm.xml | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index b85b1c74b3f..a367589573f 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,19 @@ # Upgrade to 2.13 +## Deprecated `QueryBuilder` methods and constants. + +1. The `QueryBuilder::getState()` method has been deprecated as the builder state is an internal concern. +2. Relying on the type of the query being built by using `QueryBuilder::getType()` has been deprecated. + If necessary, track the type of the query being built outside of the builder. + +The following `QueryBuilder` constants related to the above methods have been deprecated: + +1. `SELECT`, +2. `DELETE`, +3. `UPDATE`, +4. `STATE_DIRTY`, +5. `STATE_CLEAN`. + ## Deprecated omitting only the alias argument for `QueryBuilder::update` and `QueryBuilder::delete` When building an UPDATE or DELETE query and when passing a class/type to the function, the alias argument must not be omitted. diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index a0504758a2b..4003615081a 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -39,13 +39,19 @@ */ class QueryBuilder { - /* The query types. */ + /** @deprecated */ public const SELECT = 0; + + /** @deprecated */ public const DELETE = 1; + + /** @deprecated */ public const UPDATE = 2; - /* The builder states. */ + /** @deprecated */ public const STATE_DIRTY = 0; + + /** @deprecated */ public const STATE_CLEAN = 1; /** @@ -275,11 +281,20 @@ public function setCacheMode($cacheMode) /** * Gets the type of the currently built query. * + * @deprecated If necessary, track the type of the query being built outside of the builder. + * * @return int * @psalm-return self::SELECT|self::DELETE|self::UPDATE */ public function getType() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/orm/pull/9945', + 'Relying on the type of the query being built is deprecated.' + . ' If necessary, track the type of the query being built outside of the builder.' + ); + return $this->_type; } @@ -296,11 +311,19 @@ public function getEntityManager() /** * Gets the state of this query builder instance. * + * @deprecated The builder state is an internal concern. + * * @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. * @psalm-return self::STATE_* */ public function getState() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/orm/pull/9945', + 'Relying on the query builder state is deprecated as it is an internal concern.' + ); + return $this->_state; } diff --git a/psalm.xml b/psalm.xml index 4b148a8162e..dd985cf7a64 100644 --- a/psalm.xml +++ b/psalm.xml @@ -43,6 +43,7 @@ +