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