CounterState::getLimit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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