Passed
Push — develop ( f2149c...9e9b3a )
by Sam
01:50 queued 17s
created

HasTieBreaker::assertTieBreaker()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Nord\Lumen\Elasticsearch\Search\Traits;
4
5
use Nord\Lumen\Elasticsearch\Exceptions\InvalidArgument;
6
7
/**
8
 * Trait HasTieBreaker
9
 * @package Nord\Lumen\Elasticsearch\Search\Traits
10
 */
11
trait HasTieBreaker
12
{
13
14
    /**
15
     * @var float
16
     */
17
    protected $tieBreaker;
18
19
    /**
20
     * @param float $tieBreaker
21
     *
22
     * @return $this
23
     *
24
     * @throws InvalidArgument
25
     */
26
    public function setTieBreaker($tieBreaker)
27
    {
28
        $this->assertTieBreaker($tieBreaker);
29
        $this->tieBreaker = $tieBreaker;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @return float
36
     */
37
    public function getTieBreaker()
38
    {
39
        return $this->tieBreaker;
40
    }
41
42
    /**
43
     * @param float $tieBreaker
44
     *
45
     * @throws InvalidArgument
46
     */
47
    protected function assertTieBreaker($tieBreaker)
48
    {
49
        if (!is_float($tieBreaker)) {
0 ignored issues
show
introduced by
The condition is_float($tieBreaker) is always true.
Loading history...
50
            throw new InvalidArgument(sprintf(
51
                'MultiMatch Query `tie_breaker` must be a float value, "%s" given.',
52
                gettype($tieBreaker)
53
            ));
54
        }
55
    }
56
}
57