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

StatsAggregation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getType() 0 4 1
A getArray() 0 12 3
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 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
22
 */
23
class StatsAggregation 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 string $script
34
     */
35
    public function __construct($name, $field = null, $script = null)
36
    {
37
        parent::__construct($name);
38
39
        $this->setField($field);
40
        $this->setScript($script);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getType()
47
    {
48
        return 'stats';
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getArray()
55
    {
56
        $out = [];
57
        if ($this->getField()) {
58
            $out['field'] = $this->getField();
59
        }
60
        if ($this->getScript()) {
61
            $out['script'] = $this->getScript();
62
        }
63
64
        return $out;
65
    }
66
}
67