| Total Complexity | 8 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | final class RateLimits |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * The API rate limits to respect. |
||
| 16 | * |
||
| 17 | * @var RateLimit[] |
||
| 18 | */ |
||
| 19 | private array $rateLimits = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Add the given rate limit. |
||
| 23 | */ |
||
| 24 | 1 | public function add(int $requests, int $perSeconds): self |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Hit the rate limits with a request. |
||
| 33 | */ |
||
| 34 | 1 | public function hit(): self |
|
| 35 | { |
||
| 36 | 1 | foreach ($this->rateLimits as $rateLimit) { |
|
| 37 | 1 | $rateLimit->hit(); |
|
| 38 | } |
||
| 39 | |||
| 40 | 1 | return $this; |
|
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Retrieve the number of requests allowed before the next rate limit. |
||
| 45 | */ |
||
| 46 | 1 | public function threshold(): int |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Retrieve the timestamp after which it is possible to send new requests. |
||
| 59 | */ |
||
| 60 | 1 | public function resetAt(): float |
|
| 73 | } |
||
| 74 | } |
||
| 75 |