Completed
Pull Request — master (#109)
by
unknown
02:59
created

GeoCentroidAggregation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getArray() 0 13 2
A getType() 0 4 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;
13
14
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
15
16
/**
17
 * Class representing geo bounds aggregation.
18
 *
19
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geocentroid-aggregation.html
20
 */
21
class GeoCentroidAggregation extends AbstractAggregation
22
{
23
    use MetricTrait;
24
25
    /**
26
     * Inner aggregations container init.
27
     *
28
     * @param string $name
29
     * @param string $field
30
     */
31
    public function __construct($name, $field = null)
32
    {
33
        parent::__construct($name);
34
35
        $this->setField($field);
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getArray()
42
    {
43
        $data = [];
44
        if ($this->getField()) {
45
            $data['field'] = $this->getField();
46
        } else {
47
            throw new \LogicException('Geo centroid aggregation must have a field set.');
48
        }
49
50
        $data = $this->processArray($data);
51
52
        return $data;
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getType()
59
    {
60
        return 'geo_centroid';
61
    }
62
}
63