Skip to content

Commit 80bca72

Browse files
committed
Merge branch '2.11.x' into 3.0.x
* 2.11.x: Added runtime deprecation to `UnitOfWork::commit()` and `clear()` (#9327) Document return type of getEntityState() (#9328) Fix broken type declaration (#9330) Enable some previously disabled PHPCS rules (#9324)
2 parents 2a0c73d + ceaefcb commit 80bca72

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ public function __construct(EntityManagerInterface $em)
325325
*/
326326
public function commit(object|array|null $entity = null): void
327327
{
328+
if ($entity !== null) {
329+
Deprecation::triggerIfCalledFromOutside(
330+
'doctrine/orm',
331+
'https://github.com/doctrine/orm/issues/8459',
332+
'Calling %s() with any arguments to commit specific entities is deprecated and will not be supported in Doctrine ORM 3.0.',
333+
__METHOD__
334+
);
335+
}
336+
328337
$connection = $this->em->getConnection();
329338

330339
if ($connection instanceof PrimaryReadReplicaConnection) {
@@ -928,8 +937,6 @@ private function computeAssociationChanges(array $assoc, mixed $value): void
928937
// so the exception will be raised from the DBAL layer (constraint violation).
929938
throw ORMInvalidArgumentException::detachedEntityFoundThroughRelationship($assoc, $entry);
930939

931-
break;
932-
933940
default:
934941
// MANAGED associated entities are already taken into account
935942
// during changeset calculation anyway, since they are in the identity map.
@@ -1503,6 +1510,9 @@ public function addToIdentityMap(object $entity): bool
15031510
* This parameter can be set to improve performance of entity state detection
15041511
* by potentially avoiding a database lookup if the distinction between NEW and DETACHED
15051512
* is either known or does not matter for the caller of the method.
1513+
* @psalm-param self::STATE_*|null $assume
1514+
*
1515+
* @psalm-return self::STATE_*
15061516
*/
15071517
public function getEntityState(object $entity, ?int $assume = null): int
15081518
{
@@ -2418,6 +2428,13 @@ public function clear(?string $entityName = null): void
24182428
$this->eagerLoadingEntities =
24192429
$this->orphanRemovals = [];
24202430
} else {
2431+
Deprecation::triggerIfCalledFromOutside(
2432+
'doctrine/orm',
2433+
'https://github.com/doctrine/orm/issues/8460',
2434+
'Calling %s() with any arguments to clear specific entities is deprecated and will not be supported in Doctrine ORM 3.0.',
2435+
__METHOD__
2436+
);
2437+
24212438
$this->clearIdentityMapForEntityName($entityName);
24222439
$this->clearEntityInsertionsForEntityName($entityName);
24232440
}

phpcs.xml.dist

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@
128128
<exclude-pattern>lib/Doctrine/ORM/Cache/DefaultQueryCache.php</exclude-pattern>
129129
</rule>
130130

131-
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment.UselessInheritDocComment">
132-
<!-- Workaround for https://github.com/slevomat/coding-standard/issues/1233 -->
133-
<exclude-pattern>lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php</exclude-pattern>
134-
</rule>
135-
136131
<rule ref="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming">
137132
<exclude-pattern>lib/Doctrine/ORM/EntityManagerInterface.php</exclude-pattern>
138133
</rule>
@@ -258,14 +253,6 @@
258253
<exclude-pattern>tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1843Test.php</exclude-pattern>
259254
</rule>
260255

261-
<rule ref="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment">
262-
<!--
263-
Remove when upgrading to squizlabs/php_codesniffer 3.6.0
264-
https://github.com/squizlabs/PHP_CodeSniffer/pull/3186
265-
-->
266-
<exclude-pattern>lib/Doctrine/ORM/Query/Parser.php</exclude-pattern>
267-
</rule>
268-
269256
<rule ref="Generic.CodeAnalysis.EmptyStatement.DetectedElse">
270257
<!-- The missing code needs to be implemented someday -->
271258
<exclude-pattern>lib/Doctrine/ORM/Id/TableGenerator.php</exclude-pattern>

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,11 +1565,6 @@ parameters:
15651565
count: 1
15661566
path: lib/Doctrine/ORM/UnitOfWork.php
15671567

1568-
-
1569-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
1570-
count: 1
1571-
path: lib/Doctrine/ORM/UnitOfWork.php
1572-
15731568
-
15741569
message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$name\\.$#"
15751570
count: 1

psalm-baseline.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,9 @@
30123012
<code>$entity</code>
30133013
<code>$entity</code>
30143014
</PossiblyNullArgument>
3015+
<RedundantConditionGivenDocblockType occurrences="1">
3016+
<code>$state === UnitOfWork::STATE_DETACHED</code>
3017+
</RedundantConditionGivenDocblockType>
30153018
</file>
30163019
<file src="lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php">
30173020
<MoreSpecificImplementedParamType occurrences="1">

tests/Doctrine/Tests/ORM/UnitOfWorkTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
99
use Doctrine\Common\EventManager;
10+
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1011
use Doctrine\ORM\EntityNotFoundException;
1112
use Doctrine\ORM\Events;
1213
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -50,6 +51,8 @@
5051
*/
5152
class UnitOfWorkTest extends OrmTestCase
5253
{
54+
use VerifyDeprecations;
55+
5356
/**
5457
* SUT
5558
*
@@ -226,6 +229,9 @@ public function testChangeTrackingNotifyIndividualCommit(): void
226229

227230
$this->_unitOfWork->persist($entity);
228231
$this->_unitOfWork->persist($entity2);
232+
233+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
234+
229235
$this->_unitOfWork->commit($entity);
230236
$this->_unitOfWork->commit();
231237

@@ -389,6 +395,8 @@ public function testPersistedEntityAndClearManager(): void
389395
$this->_unitOfWork->persist($entity2);
390396
self::assertTrue($this->_unitOfWork->isInIdentityMap($entity2));
391397

398+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8460');
399+
392400
$this->_unitOfWork->clear(Country::class);
393401
self::assertTrue($this->_unitOfWork->isInIdentityMap($entity1));
394402
self::assertFalse($this->_unitOfWork->isInIdentityMap($entity2));
@@ -410,6 +418,8 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnSingleEntity(): void
410418
$this->_unitOfWork->persist($entity1);
411419
$this->_unitOfWork->persist($entity2);
412420

421+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
422+
413423
$this->_unitOfWork->commit($entity1);
414424
self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1));
415425
self::assertCount(1, $this->_unitOfWork->getEntityChangeSet($entity2));
@@ -432,6 +442,8 @@ public function testEntityChangeSetIsNotClearedAfterFlushOnArrayOfEntities(): vo
432442
$this->_unitOfWork->persist($entity2);
433443
$this->_unitOfWork->persist($entity3);
434444

445+
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/8459');
446+
435447
$this->_unitOfWork->commit([$entity1, $entity3]);
436448

437449
self::assertEmpty($this->_unitOfWork->getEntityChangeSet($entity1));

0 commit comments

Comments
 (0)