Completed
Pull Request — master (#257)
by
unknown
01:15
created

DashboardApiController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 29 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
4
5
class DashboardApiController
6
{
7
    public function __invoke($appId)
8
    {
9
        $webSocketsStatisticsEntryModelClass = config('websockets.statistics.model');
10
        $statistics = $webSocketsStatisticsEntryModelClass::where('app_id', $appId)->latest()->limit(120)->get();
11
12
        $statisticData = $statistics->map(function ($statistic) {
13
            return [
14
                'timestamp' => (string) $statistic->created_at,
15
                'peak_connection_count' => $statistic->peak_connection_count,
16
                'websocket_message_count' => $statistic->websocket_message_count,
17
                'api_message_count' => $statistic->api_message_count,
18
            ];
19
        })->reverse();
20
21
        return [
22
            'peak_connections' => [
23
                'x' => $statisticData->pluck('timestamp'),
24
                'y' => $statisticData->pluck('peak_connection_count'),
25
            ],
26
            'websocket_message_count' => [
27
                'x' => $statisticData->pluck('timestamp'),
28
                'y' => $statisticData->pluck('websocket_message_count'),
29
            ],
30
            'api_message_count' => [
31
                'x' => $statisticData->pluck('timestamp'),
32
                'y' => $statisticData->pluck('api_message_count'),
33
            ],
34
        ];
35
    }
36
}
37