Total Complexity | 10 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | trait HasExpiration |
||
10 | { |
||
11 | 9 | public function initializeHasExpiration() |
|
15 | } |
||
16 | } |
||
17 | |||
18 | 9 | public function expirationKeyName(): string |
|
19 | { |
||
20 | 9 | return property_exists($this, 'expirationKeyName') ? $this->expirationKeyName : 'expire_at'; |
|
21 | } |
||
22 | |||
23 | 3 | public function expiresAt(): ?\DateTimeInterface |
|
26 | } |
||
27 | |||
28 | 3 | public function expired(): bool |
|
29 | { |
||
30 | 3 | return $this->willBeExpiredAt(Carbon::now()); |
|
31 | } |
||
32 | |||
33 | 3 | public function willBeExpiredAt(\DateTimeInterface $dateTime): bool |
|
34 | { |
||
35 | 3 | $expiresAt = $this->expiresAt(); |
|
36 | 3 | if (is_null($expiresAt)) { |
|
37 | 1 | return false; |
|
38 | } |
||
39 | |||
40 | 2 | return Carbon::instance($dateTime)->greaterThan($expiresAt); |
|
41 | } |
||
42 | |||
43 | 1 | public function scopeExpired(Builder $query): void |
|
46 | } |
||
47 | |||
48 | 6 | public function scopeWillBeExpiredAt(Builder $query, \DateTimeInterface $dateTime): void |
|
53 | 6 | }); |
|
54 | } |
||
56 |