TimeSeriesQueryResponse::data()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Responses;
5
6
class TimeSeriesQueryResponse extends QueryResponse
7
{
8
    protected string $timeOutputName;
9
10
    /**
11
     * TimeSeriesQueryResponse constructor.
12
     *
13
     * @param array<string|int,string|int|array<mixed>> $response $response
14
     * @param string                                    $timeOutputName
15
     */
16 5
    public function __construct(array $response, string $timeOutputName)
17
    {
18 5
        parent::__construct($response);
19
20 5
        $this->timeOutputName = $timeOutputName;
21
    }
22
23
    /**
24
     * Return the data in a "normalized" way, so we can easily iterate over it
25
     *
26
     * @return array<array<mixed>>
27
     */
28 2
    public function data(): array
29
    {
30 2
        return array_map(function ($row) {
31
            /** @var array<string,array<array<mixed>>> $row */
32 1
            $row['result'][$this->timeOutputName] = $row['timestamp'];
33
34 1
            return $row['result'];
35 2
        }, $this->response);
36
    }
37
}