Passed
Pull Request — master (#204)
by
unknown
01:59
created

CounterStatistics::isLimitReached()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Web\RateLimiter;
6
7
/**
8
 * Rate limiter counter statistics
9
 */
10
final class CounterStatistics
11
{
12
    private int $limit;
13
    private int $remaining;
14
    private int $reset;
15
16
    /**
17
     * @param int $limit the maximum number of requests allowed with a time period
18
     * @param int $remaining the number of remaining requests in the current time period
19
     * @param int $reset timestamp to wait until the rate limit resets
20
     */
21
    public function __construct(int $limit, int $remaining, int $reset)
22
    {
23
        $this->limit = $limit;
24
        $this->remaining = $remaining;
25
        $this->reset = $reset;
26
    }
27
28
    /**
29
     * @return int the maximum number of requests allowed with a time period
30
     */
31
    public function getLimit(): int
32
    {
33
        return $this->limit;
34
    }
35
36
    /**
37
     * @return int the number of remaining requests in the current time period
38
     */
39
    public function getRemaining(): int
40
    {
41
        return $this->remaining;
42
    }
43
44
    /**
45
     * @return int timestamp to wait until the rate limit resets
46
     */
47
    public function getResetTime(): int
48
    {
49
        return $this->reset;
50
    }
51
52
    /**
53
     * @return bool if requests limit is reached
54
     */
55
    public function isLimitReached(): bool
56
    {
57
        return $this->remaining === 0;
58
    }
59
}
60