Completed
Pull Request — develop (#17)
by Sam
04:04
created

BoostableQuery::hasBoost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Search\Query\TermLevel;
4
5
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
6
7
/**
8
 * Trait BoostableQuery
9
 * @package Nord\Lumen\Elasticsearch\Search\Query\TermLevel
10
 */
11
trait BoostableQuery
12
{
13
14
    /**
15
     * @var float Sets the boost value of the query, defaults to 1.0.
16
     */
17
    protected $boost;
18
19
    /**
20
     * @return float
21
     */
22
    public function getBoost()
23
    {
24
        return $this->boost;
25
    }
26
27
    /**
28
     * @param float $boost
29
     *
30
     * @return $this
31
     *
32
     * @throws InvalidArgument
33
     */
34
    public function setBoost($boost)
35
    {
36
        $this->assertBoost($boost);
37
        $this->boost = $boost;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    public function hasBoost()
46
    {
47
        return $this->boost !== null;
48
    }
49
50
    /**
51
     * @param float $boost
52
     *
53
     * @throws InvalidArgument
54
     */
55
    protected function assertBoost($boost)
56
    {
57
        if (!is_float($boost)) {
58
            throw new InvalidArgument(sprintf(
59
                '`boost` must be a float value, "%s" given.',
60
                gettype($boost)
61
            ));
62
        }
63
    }
64
}
65