@@ -177,8 +177,8 @@ public function save()
177177 return ;
178178 }
179179
180- $ statistic = $ this ->listToStatisticInstance (
181- $ appId , $ list
180+ $ statistic = $ this ->arrayToStatisticInstance (
181+ $ appId , $ this -> redisListToArray ( $ list)
182182 );
183183
184184 $ this ->createRecord ($ statistic , $ appId );
@@ -228,8 +228,8 @@ public function getStatistics(): PromiseInterface
228228 ->getPublishClient ()
229229 ->hgetall ($ this ->channelManager ->getRedisKey ($ appId , null , ['stats ' ]))
230230 ->then (function ($ list ) use ($ appId , &$ appsWithStatistics ) {
231- $ appsWithStatistics [$ appId ] = $ this ->listToStatisticInstance (
232- $ appId , $ list
231+ $ appsWithStatistics [$ appId ] = $ this ->arrayToStatisticInstance (
232+ $ appId , $ this -> redisListToArray ( $ list)
233233 );
234234 });
235235 }
@@ -250,6 +250,8 @@ public function getAppStatistics($appId): PromiseInterface
250250 ->getPublishClient ()
251251 ->hgetall ($ this ->channelManager ->getRedisKey ($ appId , null , ['stats ' ]))
252252 ->then (function ($ list ) use ($ appId ) {
253+ return $ this ->arrayToStatisticInstance (
254+ $ appId , $ this ->redisListToArray ($ list )
253255 );
254256 });
255257 }
@@ -366,13 +368,12 @@ protected function lock()
366368 * @param array $list
367369 * @return array
368370 */
369- protected function listToKeyValue (array $ list )
371+ protected function redisListToArray (array $ list )
370372 {
371373 // Redis lists come into a format where the keys are on even indexes
372374 // and the values are on odd indexes. This way, we know which
373375 // ones are keys and which ones are values and their get combined
374376 // later to form the key => value array.
375-
376377 [$ keys , $ values ] = collect ($ list )->partition (function ($ value , $ key ) {
377378 return $ key % 2 === 0 ;
378379 });
@@ -381,21 +382,18 @@ protected function listToKeyValue(array $list)
381382 }
382383
383384 /**
384- * Transform a list coming from a Redis list
385- * to a Statistic instance.
385+ * Transform a key-value pair to a Statistic instance.
386386 *
387387 * @param string|int $appId
388- * @param array $list
388+ * @param array $stats
389389 * @return \BeyondCode\LaravelWebSockets\Statistics\Statistic
390390 */
391- protected function listToStatisticInstance ($ appId , array $ list )
391+ protected function arrayToStatisticInstance ($ appId , array $ stats )
392392 {
393- $ list = $ this ->listToKeyValue ($ list );
394-
395- return (new Statistic ($ appId ))
396- ->setCurrentConnectionsCount ($ list ['current_connections_count ' ] ?? 0 )
397- ->setPeakConnectionsCount ($ list ['peak_connections_count ' ] ?? 0 )
398- ->setWebSocketMessagesCount ($ list ['websocket_messages_count ' ] ?? 0 )
399- ->setApiMessagesCount ($ list ['api_messages_count ' ] ?? 0 );
393+ return Statistic::new ($ appId )
394+ ->setCurrentConnectionsCount ($ stats ['current_connections_count ' ] ?? 0 )
395+ ->setPeakConnectionsCount ($ stats ['peak_connections_count ' ] ?? 0 )
396+ ->setWebSocketMessagesCount ($ stats ['websocket_messages_count ' ] ?? 0 )
397+ ->setApiMessagesCount ($ stats ['api_messages_count ' ] ?? 0 );
400398 }
401399}
0 commit comments