Completed
Pull Request — master (#348)
by
unknown
10:14
created

ScriptedMetricAggregation   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 152
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Metric;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
18
use ONGR\ElasticsearchDSL\ScriptAwareTrait;
19
20
/**
21
 * Class representing StatsAggregation.
22
 *
23
 * @link http://goo.gl/JbQsI3
24
 */
25
class ScriptedMetricAggregation extends AbstractAggregation
26
{
27
    use MetricTrait;
28
29
    public function __construct(
30
        private string $name,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
31
        private mixed $initScript = null,
32
        private mixed $mapScript = null,
33
        private mixed $combineScript = null,
34
        private mixed $reduceScript = null
35
    ) {
36
    
37
        parent::__construct($name);
38
39
        $this->setInitScript($initScript);
40
        $this->setMapScript($mapScript);
41
        $this->setCombineScript($combineScript);
42
        $this->setReduceScript($reduceScript);
43
    }
44
45
    public function getType(): string
46
    {
47
        return 'scripted_metric';
48
    }
49
50
    public function getInitScript(): mixed
51
    {
52
        return $this->initScript;
53
    }
54
55
    public function setInitScript(mixed $initScript): static
56
    {
57
        $this->initScript = $initScript;
58
59
        return $this;
60
    }
61
62
    public function getMapScript(): mixed
63
    {
64
        return $this->mapScript;
65
    }
66
67
    public function setMapScript(mixed $mapScript): static
68
    {
69
        $this->mapScript = $mapScript;
70
71
        return $this;
72
    }
73
74
    public function getCombineScript(): mixed
75
    {
76
        return $this->combineScript;
77
    }
78
79
    public function setCombineScript(mixed $combineScript): static
80
    {
81
        $this->combineScript = $combineScript;
82
83
        return $this;
84
    }
85
86
    public function getReduceScript(): mixed
87
    {
88
        return $this->reduceScript;
89
    }
90
91
    public function setReduceScript(mixed $reduceScript): static
92
    {
93
        $this->reduceScript = $reduceScript;
94
95
        return $this;
96
    }
97
98
99
    public function getArray(): array
100
    {
101
        return array_filter(
102
            [
103
                'init_script' => $this->getInitScript(),
104
                'map_script' => $this->getMapScript(),
105
                'combine_script' => $this->getCombineScript(),
106
                'reduce_script' => $this->getReduceScript(),
107
            ]
108
        );
109
    }
110
}
111