Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 1923cee

Browse files
committed
Moved the create record into a separate method.
1 parent aa014ad commit 1923cee

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/Statistics/Logger/MemoryStatisticsLogger.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function save()
103103
continue;
104104
}
105105

106-
$this->driver::create($statistic->toArray());
106+
$this->createRecord($statistic);
107107

108108
$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
109109

@@ -135,4 +135,15 @@ public function getStatistics(): array
135135
{
136136
return $this->statistics;
137137
}
138+
139+
/**
140+
* Create a new record using the Statistic Driver.
141+
*
142+
* @param Statistic $statistic
143+
* @return void
144+
*/
145+
public function createRecord(Statistic $statistic)
146+
{
147+
$this->driver::create($statistic->toArray());
148+
}
138149
}

src/Statistics/Logger/RedisStatisticsLogger.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ public function save()
122122
continue;
123123
}
124124

125-
$this->driver::create([
126-
'app_id' => $appId,
127-
'peak_connection_count' => $statistic['peak_connection_count'] ?? 0,
128-
'websocket_message_count' => $statistic['websocket_message_count'] ?? 0,
129-
'api_message_count' => $statistic['api_message_count'] ?? 0,
130-
]);
125+
$this->createRecord($statistic);
131126

132127
$currentConnectionCount = $this->channelManager->getConnectionCount($appId);
133128

@@ -203,4 +198,20 @@ protected function lock()
203198
{
204199
return new RedisLock($this->redis, 'laravel-websockets:lock', 0);
205200
}
201+
202+
/**
203+
* Create a new record using the Statistic Driver.
204+
*
205+
* @param array $statistic
206+
* @return void
207+
*/
208+
protected function createRecord(array $statistic): void
209+
{
210+
$this->driver::create([
211+
'app_id' => $appId,
212+
'peak_connection_count' => $statistic['peak_connection_count'] ?? 0,
213+
'websocket_message_count' => $statistic['websocket_message_count'] ?? 0,
214+
'api_message_count' => $statistic['api_message_count'] ?? 0,
215+
]);
216+
}
206217
}

0 commit comments

Comments
 (0)