StatisticsUpdated   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A broadcastWith() 0 10 1
A broadcastOn() 0 6 1
A broadcastAs() 0 4 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Statistics\Events;
4
5
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
6
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
7
use Illuminate\Broadcasting\PrivateChannel;
8
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Support\Str;
11
12
class StatisticsUpdated implements ShouldBroadcast
13
{
14
    use SerializesModels;
15
16
    /** @var \BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry */
17
    protected $webSocketsStatisticsEntry;
18
19
    public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry)
20
    {
21
        $this->webSocketsStatisticsEntry = $webSocketsStatisticsEntry;
22
    }
23
24
    public function broadcastWith()
25
    {
26
        return [
27
            'time' => (string) $this->webSocketsStatisticsEntry->created_at,
28
            'app_id' => $this->webSocketsStatisticsEntry->app_id,
29
            'peak_connection_count' => $this->webSocketsStatisticsEntry->peak_connection_count,
30
            'websocket_message_count' => $this->webSocketsStatisticsEntry->websocket_message_count,
31
            'api_message_count' => $this->webSocketsStatisticsEntry->api_message_count,
32
        ];
33
    }
34
35
    public function broadcastOn()
36
    {
37
        $channelName = Str::after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-');
38
39
        return new PrivateChannel($channelName);
40
    }
41
42
    public function broadcastAs()
43
    {
44
        return 'statistics-updated';
45
    }
46
}
47