SessionFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 16
c 1
b 0
f 1
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 21 2
1
<?php
2
3
namespace Socialblue\LaravelQueryAdviser\Helper;
4
5
use Illuminate\Support\Arr;
6
7
class SessionFormatter
8
{
9
    public static function format(array $data, string $sessionKey): array
10
    {
11
        $flattedSessionData = Arr::flatten($data, 1);
12
13
        if (empty($flattedSessionData)) {
14
            return [];
15
        }
16
17
        $queries = count($flattedSessionData);
18
        $totalQueryTime = array_sum(array_column($flattedSessionData, 'queryTime'));
19
        $routes = count(array_unique(array_column($flattedSessionData, 'url')));
20
        $firstQueryLoggedTime = min(array_keys($data));
21
        $lastQueryLoggedTime = max(array_keys($data));
22
23
        return [
24
            'sessionKey' => $sessionKey,
25
            'queries' => $queries,
26
            'queryTime' => $totalQueryTime,
27
            'routes' => $routes,
28
            'firstQueryLogged' => $firstQueryLoggedTime,
29
            'lastQueryLogged' => $lastQueryLoggedTime,
30
        ];
31
    }
32
}
33