GlobalAggregation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addAggregation() 0 4 1
A __construct() 0 3 1
A toArray() 0 5 1
A getAggregations() 0 3 1
1
<?php namespace Nord\Lumen\Elasticsearch\Search\Aggregation\Bucket;
2
3
use Nord\Lumen\Elasticsearch\Search\Aggregation\Aggregation;
4
use Nord\Lumen\Elasticsearch\Search\Aggregation\AggregationCollection;
5
6
/**
7
 * Defines a single bucket of all the documents within the search execution context. This context is defined by the
8
 * indices and the document types you’re searching on, but is not influenced by the search query itself.
9
 *
10
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html
11
 */
12
class GlobalAggregation extends AbstractAggregation
13
{
14
    /**
15
     * @var AggregationCollection
16
     */
17
    private $aggregations;
18
19
20
    /**
21
     * Constructor.
22
     */
23
    public function __construct()
24
    {
25
        $this->aggregations = new AggregationCollection();
26
    }
27
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function toArray()
33
    {
34
        return [
35
            'global' => new \stdClass(),
36
            'aggs' => $this->getAggregations()->toArray()
37
        ];
38
    }
39
40
41
    /**
42
     * @return AggregationCollection
43
     */
44
    public function getAggregations()
45
    {
46
        return $this->aggregations;
47
    }
48
49
50
    /**
51
     * @param Aggregation $aggregation
52
     * @return GlobalAggregation
53
     */
54
    public function addAggregation(Aggregation $aggregation)
55
    {
56
        $this->aggregations->add($aggregation);
57
        return $this;
58
    }
59
}
60