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

RangeQuery::__construct()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 14

Duplication

Lines 6
Ratio 42.86 %

Importance

Changes 0
Metric Value
dl 6
loc 14
rs 9.4888
c 0
b 0
f 0
cc 5
nc 4
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
declare(strict_types=1);
13
14
namespace ONGR\ElasticsearchDSL\Query\TermLevel;
15
16
use ONGR\ElasticsearchDSL\BuilderInterface;
17
use ONGR\ElasticsearchDSL\ParametersTrait;
18
19
/**
20
 * Represents Elasticsearch "range" query.
21
 *
22
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
23
 */
24
class RangeQuery implements BuilderInterface
25
{
26
    use ParametersTrait;
27
28
    public const LT = 'lt';
29
30
    public const GT = 'gt';
31
32
    public const LTE = 'lte';
33
34
    public const GTE = 'gte';
35
36
    public function __construct(private string $field, array $parameters = [])
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...
37
    {
38
        $this->setParameters($parameters);
39
40
        if ($this->hasParameter(self::GTE) && $this->hasParameter(self::GT)) {
41
            unset($this->parameters[self::GT]);
42
        }
43
44
        if ($this->hasParameter(self::LTE) && $this->hasParameter(self::LT)) {
45
            unset($this->parameters[self::LT]);
46
        }
47
    }
48
49
    public function getType(): string
50
    {
51
        return 'range';
52
    }
53
54
    public function toArray(): array
55
    {
56
        $output = [
57
            $this->field => $this->getParameters(),
58
        ];
59
60
        return [$this->getType() => $output];
61
    }
62
}
63