| Total Complexity | 9 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 16 | trait TExpire |
||
| 17 | { |
||
| 18 | protected ?int $expire = null; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param object|DateTimeInterface|int|null $expiration |
||
| 22 | * @return $this |
||
| 23 | */ |
||
| 24 | 3 | public function expiresAt($expiration) |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param object|DateInterval|int|null $time |
||
| 38 | * @throws Exception |
||
| 39 | * @return $this |
||
| 40 | */ |
||
| 41 | 1 | public function expiresAfter($time) |
|
| 42 | { |
||
| 43 | 1 | $when = null; |
|
| 44 | 1 | if (is_object($time) && ($time instanceof DateInterval)) { |
|
| 45 | 1 | $expiration = new \DateTime(); |
|
| 46 | 1 | $when = $expiration->add($time)->getTimestamp(); |
|
| 47 | 1 | } elseif (is_int($time)) { |
|
| 48 | 1 | $when = time() + $time; |
|
| 49 | } |
||
| 50 | 1 | $this->expire = $when; |
|
| 51 | 1 | return $this; |
|
| 52 | } |
||
| 53 | |||
| 54 | 7 | public function getExpire(): ?int |
|
| 57 | } |
||
| 58 | } |
||
| 59 |