Refactor code in `EventHandler`
authorMatthias Schmidt <gravatronics@live.com>
Thu, 17 Jun 2021 04:57:55 +0000 (06:57 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Thu, 17 Jun 2021 04:57:55 +0000 (06:57 +0200)
… to reduce code complexity and nesting levels.

wcfsetup/install/files/lib/system/event/EventHandler.class.php

index a533771a79cfdc9ac72ba01aff7d346624e52e86..685df35398a4b3c239db8554123d011c1e3dbbe3 100644 (file)
@@ -107,19 +107,18 @@ class EventHandler extends SingletonFactory
             }
 
             foreach ($familyTree as $member) {
-                if (isset($this->inheritedActions[$member])) {
-                    $actions = $this->inheritedActions[$member];
-                    if (isset($actions[$eventName]) && !empty($actions[$eventName])) {
-                        /** @var EventListener $eventListener */
-                        foreach ($actions[$eventName] as $eventListener) {
-                            if ($eventListener->validateOptions() && $eventListener->validatePermissions()) {
-                                if (isset($this->inheritedActionsObjects[$name][$eventListener->listenerClassName])) {
-                                    continue;
-                                }
+                if (empty($this->inheritedActions[$member][$eventName])) {
+                    continue;
+                }
 
-                                $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $this->getListenerObject($eventListener);
-                            }
-                        }
+                /** @var EventListener $eventListener */
+                foreach ($this->inheritedActions[$member][$eventName] as $eventListener) {
+                    if (
+                        $eventListener->validateOptions()
+                        && $eventListener->validatePermissions()
+                        && !isset($this->inheritedActionsObjects[$name][$eventListener->listenerClassName])
+                    ) {
+                        $this->inheritedActionsObjects[$name][$eventListener->listenerClassName] = $this->getListenerObject($eventListener);
                     }
                 }
             }
@@ -212,11 +211,11 @@ class EventHandler extends SingletonFactory
             $this->actionsObjects[$name] = [];
             /** @var EventListener $eventListener */
             foreach ($this->actions[$name] as $eventListener) {
-                if ($eventListener->validateOptions() && $eventListener->validatePermissions()) {
-                    if (isset($this->actionsObjects[$name][$eventListener->listenerClassName])) {
-                        continue;
-                    }
-
+                if (
+                    $eventListener->validateOptions()
+                    && $eventListener->validatePermissions()
+                    && !isset($this->actionsObjects[$name][$eventListener->listenerClassName])
+                ) {
                     $this->actionsObjects[$name][$eventListener->listenerClassName] = $this->getListenerObject($eventListener);
                 }
             }