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

GeoHashGridAggregation::getArray()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.2248
c 0
b 0
f 0
cc 5
nc 9
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Aggregation\Bucketing;
15
16
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation;
17
use ONGR\ElasticsearchDSL\Aggregation\Type\BucketingTrait;
18
19
/**
20
 * Class representing geohash grid aggregation.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html
23
 */
24
class GeoHashGridAggregation extends AbstractAggregation
25
{
26
    use BucketingTrait;
27
28
    public function __construct(
29
        private string $name,
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...
30
        private ?string $field = null,
31
        private ?int $precision = null,
32
        private ?int $size = null,
33
        private ?int $shardSize = null
34
    ) {
35
        parent::__construct($name);
36
37
        $this->setField($field);
38
        $this->setPrecision($precision);
39
        $this->setSize($size);
40
        $this->setShardSize($shardSize);
41
    }
42
43
    public function getPrecision(): ?int
44
    {
45
        return $this->precision;
46
    }
47
48
    public function setPrecision(?int $precision): static
49
    {
50
        $this->precision = $precision;
51
52
        return $this;
53
    }
54
55
    public function getSize(): ?int
56
    {
57
        return $this->size;
58
    }
59
60
    public function setSize(?int $size): static
61
    {
62
        $this->size = $size;
63
64
        return $this;
65
    }
66
67
    public function getShardSize(): ?int
68
    {
69
        return $this->shardSize;
70
    }
71
72
    public function setShardSize(?int $shardSize): static
73
    {
74
        $this->shardSize = $shardSize;
75
76
        return $this;
77
    }
78
79
    public function getArray(): array
80
    {
81
        $data = [];
82
83
        if ($this->getField()) {
84
            $data['field'] = $this->getField();
85
        } else {
86
            throw new \LogicException('Geo bounds aggregation must have a field set.');
87
        }
88
89
        if ($this->getPrecision()) {
90
            $data['precision'] = $this->getPrecision();
91
        }
92
93
        if ($this->getSize()) {
94
            $data['size'] = $this->getSize();
95
        }
96
97
        if ($this->getShardSize()) {
98
            $data['shard_size'] = $this->getShardSize();
99
        }
100
101
        return $data;
102
    }
103
104
    public function getType(): string
105
    {
106
        return 'geohash_grid';
107
    }
108
}
109