RankPostAggregator::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 2
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\PostAggregations;
5
6
class RankPostAggregator implements PostAggregatorInterface
7
{
8
    protected string $outputName;
9
10
    protected PostAggregatorInterface $dimension;
11
12
    protected float $value;
13
14
    /**
15
     * QuantilePostAggregator constructor.
16
     *
17
     * @param PostAggregatorInterface $dimension    Post aggregator that refers to a DoublesSketch (fieldAccess or
18
     *                                              another post aggregator)
19
     * @param string                  $outputName   The name as it will be used in our result.
20
     * @param float                   $value        This returns an approximation to the rank of a given value that is
21
     *                                              the fraction of the distribution less than that value.
22
     */
23 1
    public function __construct(PostAggregatorInterface $dimension, string $outputName, float $value)
24
    {
25 1
        $this->outputName = $outputName;
26 1
        $this->dimension  = $dimension;
27 1
        $this->value      = $value;
28
    }
29
30
    /**
31
     * Return the aggregator as it can be used in a druid query.
32
     *
33
     * @return array<string,string|array<string,string|array<mixed>>|float>
34
     */
35 1
    public function toArray(): array
36
    {
37 1
        return [
38 1
            'type'  => 'quantilesDoublesSketchToRank',
39 1
            'name'  => $this->outputName,
40 1
            'field' => $this->dimension->toArray(),
41 1
            'value' => $this->value,
42 1
        ];
43
    }
44
}