diff --git a/src/Statistics/Logger/MemoryStatisticsLogger.php b/src/Statistics/Logger/MemoryStatisticsLogger.php index a0bee8e..f79d891 100644 --- a/src/Statistics/Logger/MemoryStatisticsLogger.php +++ b/src/Statistics/Logger/MemoryStatisticsLogger.php @@ -103,7 +103,7 @@ class MemoryStatisticsLogger implements StatisticsLogger continue; } - $this->driver::create($statistic->toArray()); + $this->createRecord($statistic); $currentConnectionCount = $this->channelManager->getConnectionCount($appId); @@ -135,4 +135,15 @@ class MemoryStatisticsLogger implements StatisticsLogger { return $this->statistics; } + + /** + * Create a new record using the Statistic Driver. + * + * @param Statistic $statistic + * @return void + */ + public function createRecord(Statistic $statistic) + { + $this->driver::create($statistic->toArray()); + } } diff --git a/src/Statistics/Logger/RedisStatisticsLogger.php b/src/Statistics/Logger/RedisStatisticsLogger.php index 5350b45..47d2cac 100644 --- a/src/Statistics/Logger/RedisStatisticsLogger.php +++ b/src/Statistics/Logger/RedisStatisticsLogger.php @@ -122,12 +122,7 @@ class RedisStatisticsLogger implements StatisticsLogger continue; } - $this->driver::create([ - 'app_id' => $appId, - 'peak_connection_count' => $statistic['peak_connection_count'] ?? 0, - 'websocket_message_count' => $statistic['websocket_message_count'] ?? 0, - 'api_message_count' => $statistic['api_message_count'] ?? 0, - ]); + $this->createRecord($statistic); $currentConnectionCount = $this->channelManager->getConnectionCount($appId); @@ -203,4 +198,20 @@ class RedisStatisticsLogger implements StatisticsLogger { return new RedisLock($this->redis, 'laravel-websockets:lock', 0); } + + /** + * Create a new record using the Statistic Driver. + * + * @param array $statistic + * @return void + */ + protected function createRecord(array $statistic): void + { + $this->driver::create([ + 'app_id' => $appId, + 'peak_connection_count' => $statistic['peak_connection_count'] ?? 0, + 'websocket_message_count' => $statistic['websocket_message_count'] ?? 0, + 'api_message_count' => $statistic['api_message_count'] ?? 0, + ]); + } }