Completed
Push — master ( 8d7496...504c55 )
by Simonas
07:21 queued 04:05
created

GeoCentroidAggregation::getArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
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 centroid 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
        return $data;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getType()
57
    {
58
        return 'geo_centroid';
59
    }
60
}
61