| Total Complexity | 12 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | final class ArrayStorage implements ThrottleStorageInterface |
||
| 6 | { |
||
| 7 | private int $currentRequests = 0; |
||
| 8 | |||
| 9 | private float|null $startedAt = null; |
||
| 10 | |||
| 11 | public function __construct( |
||
| 12 | private int $maxRequests, |
||
| 13 | private float $timeWindow |
||
| 14 | ) { |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @inheritDoc |
||
| 19 | */ |
||
| 20 | public function getRemainingCalls(): int |
||
| 21 | { |
||
| 22 | return \max(0, ($this->maxRequests - $this->currentRequests)); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @inheritDoc |
||
| 27 | */ |
||
| 28 | public function getRemainingTime(): float |
||
| 29 | { |
||
| 30 | if (null === $this->startedAt) { |
||
| 31 | return 0; |
||
| 32 | } |
||
| 33 | |||
| 34 | return \max(0, ($this->startedAt + $this->timeWindow) - \microtime(true)); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @inheritDoc |
||
| 39 | */ |
||
| 40 | public function increment(): void |
||
| 51 | } |
||
| 52 | |||
| 53 | public function decrement(): void |
||
| 54 | { |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | |||
| 62 | private function reset(): void |
||
| 63 | { |
||
| 64 | $this->currentRequests = 0; |
||
| 65 | $this->startedAt = null; |
||
| 66 | } |
||
| 67 | |||
| 68 | private function isExpired(): bool |
||
| 75 | } |
||
| 76 | } |
||
| 77 |