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

BoostingQuery::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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