Completed
Pull Request — master (#148)
by Simonas
03:24
created

GeoBoundsAggregation::setWrapLongitude()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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 bounds aggregation.
19
 *
20
 * @link http://goo.gl/aGqw7Y
21
 */
22
class GeoBoundsAggregation extends AbstractAggregation
23
{
24
    use MetricTrait;
25
26
    /**
27
     * @var bool
28
     */
29
    private $wrapLongitude = true;
30
31
    /**
32
     * Inner aggregations container init.
33
     *
34
     * @param string $name
35
     * @param string $field
36
     * @param bool   $wrapLongitude
37
     */
38
    public function __construct($name, $field = null, $wrapLongitude = true)
39
    {
40
        parent::__construct($name);
41
42
        $this->setField($field);
43
        $this->setWrapLongitude($wrapLongitude);
44
    }
45
46
    /**
47
     * @return bool
48
     */
49
    public function isWrapLongitude()
50
    {
51
        return $this->wrapLongitude;
52
    }
53
54
    /**
55
     * @param bool $wrapLongitude
56
     */
57
    public function setWrapLongitude($wrapLongitude)
58
    {
59
        $this->wrapLongitude = $wrapLongitude;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getArray()
66
    {
67
        $data = [];
68
        if ($this->getField()) {
69
            $data['field'] = $this->getField();
70
        } else {
71
            throw new \LogicException('Geo bounds aggregation must have a field set.');
72
        }
73
74
        $data['wrap_longitude'] = $this->isWrapLongitude();
75
76
        return $data;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getType()
83
    {
84
        return 'geo_bounds';
85
    }
86
}
87