JavaScriptPostAggregator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 12
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toArray() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\PostAggregations;
5
6
use Level23\Druid\Collections\PostAggregationCollection;
7
8
class JavaScriptPostAggregator implements PostAggregatorInterface
9
{
10
    protected string $outputName;
11
12
    protected PostAggregationCollection $fields;
13
14
    protected string $javascriptFunction;
15
16
    /**
17
     * JavaScriptPostAggregator constructor.
18
     *
19
     * NOTE: JavaScript-based functionality is disabled by default. Please refer to the Druid JavaScript programming
20
     * guide for guidelines about using Druid's JavaScript functionality, including instructions on how to enable it.
21
     *
22
     * @param string                    $outputName
23
     * @param PostAggregationCollection $fields
24
     * @param string                    $javascriptFunction
25
     */
26 1
    public function __construct(string $outputName, PostAggregationCollection $fields, string $javascriptFunction)
27
    {
28 1
        $this->outputName         = $outputName;
29 1
        $this->fields             = $fields;
30 1
        $this->javascriptFunction = $javascriptFunction;
31
    }
32
33
    /**
34
     * Return the post aggregator as it can be used in a druid query.
35
     *
36
     * @return array<string,string|array<array<string,string|array<mixed>>>>
37
     */
38 1
    public function toArray(): array
39
    {
40 1
        return [
41 1
            'type'       => 'javascript',
42 1
            'name'       => $this->outputName,
43 1
            'fieldNames' => $this->fields->toArray(),
44 1
            'function'   => $this->javascriptFunction,
45 1
        ];
46
    }
47
}