EventIndicator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 49
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

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