From 2751c0fff2a52f651354236f66b5a257dc17502e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 21 Aug 2017 20:08:20 +0200 Subject: [PATCH] #1521 DDC-2922 minor code cleanup - renaming internal private methods, variables, removing redundant if/else --- lib/Doctrine/ORM/UnitOfWork.php | 41 ++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b3f3fb23d..5efb01b3b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -187,9 +187,9 @@ class UnitOfWork implements PropertyChangedListener * Keys are OIDs, payload is a two-item array describing the association * and the entity. * - * @var array + * @var object[][]|array[][] indexed by respective object spl_object_hash() */ - private $newEntitiesWithoutCascade = array(); + private $nonCascadedNewDetectedEntities = []; /** * All pending collection deletions. @@ -347,7 +347,8 @@ class UnitOfWork implements PropertyChangedListener } } - $this->assertNoCascadingGaps(); + // @TODO move this further down + $this->assertThatThereAreNoUnintentionallyNonPersistedAssociations(); if ( ! ($this->entityInsertions || $this->entityDeletions || @@ -442,7 +443,7 @@ class UnitOfWork implements PropertyChangedListener $this->entityDeletions = $this->extraUpdates = $this->collectionUpdates = - $this->newEntitiesWithoutCascade = + $this->nonCascadedNewDetectedEntities = $this->collectionDeletions = $this->visitedCollections = $this->orphanRemovals = []; @@ -883,11 +884,14 @@ class UnitOfWork implements PropertyChangedListener * through the object-graph where cascade-persistence * is enabled for this object. */ - $this->newEntitiesWithoutCascade[spl_object_hash($entry)] = array($assoc,$entry); - }else { - $this->persistNew($targetClass, $entry); - $this->computeChangeSet($targetClass, $entry); + $this->nonCascadedNewDetectedEntities[\spl_object_hash($entry)] = [$assoc, $entry]; + + break; } + + $this->persistNew($targetClass, $entry); + $this->computeChangeSet($targetClass, $entry); + break; case self::STATE_REMOVED: @@ -2433,7 +2437,7 @@ class UnitOfWork implements PropertyChangedListener $this->entityInsertions = $this->entityUpdates = $this->entityDeletions = - $this->newEntitiesWithoutCascade = + $this->nonCascadedNewDetectedEntities = $this->collectionDeletions = $this->collectionUpdates = $this->extraUpdates = @@ -3388,21 +3392,16 @@ class UnitOfWork implements PropertyChangedListener } /** - * Checks that there are no new entities found through non-cascade-persist - * paths which are not also scheduled for insertion through valid paths. - * - * @return void * @throws ORMInvalidArgumentException */ - private function assertNoCascadingGaps() + private function assertThatThereAreNoUnintentionallyNonPersistedAssociations() : void { - /** - * Filter out any entities that we (successfully) managed to schedule - * for insertion. - */ - $entitiesNeedingCascadePersist = array_diff_key($this->newEntitiesWithoutCascade, $this->entityInsertions); - if(count($entitiesNeedingCascadePersist) > 0){ - list($assoc,$entity) = array_values($entitiesNeedingCascadePersist)[0]; + $entitiesNeedingCascadePersist = \array_diff_key($this->nonCascadedNewDetectedEntities, $this->entityInsertions); + + if($entitiesNeedingCascadePersist){ + [$assoc, $entity] = \array_values($entitiesNeedingCascadePersist)[0]; + + // @TODO internal clean up here throw ORMInvalidArgumentException::newEntityFoundThroughRelationship($assoc, $entity); } }