Completed
Pull Request — master (#348)
by
unknown
10:14
created

GeoDistanceQuery   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 56
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\Query\Geo;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * Represents Elasticsearch "geo_distance" query.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
23
 */
24
class GeoDistanceQuery implements BuilderInterface
25
{
26
    use ParametersTrait;
27
28
    public function __construct(
29
        private string $field,
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 $distance,
31
        private mixed $location,
32
        array $parameters = []
33
    ) {
34
        $this->setParameters($parameters);
35
    }
36
37
    public function getType(): string
38
    {
39
        return 'geo_distance';
40
    }
41
42
    public function toArray(): array
43
    {
44
        $query = [
45
            'distance' => $this->distance,
46
            $this->field => $this->location,
47
        ];
48
        $output = $this->processArray($query);
49
50
        return [$this->getType() => $output];
51
    }
52
}
53