| Total Complexity | 5 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | class Timeout implements ITimeout |
||
| 16 | { |
||
| 17 | public const CAPTCHA_TIME = 'captchaTime'; |
||
| 18 | |||
| 19 | protected ArrayAccess $session; |
||
| 20 | /** @var int When ends time of pass */ |
||
| 21 | protected int $time = 0; |
||
| 22 | /** @var int How log interval is preset after correct response */ |
||
| 23 | protected int $timeout = 0; |
||
| 24 | |||
| 25 | 1 | public function __construct(ArrayAccess &$session, int $timeout = 0) |
|
| 32 | 1 | } |
|
| 33 | |||
| 34 | 1 | public function updateExpire(): void |
|
| 35 | { |
||
| 36 | 1 | $this->time = time() + $this->timeout; // when it begins |
|
| 37 | 1 | $this->session->offsetSet(static::CAPTCHA_TIME, $this->time); // set into session |
|
| 38 | 1 | } |
|
| 39 | |||
| 40 | 1 | public function isRunning(): bool |
|
| 41 | { |
||
| 42 | 1 | return (0 < $this->timeLeft()); |
|
| 43 | } |
||
| 44 | |||
| 45 | 1 | public function timeLeft(): int |
|
| 48 | } |
||
| 49 | } |
||
| 50 |