Counter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 12
c 1
b 0
f 1
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hits() 0 3 1
A addHit() 0 6 1
A resetsAt() 0 5 2
A resetsIn() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace Zenstruck\Governator;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
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
20
    {
21 114
        return $this->hits;
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
37
    {
38 42
        $clone = clone $this;
39 42
        ++$clone->hits;
40
41 42
        return $clone;
42
    }
43
}
44