Completed
Pull Request — master (#257)
by
unknown
01:59 queued 40s
created

DashboardApiController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
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