Completed
Pull Request — master (#348)
by
unknown
10:14
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
namespace ONGR\ElasticsearchDSL\Query\TermLevel;
4
5
use ONGR\ElasticsearchDSL\BuilderInterface;
6
use ONGR\ElasticsearchDSL\ParametersTrait;
7
8
/**
9
 * Represents Elasticsearch "term" query.
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
12
 */
13
class TermQuery implements BuilderInterface
14
{
15
    use ParametersTrait;
16
17
    public function __construct(
18
        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...
19
        private string $value,
20
        array $parameters = []
21
    ) {
22
        $this->setParameters($parameters);
23
    }
24
25
    public function getType(): string
26
    {
27
        return 'term';
28
    }
29
30
    public function toArray(): array
31
    {
32
        $query = $this->processArray();
33
34
        if (empty($query)) {
35
            $query = $this->value;
36
        } else {
37
            $query['value'] = $this->value;
38
        }
39
40
        $output = [
41
            $this->field => $query,
42
        ];
43
44
        return [$this->getType() => $output];
45
    }
46
}
47