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

TermQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
rs 10
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 "term" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
21
 */
22
class TermQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    public function __construct(
27
        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...
28
        private string $value,
29
        array $parameters = []
30
    ) {
31
        $this->setParameters($parameters);
32
    }
33
34
    public function getType(): string
35
    {
36
        return 'term';
37
    }
38
39
    public function toArray(): array
40
    {
41
        $query = $this->processArray();
42
43
        if (empty($query)) {
44
            $query = $this->value;
45
        } else {
46
            $query['value'] = $this->value;
47
        }
48
49
        $output = [
50
            $this->field => $query,
51
        ];
52
53
        return [$this->getType() => $output];
54
    }
55
}
56