Completed
Pull Request — master (#109)
by
unknown
22:12 queued 19:23
created

GeoCentroidAggregation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
class GeoCentroidAggregation extends AbstractAggregation
20
{
21
    use MetricTrait;
22
23
    /**
24
     * Inner aggregations container init.
25
     *
26
     * @param string $name
27
     * @param string $field
28
     */
29
    public function __construct($name, $field = null)
30
    {
31
        parent::__construct($name);
32
33
        $this->setField($field);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getArray()
40
    {
41
        $data = [];
42
        if ($this->getField()) {
43
            $data['field'] = $this->getField();
44
        } else {
45
            throw new \LogicException('Geo centroid aggregation must have a field set.');
46
        }
47
48
        return $data;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getType()
55
    {
56
        return 'geo_centroid';
57
    }
58
}
59