| Total Complexity | 6 |
| Total Lines | 54 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 |
||
| 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 |
||
| 48 | 7 | } |
|
| 49 | |||
| 50 | 7 | /** |
|
| 51 | * @return bool If requests limit is reached. |
||
| 52 | */ |
||
| 53 | public function isLimitReached(): bool |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return bool If fail to store updated the rate limit data after maximum attempts. |
||
| 60 | */ |
||
| 61 | public function isExceedingMaxAttempts(): bool |
||
| 64 | } |
||
| 65 | } |
||
| 66 |