CounterState   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 5
c 1
b 0
f 0
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getLimit() 0 3 1
A getResetTime() 0 3 1
A isLimitReached() 0 3 1
A __construct() 0 2 1
A getRemaining() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\RateLimiter;
6
7
/**
8
 * Rate limiter counter state stores information about when the next request won't be limited.
9
 */
10
final class CounterState
11
{
12
    /**
13
     * @param int $limit The maximum number of requests allowed with a time period.
14
     * @param int $remaining The number of remaining requests in the current time period.
15
     * @param int $resetTime Timestamp to wait until the rate limit resets.
16
     */
17 9
    public function __construct(private int $limit, private int $remaining, private int $resetTime)
18
    {
19 9
    }
20
21
    /**
22
     * @return int The maximum number of requests allowed with a time period.
23
     */
24 7
    public function getLimit(): int
25
    {
26 7
        return $this->limit;
27
    }
28
29
    /**
30
     * @return int The number of remaining requests in the current time period.
31
     */
32 8
    public function getRemaining(): int
33
    {
34 8
        return $this->remaining;
35
    }
36
37
    /**
38
     * @return int Timestamp to wait until the rate limit resets.
39
     */
40 7
    public function getResetTime(): int
41
    {
42 7
        return $this->resetTime;
43
    }
44
45
    /**
46
     * @return bool If requests limit is reached.
47
     */
48 7
    public function isLimitReached(): bool
49
    {
50 7
        return $this->remaining === 0;
51
    }
52
}
53