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

EventIndicator::event()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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