Completed
Pull Request — master (#148)
by Simonas
05:22
created

ScriptedMetricAggregation::getReduceScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
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($name, $initScript = null, $mapScript = null, $combineScript = null, $reduceScript = null)
55
    {
56
        parent::__construct($name);
57
58
        $this->setInitScript($initScript);
59
        $this->setMapScript($mapScript);
60
        $this->setCombineScript($combineScript);
61
        $this->setReduceScript($reduceScript);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getType()
68
    {
69
        return 'stats';
70
    }
71
72
    /**
73
     * @return mixed
74
     */
75
    public function getInitScript()
76
    {
77
        return $this->initScript;
78
    }
79
80
    /**
81
     * @param mixed $initScript
82
     */
83
    public function setInitScript($initScript)
84
    {
85
        $this->initScript = $initScript;
86
    }
87
88
    /**
89
     * @return mixed
90
     */
91
    public function getMapScript()
92
    {
93
        return $this->mapScript;
94
    }
95
96
    /**
97
     * @param mixed $mapScript
98
     */
99
    public function setMapScript($mapScript)
100
    {
101
        $this->mapScript = $mapScript;
102
    }
103
104
    /**
105
     * @return mixed
106
     */
107
    public function getCombineScript()
108
    {
109
        return $this->combineScript;
110
    }
111
112
    /**
113
     * @param mixed $combineScript
114
     */
115
    public function setCombineScript($combineScript)
116
    {
117
        $this->combineScript = $combineScript;
118
    }
119
120
    /**
121
     * @return mixed
122
     */
123
    public function getReduceScript()
124
    {
125
        return $this->reduceScript;
126
    }
127
128
    /**
129
     * @param mixed $reduceScript
130
     */
131
    public function setReduceScript($reduceScript)
132
    {
133
        $this->reduceScript = $reduceScript;
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139
    public function getArray()
140
    {
141
        $out = array_filter(
142
            [
143
                'init_script' => $this->getInitScript(),
144
                'map_script' => $this->getMapScript(),
145
                'combine_script' => $this->getCombineScript(),
146
                'reduce_script' => $this->getReduceScript(),
147
            ]
148
        );
149
150
        return $out;
151
    }
152
}
153