| Total Complexity | 12 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | trait TExpiration |
||
| 16 | { |
||
| 17 | /** @var int */ |
||
| 18 | protected $changeInterval = 31536000; // 60×60×24×365 - one year |
||
| 19 | /** @var int */ |
||
| 20 | protected $changeNotice = 2592000; // 60×60×24×30 - one month |
||
| 21 | |||
| 22 | 1 | protected function initExpiry(int $changeInterval, int $changeNoticeBefore): void |
|
| 23 | { |
||
| 24 | 1 | $this->changeInterval = $changeInterval; |
|
| 25 | 1 | $this->changeNotice = $changeNoticeBefore; |
|
| 26 | 1 | } |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @param object|int|string $class |
||
| 30 | * @param int $nextChange |
||
| 31 | * @throws AuthException |
||
| 32 | */ |
||
| 33 | 5 | public function setExpirationNotice($class, int $nextChange): void |
|
| 34 | { |
||
| 35 | 5 | if ($class && is_object($class) && $class instanceof IExpire) { |
|
| 36 | 1 | $class->setExpireNotice( $this->shallExpire($nextChange)); |
|
| 37 | } |
||
| 38 | 5 | } |
|
| 39 | |||
| 40 | 1 | protected function shallExpire(int $nextChange): bool |
|
| 41 | { |
||
| 42 | 1 | return $this->getTime() + $this->changeNotice > $nextChange; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param object|int|string $class |
||
| 47 | * @throws AuthException |
||
| 48 | */ |
||
| 49 | 1 | public function updateExpirationTime($class): void |
|
| 53 | } |
||
| 54 | 1 | } |
|
| 55 | |||
| 56 | 4 | protected function whenItExpire(): int |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return int |
||
| 63 | * @codeCoverageIgnore too dynamic |
||
| 64 | */ |
||
| 65 | 3 | protected function getTime(): int |
|
| 70 |