ExtendedStatsAggregation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 74
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getSigma() 0 4 1
A setSigma() 0 6 1
A getType() 0 4 1
A getArray() 0 15 2
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
     * @return $this
62
     */
63
    public function setSigma($sigma)
64
    {
65
        $this->sigma = $sigma;
66
67
        return $this;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getType()
74
    {
75
        return 'extended_stats';
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function getArray()
82
    {
83
        $out = array_filter(
84
            [
85
                'field' => $this->getField(),
86
                'script' => $this->getScript(),
87
                'sigma' => $this->getSigma(),
88
            ],
89
            function ($val) {
90
                return ($val || is_numeric($val));
91
            }
92
        );
93
94
        return $out;
95
    }
96
}
97