Term::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
use PHPinnacle\Elastics\Traits;
17
18
class Term implements Query
19
{
20
    use Traits\Boost;
21
22
    /**
23
     * @var string
24
     */
25
    private $field;
26
27
    /**
28
     * @var mixed
29
     */
30
    private $value;
31
32
    /**
33
     * @param string $field
34
     * @param mixed  $value
35
     */
36 18
    public function __construct(string $field, $value)
37
    {
38 18
        $this->field = $field;
39 18
        $this->value = $value;
40 18
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 16
    public function name(): string
46
    {
47 16
        return 'term';
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 16
    public function compile(): array
54
    {
55 16
        if ($this->boost === null) {
56
            return [
57 16
                $this->field => $this->value,
58
            ];
59
        }
60
61
        return [
62 1
            $this->field => [
63 1
                'value' => $this->value,
64 1
                'boost' => $this->boost,
65
            ],
66
        ];
67
    }
68
}
69