Completed
Pull Request — master (#148)
by Simonas
02:51
created

GeoCentroidAggregation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

3 Methods

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