ScriptedMetricAggregation   A
last analyzed

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A getType() 0 4 1
A getInitScript() 0 4 1
A setInitScript() 0 6 1
A getMapScript() 0 4 1
A setMapScript() 0 6 1
A getCombineScript() 0 4 1
A setCombineScript() 0 6 1
A getReduceScript() 0 4 1
A setReduceScript() 0 6 1
A getArray() 0 13 1
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
namespace ONGR\ElasticsearchDSL\Aggregation\Metric;
13
14
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
15
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
16
use ONGR\ElasticsearchDSL\ScriptAwareTrait;
17
18
/**
19
 * Class representing StatsAggregation.
20
 *
21
 * @link http://goo.gl/JbQsI3
22
 */
23
class ScriptedMetricAggregation extends AbstractAggregation
24
{
25
    use MetricTrait;
26
27
    /**
28
     * @var mixed
29
     */
30
    private $initScript;
31
32
    /**
33
     * @var mixed
34
     */
35
    private $mapScript;
36
37
    /**
38
     * @var mixed
39
     */
40
    private $combineScript;
41
42
    /**
43
     * @var mixed
44
     */
45
    private $reduceScript;
46
    /**
47
     * ScriptedMetricAggregation constructor.
48
     * @param string $name
49
     * @param mixed $initScript
50
     * @param mixed $mapScript
51
     * @param mixed $combineScript
52
     * @param mixed $reduceScript
53
     */
54
    public function __construct(
55
        $name,
56
        $initScript = null,
57
        $mapScript = null,
58
        $combineScript = null,
59
        $reduceScript = null
60
    ) {
61
    
62
        parent::__construct($name);
63
64
        $this->setInitScript($initScript);
65
        $this->setMapScript($mapScript);
66
        $this->setCombineScript($combineScript);
67
        $this->setReduceScript($reduceScript);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getType()
74
    {
75
        return 'scripted_metric';
76
    }
77
78
    /**
79
     * @return mixed
80
     */
81
    public function getInitScript()
82
    {
83
        return $this->initScript;
84
    }
85
86
    /**
87
     * @param mixed $initScript
88
     *
89
     * @return $this
90
     */
91
    public function setInitScript($initScript)
92
    {
93
        $this->initScript = $initScript;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return mixed
100
     */
101
    public function getMapScript()
102
    {
103
        return $this->mapScript;
104
    }
105
106
    /**
107
     * @param mixed $mapScript
108
     *
109
     * @return $this
110
     */
111
    public function setMapScript($mapScript)
112
    {
113
        $this->mapScript = $mapScript;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function getCombineScript()
122
    {
123
        return $this->combineScript;
124
    }
125
126
    /**
127
     * @param mixed $combineScript
128
     *
129
     * @return $this
130
     */
131
    public function setCombineScript($combineScript)
132
    {
133
        $this->combineScript = $combineScript;
134
135
        return $this;
136
    }
137
138
    /**
139
     * @return mixed
140
     */
141
    public function getReduceScript()
142
    {
143
        return $this->reduceScript;
144
    }
145
146
    /**
147
     * @param mixed $reduceScript
148
     *
149
     * @return $this
150
     */
151
    public function setReduceScript($reduceScript)
152
    {
153
        $this->reduceScript = $reduceScript;
154
155
        return $this;
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    public function getArray()
162
    {
163
        $out = array_filter(
164
            [
165
                'init_script' => $this->getInitScript(),
166
                'map_script' => $this->getMapScript(),
167
                'combine_script' => $this->getCombineScript(),
168
                'reduce_script' => $this->getReduceScript(),
169
            ]
170
        );
171
172
        return $out;
173
    }
174
}
175