From 5183224a3a46e6f8e1f1448c3ff053e00c6e7ef1 Mon Sep 17 00:00:00 2001
From: Oliver Klee <typo3-coding@oliverklee.de>
Date: Fri, 14 Apr 2023 16:44:03 +0200
Subject: [PATCH] [TASK] Simplify code in LazyObjectStorage
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Simplify `initialize` using a guard clause.

Resolves: #100598
Releases: main, 11.5
Change-Id: Ic53d190a139bc4c74517fc680adf43a8daadb6d9
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78574
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
---
 .../Persistence/Generic/LazyObjectStorage.php | 22 ++++++++++---------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php b/typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php
index 66888797f629..33989f3b22ca 100644
--- a/typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php
+++ b/typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php
@@ -103,16 +103,18 @@ class LazyObjectStorage extends ObjectStorage implements LoadingStrategyInterfac
      */
     protected function initialize()
     {
-        if (!$this->isInitialized) {
-            $this->isInitialized = true;
-            $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false);
-            foreach ($objects as $object) {
-                parent::attach($object);
-            }
-            $this->_memorizeCleanState();
-            if (!$this->isStorageAlreadyMemorizedInParentCleanState()) {
-                $this->parentObject->_memorizeCleanState($this->propertyName);
-            }
+        if ($this->isInitialized) {
+            return;
+        }
+
+        $this->isInitialized = true;
+        $objects = $this->dataMapper->fetchRelated($this->parentObject, $this->propertyName, $this->fieldValue, false);
+        foreach ($objects as $object) {
+            parent::attach($object);
+        }
+        $this->_memorizeCleanState();
+        if (!$this->isStorageAlreadyMemorizedInParentCleanState()) {
+            $this->parentObject->_memorizeCleanState($this->propertyName);
         }
     }
 
-- 
GitLab