ConstantScore::compile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
ccs 5
cts 5
cp 1
crap 2
rs 9.4285
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 ConstantScore implements Query
19
{
20
    use Traits\Boost;
21
22
    /**
23
     * @var Query
24
     */
25
    private $query;
26
27
    /**
28
     * @param Query $query
29
     */
30 3
    public function __construct(Query $query)
31
    {
32 3
        $this->query = $query;
33 3
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function name(): string
39
    {
40 1
        return 'constant_score';
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function compile(): array
47
    {
48
        $query = [
49 2
            'filter' => \elastics_compile($this->query),
50
        ];
51
52 2
        if ($this->boost !== null) {
53 1
            $query['boost'] = $this->boost;
54
        }
55
56 2
        return $query;
57
    }
58
}
59