From ea2779b1f5d931b2a9b28d181ea1541b53b053d4 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Thu, 17 Jun 2021 06:57:55 +0200 Subject: [PATCH] Refactor code in `EventHandler` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … to reduce code complexity and nesting levels. --- .../lib/system/event/EventHandler.class.php | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/wcfsetup/install/files/lib/system/event/EventHandler.class.php b/wcfsetup/install/files/lib/system/event/EventHandler.class.php index a533771a79..685df35398 100644 --- a/wcfsetup/install/files/lib/system/event/EventHandler.class.php +++ b/wcfsetup/install/files/lib/system/event/EventHandler.class.php @@ -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); } } -- 2.20.1