Completed
Push — master ( c0d232...67b20e )
by Olivier
43:39 queued 05:10
created

BoostingQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 43
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get_negative() 0 3 2
A get_positive() 0 3 2
A jsonSerialize() 0 7 1
1
<?php
2
3
namespace olvlvl\ElasticsearchDSL\Query\Compound;
4
5
use olvlvl\ElasticsearchDSL\Query\QueryAbstract;
6
use olvlvl\ElasticsearchDSL\Query\QueryCollection;
7
8
/**
9
 * @property-read QueryCollection $positive
10
 * @property-read QueryCollection $negative
11
 */
12
class BoostingQuery extends QueryAbstract
13
{
14
	const NAME = 'boosting';
15
16
	/**
17
	 * @var QueryCollection
18
	 */
19
	private $positive;
20
21
	protected function get_positive(): QueryCollection
22
	{
23
		return $this->positive ?: $this->positive = new QueryCollection;
0 ignored issues
show
Bug introduced by
The property positive is declared read-only in olvlvl\ElasticsearchDSL\...\Compound\BoostingQuery.
Loading history...
24
	}
25
26
	/**
27
	 * @var QueryCollection
28
	 */
29
	private $negative;
30
31
	protected function get_negative(): QueryCollection
32
	{
33
		return $this->negative ?: $this->negative = new QueryCollection;
0 ignored issues
show
Bug introduced by
The property negative is declared read-only in olvlvl\ElasticsearchDSL\...\Compound\BoostingQuery.
Loading history...
34
	}
35
36
	/**
37
	 * @var float
38
	 */
39
	private $negative_boost;
40
41
	public function __construct(float $negative_boost = 0.5)
42
	{
43
		$this->negative_boost = $negative_boost;
44
45
		parent::__construct();
46
	}
47
48
	public function jsonSerialize()
49
	{
50
		return [ self::NAME => array_filter([
51
52
			'positive' => $this->positive,
53
			'negative' => $this->negative,
54
			'negative_boost' => $this->negative_boost,
55
56
		]) ];
57
	}
58
}
59