HistogramPostAggregator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 18
dl 0
loc 56
ccs 16
cts 16
cp 1
rs 10
c 3
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A toArray() 0 17 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\PostAggregations;
5
6
class HistogramPostAggregator implements PostAggregatorInterface
7
{
8
    protected string $outputName;
9
10
    protected PostAggregatorInterface $dimension;
11
12
    /**
13
     * @var array<float>|null
14
     */
15
    protected ?array $splitPoints = null;
16
17
    protected ?int $numBins = null;
18
19
    /**
20
     * HistogramPostAggregator constructor.
21
     *
22
     * @param PostAggregatorInterface $dimension     Post aggregator that refers to a DoublesSketch (fieldAccess or
23
     *                                               another post aggregator)
24
     * @param string                  $outputName
25
     * @param array<float>|null       $splitPoints   array of split points (optional)
26
     * @param int|null                $numBins       number of bins (optional, defaults to 10)
27
     */
28 3
    public function __construct(
29
        PostAggregatorInterface $dimension,
30
        string $outputName,
31
        ?array $splitPoints = null,
32
        ?int $numBins = null
33
    ) {
34 3
        $this->outputName  = $outputName;
35 3
        $this->dimension   = $dimension;
36 3
        $this->splitPoints = $splitPoints;
37 3
        $this->numBins     = $numBins;
38
    }
39
40
    /**
41
     * Return the aggregator as it can be used in a druid query.
42
     *
43
     * @return array<string,string|float[]|array<string,string|array<mixed>>|int>
44
     */
45 3
    public function toArray(): array
46
    {
47 3
        $result = [
48 3
            'type'  => 'quantilesDoublesSketchToHistogram',
49 3
            'name'  => $this->outputName,
50 3
            'field' => $this->dimension->toArray(),
51 3
        ];
52
53 3
        if ($this->splitPoints !== null) {
54 1
            $result['splitPoints'] = $this->splitPoints;
55
        }
56
57 3
        if ($this->numBins !== null) {
58 1
            $result['numBins'] = $this->numBins;
59
        }
60
61 3
        return $result;
62
    }
63
}