| Total Complexity | 8 |
| Total Lines | 65 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class QuotaExceeded extends \RuntimeException |
||
| 11 | { |
||
| 12 | private Quota $quota; |
||
| 13 | |||
| 14 | 40 | public function __construct(Quota $quota) |
|
| 15 | { |
||
| 16 | 40 | $this->quota = $quota; |
|
| 17 | |||
| 18 | 40 | parent::__construct(\sprintf('Quota Exceeded (%d/%d), resets in %d seconds.', $quota->hits(), $quota->limit(), $quota->resetsIn())); |
|
| 19 | 40 | } |
|
| 20 | |||
| 21 | /** |
||
| 22 | * @return Quota The exceeded Quota object for the throttle |
||
| 23 | */ |
||
| 24 | 9 | public function quota(): Quota |
|
| 25 | { |
||
| 26 | 9 | return $this->quota; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @return string The throttle's unique identifier |
||
| 31 | */ |
||
| 32 | 9 | public function resource(): string |
|
| 33 | { |
||
| 34 | 9 | return $this->quota->resource(); |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return int The throttle's limit |
||
| 39 | */ |
||
| 40 | 9 | public function limit(): int |
|
| 41 | { |
||
| 42 | 9 | return $this->quota->limit(); |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return int The number of throttle hits |
||
| 47 | */ |
||
| 48 | 20 | public function hits(): int |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return int Number of allowed hits before the throttle resets (always 0) |
||
| 55 | */ |
||
| 56 | 18 | public function remaining(): int |
|
| 57 | { |
||
| 58 | 18 | return 0; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return \DateTimeImmutable When the throttle resets (never in the past) |
||
| 63 | */ |
||
| 64 | 9 | public function resetsAt(): \DateTimeImmutable |
|
| 65 | { |
||
| 66 | 9 | return $this->quota->resetsAt(); |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return int Number of seconds until the throttle resets (never negative) |
||
| 71 | */ |
||
| 72 | 38 | public function resetsIn(): int |
|
| 75 | } |
||
| 76 | } |
||
| 77 |