Passed
Push — master ( 81ac1b...8d070d )
by Alexander
07:32
created

FakeCounter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 4
1
<?php
2
3
namespace Yiisoft\Yii\RateLimiter\Tests;
4
5
use Yiisoft\Yii\RateLimiter\CounterInterface;
6
use Yiisoft\Yii\RateLimiter\CounterState;
7
8
final class FakeCounter implements CounterInterface
9
{
10
    private int $remaining;
11
    private int $limit;
12
    private int $reset;
13
    private string $id;
14
15
    public function __construct(int $limit, int $reset)
16
    {
17
        $this->reset = $reset;
18
        $this->limit = $limit;
19
        $this->remaining = $limit;
20
    }
21
22
    public function setId(string $id): void
23
    {
24
        $this->id = $id;
25
    }
26
27
    public function getId(): ?string
28
    {
29
        return $this->id;
30
    }
31
32
    public function incrementAndGetState(): CounterState
33
    {
34
        $this->remaining--;
35
        return new CounterState($this->limit, $this->remaining, $this->reset);
36
    }
37
}
38