TermsQuery   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A toArray() 0 10 1
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 "terms" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html
21
 */
22
class TermsQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $field;
30
31
    /**
32
     * @var array
33
     */
34
    private $terms;
35
36
    /**
37
     * Constructor.
38
     *
39
     * @param string $field      Field name
40
     * @param array  $terms      An array of terms
41
     * @param array  $parameters Optional parameters
42
     */
43
    public function __construct($field, $terms, array $parameters = [])
44
    {
45
        $this->field = $field;
46
        $this->terms = $terms;
47
        $this->setParameters($parameters);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getType()
54
    {
55
        return 'terms';
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function toArray()
62
    {
63
        $query = [
64
            $this->field => $this->terms,
65
        ];
66
67
        $output = $this->processArray($query);
68
69
        return [$this->getType() => $output];
70
    }
71
}
72