CountBetween::shouldRun()   B
last analyzed

Complexity

Conditions 7
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 5
nc 3
nop 1
crap 7
1
<?php
2
namespace pmill\RabbitRabbit\Conditions;
3
4
class CountBetween implements ConditionInterface
5
{
6
    /**
7
     * @var int
8
     */
9
    protected $from;
10
11
    /**
12
     * @var int
13
     */
14
    protected $to;
15
16
    /**
17
     * @var bool
18
     */
19
    protected $inclusive = false;
20
21
    /**
22
     * CountBetween constructor.
23
     *
24
     * @param int $from
25
     * @param int $to
26
     * @param bool $inclusive
27
     */
28 7
    public function __construct(int $from, int $to, bool $inclusive = false)
29
    {
30 7
        $this->from = $from;
31 7
        $this->to = $to;
32 7
        $this->inclusive = $inclusive;
33 7
    }
34
35
    /**
36
     * @param int $value
37
     *
38
     * @return bool
39
     */
40 7
    public function shouldRun($value)
41
    {
42 7
        if ($this->inclusive && $value >= $this->from && $value <= $this->to) {
43 2
            return true;
44
        }
45
46 5
        if (!$this->inclusive && $value > $this->from && $value < $this->to) {
47 1
            return true;
48
        }
49
50 4
        return false;
51
    }
52
}
53