Completed
Pull Request — master (#148)
by Simonas
03:24
created

ExtendedStatsAggregation::setSigma()   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 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 Extended stats aggregation.
20
 *
21
 * @link http://goo.gl/E0PpDv
22
 */
23
class ExtendedStatsAggregation extends AbstractAggregation
24
{
25
    use MetricTrait;
26
    use ScriptAwareTrait;
27
28
    /**
29
     * Inner aggregations container init.
30
     *
31
     * @param string $name
32
     * @param string $field
33
     * @param int    $sigma
34
     * @param string $script
35
     */
36
    public function __construct($name, $field = null, $sigma = null, $script = null)
37
    {
38
        parent::__construct($name);
39
40
        $this->setField($field);
41
        $this->setSigma($sigma);
42
        $this->setScript($script);
43
    }
44
45
    /**
46
     * @var int
47
     */
48
    private $sigma;
49
50
    /**
51
     * @return int
52
     */
53
    public function getSigma()
54
    {
55
        return $this->sigma;
56
    }
57
58
    /**
59
     * @param int $sigma
60
     */
61
    public function setSigma($sigma)
62
    {
63
        $this->sigma = $sigma;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getType()
70
    {
71
        return 'extended_stats';
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getArray()
78
    {
79
        $out = array_filter(
80
            [
81
                'field' => $this->getField(),
82
                'script' => $this->getScript(),
83
                'sigma' => $this->getSigma(),
84
            ],
85
            function ($val) {
86
                return ($val || is_numeric($val));
87
            }
88
        );
89
90
        return $out;
91
    }
92
}
93