| Conditions | 3 |
| Paths | 3 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 4 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | public function handle(string $identifier, QuotaPolicy $quotaPolicy): Status |
||
| 15 | { |
||
| 16 | $key = "$identifier:{$quotaPolicy->getInterval()}:" . floor(time() / $quotaPolicy->getInterval()); |
||
| 17 | |||
| 18 | if (!isset($this->store[$key])) { |
||
| 19 | $this->store[$key] = [ |
||
| 20 | 'current' => 1, |
||
| 21 | 'expires' => time() + $quotaPolicy->getInterval(), |
||
| 22 | ]; |
||
| 23 | } elseif ($this->store[$key]['current'] <= $quotaPolicy->getQuota()) { |
||
| 24 | $this->store[$key]['current']++; |
||
| 25 | 10 | } |
|
| 26 | |||
| 27 | return Status::from( |
||
| 28 | 10 | $identifier, |
|
| 29 | 10 | $this->store[$key]['current'], |
|
| 30 | $quotaPolicy, |
||
| 31 | 10 | new DateTimeImmutable('@' . $this->store[$key]['expires']) |
|
| 32 | ); |
||
| 33 | } |
||
| 34 | } |
||
| 35 |