Test Failed
Pull Request — master (#43)
by Sergei
02:30
created

CounterState::isExceedingMaxAttempts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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