Completed
Push — master ( 6c9334...f3ba17 )
by Simonas
02:26
created

RangeQuery::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 6
Ratio 42.86 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 14
rs 8.8571
cc 5
eloc 7
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
namespace ONGR\ElasticsearchDSL\Query\TermLevel;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "range" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
21
 */
22
class RangeQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * Range control names.
28
     */
29
    const LT = 'lt';
30
    const GT = 'gt';
31
    const LTE = 'lte';
32
    const GTE = 'gte';
33
34
    /**
35
     * @var string Field name.
36
     */
37
    private $field;
38
39
    /**
40
     * @param string $field
41
     * @param array  $parameters
42
     */
43
    public function __construct($field, array $parameters = [])
44
    {
45
        $this->setParameters($parameters);
46
47 View Code Duplication
        if ($this->hasParameter(self::GTE) && $this->hasParameter(self::GT)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
            unset($this->parameters[self::GT]);
49
        }
50
51 View Code Duplication
        if ($this->hasParameter(self::LTE) && $this->hasParameter(self::LT)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
            unset($this->parameters[self::LT]);
53
        }
54
55
        $this->field = $field;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function getType()
62
    {
63
        return 'range';
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function toArray()
70
    {
71
        $output = [
72
            $this->field => $this->getParameters(),
73
        ];
74
75
        return [$this->getType() => $output];
76
    }
77
}
78