From 964ce44577a62887537214fa22c4b6fdbf81e893 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 15 Mar 2022 15:11:57 +0100 Subject: [PATCH] EventService: code cleanup --- sources/Application/Service/EventData.php | 40 ++++++++++---------- sources/Application/Service/EventService.php | 20 +++++----- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/sources/Application/Service/EventData.php b/sources/Application/Service/EventData.php index a58fcf4d1..5e9592181 100644 --- a/sources/Application/Service/EventData.php +++ b/sources/Application/Service/EventData.php @@ -16,24 +16,24 @@ namespace Combodo\iTop\Service; class EventData { private $sEvent; - private $sEventSource; - private $mEventData; - private $mCallbackData; + private $mEventSource; + private $aEventData; + private $aCallbackData; /** * EventServiceData constructor. * * @param string $sEvent - * @param string $sEventSource + * @param mixed $mEventSource * @param array $aEventData * @param array $aCallbackData */ - public function __construct($sEvent, $sEventSource, $aEventData, $aCallbackData) + public function __construct(string $sEvent, $mEventSource, array $aEventData, array $aCallbackData) { $this->sEvent = $sEvent; - $this->mEventData = $aEventData; - $this->sEventSource = $sEventSource; - $this->mCallbackData = $aCallbackData; + $this->aEventData = $aEventData; + $this->mEventSource = $mEventSource; + $this->aCallbackData = $aCallbackData; } /** @@ -46,38 +46,38 @@ class EventData public function Get($sParam) { - if (is_array($this->mEventData) && isset($this->mEventData[$sParam])) { - return $this->mEventData[$sParam]; + if (is_array($this->aEventData) && isset($this->aEventData[$sParam])) { + return $this->aEventData[$sParam]; } - if (is_array($this->mCallbackData) && isset($this->mCallbackData[$sParam])) { - return $this->mCallbackData[$sParam]; + if (is_array($this->aCallbackData) && isset($this->aCallbackData[$sParam])) { + return $this->aCallbackData[$sParam]; } return null; } /** - * @return string + * @return mixed */ public function GetEventSource() { - return $this->sEventSource; + return $this->mEventSource; } /** - * @return mixed + * @return array */ - public function GetEventData() + public function GetEventData(): array { - return $this->mEventData; + return $this->aEventData; } /** - * @return mixed + * @return array */ - public function GetCallbackData() + public function GetCallbackData(): array { - return $this->mCallbackData; + return $this->aCallbackData; } } diff --git a/sources/Application/Service/EventService.php b/sources/Application/Service/EventService.php index 33326e6a1..ba02644dc 100644 --- a/sources/Application/Service/EventService.php +++ b/sources/Application/Service/EventService.php @@ -33,11 +33,11 @@ class EventService * * @throws \Exception */ - public static function Register($sEvent, callable $callback, $sEventSource = null, $aCallbackData = array(), $context = null, $fPriority = 0.0) + public static function Register(string $sEvent, callable $callback, $sEventSource = null, array $aCallbackData = [], $context = null, float $fPriority = 0.0): string { is_callable($callback, false, $sName); - $aEventCallbacks = isset(self::$aEvents[$sEvent]) ? self::$aEvents[$sEvent] : array(); + $aEventCallbacks = self::$aEvents[$sEvent] ?? []; $sId = 'event_'.self::$iEventIdCounter++; $aEventCallbacks[] = array( 'id' => $sId, @@ -78,7 +78,7 @@ class EventService * * @throws \Exception from the callback */ - public static function FireEvent($sEvent, $eventSource = null, $aEventData = array()) + public static function FireEvent(string $sEvent, $eventSource = null, array $aEventData = array()) { $oKPI = new ExecutionKPI(); $sSource = isset($aEventData['debug_info']) ? " {$aEventData['debug_info']}" : ''; @@ -116,7 +116,7 @@ class EventService $oKPI->ComputeStats('FireEvent', $sEvent); } - private static function MatchEventSource($srcRegistered, $srcEvent) + private static function MatchEventSource($srcRegistered, $srcEvent): bool { if (empty($srcRegistered)) { // no filtering @@ -153,7 +153,7 @@ class EventService return false; } - private static function MatchContext($registeredContext) + private static function MatchContext($registeredContext): bool { if (empty($registeredContext)) { return true; @@ -174,7 +174,7 @@ class EventService return false; } - private static function GetSourcesAsString($srcRegistered) + private static function GetSourcesAsString($srcRegistered): string { if (empty($srcRegistered)) { return ''; @@ -183,7 +183,7 @@ class EventService return $srcRegistered; } if (is_array($srcRegistered)) { - $sStr = implode(',', $srcRegistered); + return implode(',', $srcRegistered); } return ''; @@ -194,7 +194,7 @@ class EventService * * @param string $sId the callback registration id */ - public static function UnRegisterCallback($sId) + public static function UnRegisterCallback(string $sId) { $bRemoved = self::Browse(function ($sEvent, $idx, $aEventCallback) use ($sId) { if ($aEventCallback['id'] == $sId) { @@ -218,7 +218,7 @@ class EventService * * @param string $sEvent event to unregister */ - public static function UnRegisterEvent($sEvent) + public static function UnRegisterEvent(string $sEvent) { if (!isset(self::$aEvents[$sEvent])) { IssueLog::Trace("No registration found for event '$sEvent'", LOG_EVENT_SERVICE_CHANNEL); @@ -246,7 +246,7 @@ class EventService * * @return bool true if interrupted else false */ - private static function Browse(closure $callback) + private static function Browse(closure $callback): bool { foreach (self::$aEvents as $sEvent => $aCallbackList) { foreach ($aCallbackList as $idx => $aEventCallback) {