Passed
Push — master ( 93c262...ab8fda )
by Alec
02:30
created

EventIndicator::isNotOk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * User: alec
4
 * Date: 16.11.18
5
 * Time: 13:41
6
 */
7
8
namespace AlecRabbit\Event;
9
10
class EventIndicator
11
{
12
    public const THRESHOLD = SECONDS_IN_01MIN;
13
14
    /** @var int */
15
    private $lastEventTimestamp;
16
    /** @var int */
17
    private $threshold;
18
19
    /**
20
     * EventIndicator constructor.
21
     * @param int|null $threshold
22
     */
23 9
    public function __construct(? int $threshold = null)
24
    {
25 9
        $this->countEvent();
26 9
        $this->threshold = $threshold ?? static::THRESHOLD;
27 9
    }
28
29 9
    public function countEvent($event = null)
30
    {
31 9
        $this->lastEventTimestamp = $this->current();
32 9
        return $event;
33
    }
34
35
    /**
36
     * @return int
37
     */
38 9
    private function current(): int
39
    {
40 9
        return time();
41
    }
42
43
    /**
44
     * @return bool
45
     */
46 2
    public function isNotOk(): bool
47
    {
48
        return
49 2
            !$this->isOk();
50
    }
51
52
    /**
53
     * @return bool
54
     */
55 2
    public function isOk(): bool
56
    {
57
        return
58 2
            $this->current() - $this->lastEventTimestamp <= $this->threshold;
59
    }
60
}
61