From 1bf41e9c994f7c04b054e021d5231131f178b892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Nikolaou?= Date: Fri, 5 Apr 2019 21:43:47 +0300 Subject: [PATCH] Refactor DiscoverEvents::within() The pairs of listeners and events can be mapped to groups of listeners keyed by the event name. By using `mapToDictionary` we can void zipping the pairs and then unzipping them while reducing. --- .../Foundation/Events/DiscoverEvents.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Illuminate/Foundation/Events/DiscoverEvents.php b/src/Illuminate/Foundation/Events/DiscoverEvents.php index 126b95d7225..cdc03e57e03 100644 --- a/src/Illuminate/Foundation/Events/DiscoverEvents.php +++ b/src/Illuminate/Foundation/Events/DiscoverEvents.php @@ -19,17 +19,12 @@ class DiscoverEvents */ public static function within($listenerPath, $basePath) { - $listenerEvents = collect(static::getListenerEvents((new Finder) - ->files() - ->in($listenerPath), $basePath)); - - return $listenerEvents->values() - ->zip($listenerEvents->keys()->all()) - ->reduce(function ($carry, $listenerEventPair) { - $carry[$listenerEventPair[0]][] = $listenerEventPair[1]; - - return $carry; - }, []); + return collect(static::getListenerEvents((new Finder) + ->files() + ->in($listenerPath), $basePath)) + ->mapToDictionary(function ($event, $listener) { + return [$event => $listener]; + })->all(); } /**