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