Completed
Pull Request — master (#348)
by
unknown
01:15
created

GeoBoundsAggregation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 69
rs 10
c 0
b 0
f 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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Metric;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait;
18
19
/**
20
 * Class representing geo bounds aggregation.
21
 *
22
 * @link http://goo.gl/aGqw7Y
23
 */
24
class GeoBoundsAggregation extends AbstractAggregation
25
{
26
    use MetricTrait;
27
28
    public function __construct(private string $name, private ?string $field = null, private bool $wrapLongitude = true)
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_PRIVATE, expecting T_VARIABLE
Loading history...
29
    {
30
        parent::__construct($name);
31
32
        $this->setField($field);
33
        $this->setWrapLongitude($wrapLongitude);
34
    }
35
36
    public function isWrapLongitude(): bool
37
    {
38
        return $this->wrapLongitude;
39
    }
40
41
    public function setWrapLongitude(bool $wrapLongitude): static
42
    {
43
        $this->wrapLongitude = $wrapLongitude;
44
45
        return $this;
46
    }
47
48
    public function getArray(): array
49
    {
50
        $data = [];
51
        if ($this->getField()) {
52
            $data['field'] = $this->getField();
53
        } else {
54
            throw new \LogicException('Geo bounds aggregation must have a field set.');
55
        }
56
57
        $data['wrap_longitude'] = $this->isWrapLongitude();
58
59
        return $data;
60
    }
61
62
    public function getType(): string
63
    {
64
        return 'geo_bounds';
65
    }
66
}
67