| 1 | <?php |
||
| 9 | class Status |
||
| 10 | { |
||
| 11 | /** @var string */ |
||
| 12 | protected $identifier; |
||
| 13 | |||
| 14 | /** @var bool */ |
||
| 15 | protected $success; |
||
| 16 | |||
| 17 | /** @var int */ |
||
| 18 | protected $limit; |
||
| 19 | |||
| 20 | /** @var int */ |
||
| 21 | protected $remainingAttempts; |
||
| 22 | |||
| 23 | /** @var DateTimeImmutable */ |
||
| 24 | protected $resetAt; |
||
| 25 | |||
| 26 | 7 | final protected function __construct(string $identifier, bool $success, int $limit, int $remainingAttempts, DateTimeImmutable $resetAt) |
|
| 27 | { |
||
| 28 | 7 | $this->identifier = $identifier; |
|
| 29 | 7 | $this->success = $success; |
|
| 30 | 7 | $this->limit = $limit; |
|
| 31 | 7 | $this->remainingAttempts = $remainingAttempts; |
|
| 32 | 7 | $this->resetAt = $resetAt; |
|
| 33 | 7 | } |
|
| 34 | |||
| 35 | 7 | public static function from(string $identifier, int $current, int $limit, DateTimeImmutable $resetAt) |
|
| 36 | { |
||
| 37 | 7 | return new static($identifier, $current <= $limit, $limit, max(0, $limit - $current), $resetAt); |
|
| 38 | } |
||
| 39 | |||
| 40 | public function getIdentifier(): string |
||
| 41 | { |
||
| 42 | return $this->identifier; |
||
| 43 | } |
||
| 44 | |||
| 45 | 7 | public function limitExceeded(): bool |
|
| 49 | |||
| 50 | 4 | public function getLimit(): int |
|
| 54 | |||
| 55 | 7 | public function getRemainingAttempts(): int |
|
| 59 | |||
| 60 | 4 | public function getResetAt(): DateTimeImmutable |
|
| 64 | } |
||
| 65 |