Terms   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 4 2
A lookup() 0 10 1
A __construct() 0 4 1
A name() 0 3 1
1
<?php
2
/*
3
 * This file is part of PHPinnacle/Elastics.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace PHPinnacle\Elastics\Query;
14
15
use PHPinnacle\Elastics\Query;
16
17
class Terms implements Query
18
{
19
    /**
20
     * @var string
21
     */
22
    private $field;
23
24
    /**
25
     * @var array
26
     */
27
    private $values;
28
29
    /**
30
     * @var array
31
     */
32
    private $lookup;
33
34
    /**
35
     * @param string $field
36
     * @param array  $values
37
     */
38 3
    public function __construct(string $field, array $values = [])
39
    {
40 3
        $this->field  = $field;
41 3
        $this->values = \array_values($values);
42 3
    }
43
44
    /**
45
     * @param string $index
46
     * @param string $id
47
     * @param string $path
48
     * @param string $type
49
     *
50
     * @return self
51
     */
52 1
    public function lookup(string $index, string $id, string $path, string $type = '_doc'): self
53
    {
54 1
        $this->lookup = [
55 1
            'index' => $index,
56 1
            'type'  => $type,
57 1
            'id'    => $id,
58 1
            'path'  => $path,
59
        ];
60
61 1
        return $this;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 1
    public function name(): string
68
    {
69 1
        return 'terms';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 2
    public function compile(): array
76
    {
77
        return [
78 2
            $this->field => $this->lookup ? $this->lookup : $this->values,
79
        ];
80
    }
81
}
82