From 16cddd4693f50b88fb1320dc0590f5fd328d66cd Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:13:06 +0300 Subject: [PATCH 1/9] claar code from `Scrutinizer` --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7044ce57e..b2c1c6f4b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1796,7 +1796,7 @@ class UnitOfWork implements PropertyChangedListener * @throws ORMInvalidArgumentException If the entity instance is NEW. * @throws EntityNotFoundException */ - private function doMerge($entity, array &$visited, $prevManagedCopy = null, $assoc = null) + private function doMerge($entity, array &$visited, $prevManagedCopy = null, array $assoc = []) { $oid = spl_object_hash($entity); From 347d1625bcbd42325df31cf92953648446786f90 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:33:23 +0300 Subject: [PATCH 2/9] merge conditions --- lib/Doctrine/ORM/UnitOfWork.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index b2c1c6f4b..dfc8d9ce0 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1155,9 +1155,9 @@ class UnitOfWork implements PropertyChangedListener } $joinColumns = reset($assoc['joinColumns']); - $isNullable = isset($joinColumns['nullable']) ? $joinColumns['nullable'] : false; + $weight = (int)empty($joinColumns['nullable']); - $calc->addDependency($targetClass->name, $class->name, $isNullable ? 0 : 1); + $calc->addDependency($targetClass->name, $class->name, $weight); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) { From db6c593463f8b545a435c730fbb059e58a07af69 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:37:12 +0300 Subject: [PATCH 3/9] clear code --- lib/Doctrine/ORM/UnitOfWork.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index dfc8d9ce0..cbf9e08be 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1344,9 +1344,7 @@ class UnitOfWork implements PropertyChangedListener $this->removeFromIdentityMap($entity); - if (isset($this->entityUpdates[$oid])) { - unset($this->entityUpdates[$oid]); - } + unset($this->entityUpdates[$oid]); if ( ! isset($this->entityDeletions[$oid])) { $this->entityDeletions[$oid] = $entity; From c6675b0ce3584f435559ce167e0716c806da47f8 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:42:46 +0300 Subject: [PATCH 4/9] use ternary --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index cbf9e08be..609c191eb 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1566,11 +1566,9 @@ class UnitOfWork implements PropertyChangedListener { $stringIdHash = (string) $idHash; - if (isset($this->identityMap[$rootClassName][$stringIdHash])) { - return $this->identityMap[$rootClassName][$stringIdHash]; - } - - return false; + return isset($this->identityMap[$rootClassName][$stringIdHash]) + ? $this->identityMap[$rootClassName][$stringIdHash] + : false; } /** From 6bf6bae219041b2686d9b9cfd5d704d53f1bb14d Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:51:44 +0300 Subject: [PATCH 5/9] clear code --- lib/Doctrine/ORM/UnitOfWork.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 609c191eb..2089d3565 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2441,9 +2441,7 @@ class UnitOfWork implements PropertyChangedListener // TODO: if $coll is already scheduled for recreation ... what to do? // Just remove $coll from the scheduled recreations? - if (isset($this->collectionUpdates[$coid])) { - unset($this->collectionUpdates[$coid]); - } + unset($this->collectionUpdates[$coid]); $this->collectionDeletions[$coid] = $coll; } From a7c4ca82fd86d1eb1e786097085ecacd1baed5e3 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 22:59:16 +0300 Subject: [PATCH 6/9] use ternary --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 2089d3565..408d2c961 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2848,11 +2848,9 @@ class UnitOfWork implements PropertyChangedListener { $oid = spl_object_hash($entity); - if (isset($this->originalEntityData[$oid])) { - return $this->originalEntityData[$oid]; - } - - return array(); + return isset($this->originalEntityData[$oid]) + ? $this->originalEntityData[$oid] + : []; } /** From 52b2d9022a9d16b3d33d6760b8d058f07beaa234 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 23:00:40 +0300 Subject: [PATCH 7/9] use ternary --- lib/Doctrine/ORM/UnitOfWork.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 408d2c961..902ccd6d7 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2936,11 +2936,9 @@ class UnitOfWork implements PropertyChangedListener { $idHash = implode(' ', (array) $id); - if (isset($this->identityMap[$rootClassName][$idHash])) { - return $this->identityMap[$rootClassName][$idHash]; - } - - return false; + return isset($this->identityMap[$rootClassName][$idHash]) + ? $this->identityMap[$rootClassName][$idHash] + : false; } /** From c0fc4f115804f95a36d9c78714600d94e24bb6d9 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Sat, 2 Jul 2016 23:02:13 +0300 Subject: [PATCH 8/9] use internal function --- lib/Doctrine/ORM/UnitOfWork.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 902ccd6d7..4c494831f 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2975,7 +2975,7 @@ class UnitOfWork implements PropertyChangedListener */ public function size() { - $countArray = array_map(function ($item) { return count($item); }, $this->identityMap); + $countArray = array_map('count', $this->identityMap); return array_sum($countArray); } From bcc79839345ab476dd5912408bd0acacb88a30e8 Mon Sep 17 00:00:00 2001 From: ReenExe Date: Tue, 5 Jul 2016 19:15:47 +0300 Subject: [PATCH 9/9] after review --- lib/Doctrine/ORM/UnitOfWork.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 4c494831f..c54d97a0b 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -1155,9 +1155,8 @@ class UnitOfWork implements PropertyChangedListener } $joinColumns = reset($assoc['joinColumns']); - $weight = (int)empty($joinColumns['nullable']); - $calc->addDependency($targetClass->name, $class->name, $weight); + $calc->addDependency($targetClass->name, $class->name, (int)empty($joinColumns['nullable'])); // If the target class has mapped subclasses, these share the same dependency. if ( ! $targetClass->subClasses) {