Boosting::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of PhpStorm.
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 Boosting implements Query
18
{
19
    /**
20
     * @var Query
21
     */
22
    private $positiveQuery;
23
24
    /**
25
     * @var float
26
     */
27
    private $positiveBoost;
28
29
    /**
30
     * @var Query
31
     */
32
    private $negativeQuery;
33
34
    /**
35
     * @var float
36
     */
37
    private $negativeBoost;
38
39
    /**
40
     * @param Query      $positive
41
     * @param float|null $boost
42
     *
43
     * @return Boosting
44
     */
45 1
    public function positive(Query $positive, float $boost = null): self
46
    {
47 1
        $this->positiveQuery = $positive;
48 1
        $this->positiveBoost = $boost;
49
50 1
        return $this;
51
    }
52
53
    /**
54
     * @param Query      $negative
55
     * @param float|null $boost
56
     *
57
     * @return Boosting
58
     */
59 1
    public function negative(Query $negative, float $boost = null): self
60
    {
61 1
        $this->negativeQuery = $negative;
62 1
        $this->negativeBoost = $boost;
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function name(): string
71
    {
72 1
        return 'boosting';
73
    }
74
75
    /**
76
     * @return array
77
     */
78 2
    public function compile(): array
79
    {
80 2
        $query = [];
81
82 2
        if ($this->positiveQuery) {
83 1
            $query['positive'] = \elastics_compile($this->positiveQuery);
84
        }
85
86 2
        if ($this->positiveBoost !== null) {
87 1
            $query['boost'] = $this->positiveBoost;
88
        }
89
90 2
        if ($this->negativeQuery) {
91 1
            $query['negative'] = \elastics_compile($this->negativeQuery);
92
        }
93
94 2
        if ($this->negativeBoost !== null) {
95 1
            $query['negative_boost'] = $this->negativeBoost;
96
        }
97
98 2
        return $query;
99
    }
100
}
101