Passed
Push — master ( de2315...d20eef )
by Alec
02:19
created

EventIndicator::countEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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
17
    /**
18
     * EventIndicator constructor.
19
     */
20
    public function __construct()
21
    {
22
        $this->countEvent();
23
    }
24
25
    public function countEvent($event = null)
26
    {
27
        $this->lastEventTimestamp = $this->current();
28
        if (null !== $event) {
29
            return $event;
30
        }
31
    }
32
33
    /**
34
     * @return int
35
     */
36
    private function current(): int
37
    {
38
        return time();
39
    }
40
41
    /**
42
     * @return bool
43
     */
44
    public function isOk(): bool
45
    {
46
        return
47
            $this->current() - $this->lastEventTimestamp >= static::THRESHOLD;
48
    }
49
}
50