Total Complexity | 6 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class AnyAggregator extends MethodAggregator |
||
9 | { |
||
10 | /** |
||
11 | * @var int|null |
||
12 | */ |
||
13 | protected $maxStringBytes; |
||
14 | |||
15 | /** |
||
16 | * constructor. |
||
17 | * |
||
18 | * @param string $metricName |
||
19 | * @param string $outputName When not given, we will use the same name as the metric. |
||
20 | * @param string $type The type of field. This can either be "long", "float" or |
||
21 | * "double" |
||
22 | * @param int|null $maxStringBytes optional, defaults to 1024 |
||
23 | */ |
||
24 | 6 | public function __construct( |
|
25 | string $metricName, |
||
26 | string $outputName = '', |
||
27 | string $type = 'long', |
||
28 | int $maxStringBytes = null |
||
29 | ) { |
||
30 | 6 | $type = DataType::validate($type); |
|
31 | |||
32 | 5 | $this->type = $type; |
|
33 | 5 | $this->metricName = $metricName; |
|
34 | 5 | $this->outputName = $outputName ?: $metricName; |
|
35 | 5 | $this->maxStringBytes = $maxStringBytes; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * Return the aggregator as it can be used in a druid query. |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | 5 | public function toArray(): array |
|
44 | { |
||
45 | 5 | $response = [ |
|
46 | 5 | 'type' => $this->type . ucfirst($this->getMethod()), |
|
47 | 5 | 'name' => $this->outputName, |
|
48 | 5 | 'fieldName' => $this->metricName, |
|
49 | ]; |
||
50 | |||
51 | 5 | if ($this->type == DataType::STRING && $this->maxStringBytes !== null) { |
|
52 | 1 | $response['maxStringBytes'] = $this->maxStringBytes; |
|
53 | } |
||
54 | |||
55 | 5 | return $response; |
|
56 | } |
||
57 | |||
58 | /** |
||
59 | * Returns the method for the type aggregation |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 5 | protected function getMethod(): string |
|
66 | } |
||
67 | } |