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

Commit 5c93909

Browse files
committed
nitpick
1 parent f6c9add commit 5c93909

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/Statistics/Logger/HttpStatisticsLogger.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111

1212
class HttpStatisticsLogger implements StatisticsLogger
1313
{
14-
/** @var Statistic[] */
14+
/** @var \BeyondCode\LaravelWebSockets\Statistics\Statistic[] */
1515
protected $statistics = [];
1616

1717
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
1818
protected $channelManager;
1919

20-
/** @var Browser */
20+
/** @var \Clue\React\Buzz\Browser */
2121
protected $browser;
2222

2323
public function __construct(ChannelManager $channelManager, Browser $browser)
@@ -29,44 +29,46 @@ public function __construct(ChannelManager $channelManager, Browser $browser)
2929

3030
public function webSocketMessage(ConnectionInterface $connection)
3131
{
32-
$this->initializeStatistics($connection->app->id);
33-
34-
$this->statistics[$connection->app->id]->webSocketMessage();
32+
$this
33+
->findOrMakeStatisticForAppId($connection->app->id)
34+
->webSocketMessage();
3535
}
3636

3737
public function apiMessage($appId)
3838
{
39-
$this->initializeStatistics($appId);
40-
41-
$this->statistics[$appId]->apiMessage();
39+
$this
40+
->findOrMakeStatisticForAppId($appId)
41+
->apiMessage();
4242
}
4343

4444
public function connection(ConnectionInterface $connection)
4545
{
46-
$this->initializeStatistics($connection->app->id);
47-
48-
$this->statistics[$connection->app->id]->connection();
46+
$this
47+
->findOrMakeStatisticForAppId($connection->app->id)
48+
->connection();
4949
}
5050

5151
public function disconnection(ConnectionInterface $connection)
5252
{
53-
$this->initializeStatistics($connection->app->id);
54-
55-
$this->statistics[$connection->app->id]->disconnection();
53+
$this
54+
->findOrMakeStatisticForAppId($connection->app->id)
55+
->disconnection();
5656
}
5757

58-
protected function initializeStatistics($id)
58+
protected function findOrMakeStatisticForAppId($appId): Statistic
5959
{
60-
if (!isset($this->statistics[$id])) {
61-
$this->statistics[$id] = new Statistic($id);
60+
if (! isset($this->statistics[$appId])) {
61+
$this->statistics[$appId] = new Statistic($appId);
6262
}
63+
64+
return $this->statistics[$appId];
6365
}
6466

6567
public function save()
6668
{
6769
foreach ($this->statistics as $appId => $statistic) {
6870

69-
if (!$statistic->isEnabled()) {
71+
if (! $statistic->isEnabled()) {
7072
continue;
7173
}
7274

0 commit comments

Comments
 (0)