From c337f8f5c70617e9cdf53229568a62264e099a38 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Mon, 30 Nov 2015 16:22:11 +0100 Subject: [PATCH] DDC-4022 deduplication of internal UnitOfWork methods the methods UnitOfWork#afterTransactionRolledBack() and UnitOfWork#afterTransactionComplete do almost the same, so it can be abstracted into another private method. --- lib/Doctrine/ORM/UnitOfWork.php | 42 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 37a123d26..1652d4a1e 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3259,21 +3259,9 @@ class UnitOfWork implements PropertyChangedListener */ private function afterTransactionComplete() { - if ( ! $this->hasCache) { - return; - } - - foreach ($this->persisters as $persister) { - if ($persister instanceof CachedPersister) { - $persister->afterTransactionComplete(); - } - } - - foreach ($this->collectionPersisters as $persister) { - if ($persister instanceof CachedPersister) { - $persister->afterTransactionComplete(); - } - } + $this->doAfterTransaction(function (CachedPersister $persister) { + $persister->afterTransactionComplete(); + }); } /** @@ -3281,19 +3269,23 @@ class UnitOfWork implements PropertyChangedListener */ private function afterTransactionRolledBack() { - if ( ! $this->hasCache) { + $this->doAfterTransaction(function (CachedPersister $persister) { + $persister->afterTransactionRolledBack(); + }); + } + + /** + * Performs an action after the transaction. + */ + private function doAfterTransaction(callable $callback) + { + if (!$this->hasCache) { return; } - - foreach ($this->persisters as $persister) { + + foreach (array_merge($this->persisters, $this->collectionPersisters) as $persister) { if ($persister instanceof CachedPersister) { - $persister->afterTransactionRolledBack(); - } - } - - foreach ($this->collectionPersisters as $persister) { - if ($persister instanceof CachedPersister) { - $persister->afterTransactionRolledBack(); + call_user_func($callback, $persister); } } }