| Conditions | 3 |
| Paths | 3 |
| Total Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function handle(string $identifier, QuotaPolicy $quotaPolicy): Status |
||
| 25 | { |
||
| 26 | $key = $this->key($identifier, $quotaPolicy->getInterval()); |
||
| 27 | 9 | ||
| 28 | $current = (int) $this->redis->get($key); |
||
| 29 | 9 | ||
| 30 | if ($current <= $quotaPolicy->getQuota()) { |
||
| 31 | 9 | $this->redis->incr($key); |
|
| 32 | 9 | ||
| 33 | if ($current === 1) { |
||
| 34 | 4 | $this->redis->expire($key, $quotaPolicy->getInterval()); |
|
| 35 | } |
||
| 36 | 4 | } |
|
| 37 | |||
| 38 | 4 | return Status::from( |
|
| 39 | 4 | $identifier, |
|
| 40 | $current, |
||
| 41 | $quotaPolicy, |
||
| 42 | 3 | (new DateTimeImmutable())->modify('+' . $this->ttl($key) . ' seconds') |
|
| 43 | ); |
||
| 44 | } |
||
| 45 | 4 | ||
| 56 |