Total Complexity | 6 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
8 | final class Counter |
||
9 | { |
||
10 | private int $hits; |
||
11 | private int $resetsAt; |
||
12 | |||
13 | 117 | public function __construct(int $hits, int $resetsAt) |
|
14 | { |
||
15 | 117 | $this->hits = $hits; |
|
16 | 117 | $this->resetsAt = $resetsAt; |
|
17 | 117 | } |
|
18 | |||
19 | 114 | public function hits(): int |
|
22 | } |
||
23 | |||
24 | 37 | public function resetsAt(): int |
|
25 | { |
||
26 | 37 | $currentTime = time(); |
|
27 | |||
28 | 37 | return $this->resetsAt < $currentTime ? $currentTime : $this->resetsAt; |
|
29 | } |
||
30 | |||
31 | 108 | public function resetsIn(): int |
|
32 | { |
||
33 | 108 | return \max(0, $this->resetsAt - time()); |
|
34 | } |
||
35 | |||
36 | 42 | public function addHit(): self |
|
42 | } |
||
43 | } |
||
44 |