Test Failed
Pull Request — master (#43)
by
unknown
02:14
created

CounterState   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getLimit() 0 3 1
A getResetTime() 0 3 1
A isLimitReached() 0 3 1
A isExceedingMaxAttempts() 0 3 1
A __construct() 0 6 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
     * @param bool $isExceedingMaxAttempts If fail to store updated the rate limit data after maximum attempts.
17 9
     */
18
    public function __construct(
19 9
        private int $limit, 
20
        private int $remaining, 
21
        private int $resetTime,
22
        private bool $isExceedingMaxAttempts = false
23
    ) {
24 7
    }
25
26 7
    /**
27
     * @return int The maximum number of requests allowed with a time period.
28
     */
29
    public function getLimit(): int
30
    {
31
        return $this->limit;
32 8
    }
33
34 8
    /**
35
     * @return int The number of remaining requests in the current time period.
36
     */
37
    public function getRemaining(): int
38
    {
39
        return $this->remaining;
40 7
    }
41
42 7
    /**
43
     * @return int Timestamp to wait until the rate limit resets.
44
     */
45
    public function getResetTime(): int
46
    {
47
        return $this->resetTime;
48 7
    }
49
50 7
    /**
51
     * @return bool If requests limit is reached.
52
     */
53
    public function isLimitReached(): bool
54
    {
55
        return $this->remaining === 0;
56
    }
57
58
    /**
59
     * @return bool If fail to store updated the rate limit data after maximum attempts.
60
     */
61
    public function isExceedingMaxAttempts(): bool
62
    {
63
        return $this->isExceedingMaxAttempts;
64
    }
65
}
66