From: Matthias Schmidt Date: Thu, 17 Jun 2021 04:57:55 +0000 (+0200) Subject: Refactor code in `EventHandler` X-Git-Tag: 5.5.0_Alpha_1~633^2~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=ea2779b1f5d931b2a9b28d181ea1541b53b053d4;p=GitHub%2FWoltLab%2FWCF.git Refactor code in `EventHandler` … to reduce code complexity and nesting levels. --- 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); } }