Total Complexity | 9 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Coverage | 94.12% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | trait ClientTrait |
||
19 | { |
||
20 | /** @var int|null Global TTL for caching, used as default expiration time in cache clients */ |
||
21 | private $ttl; |
||
22 | |||
23 | /** @var \Memcached | \Redis | \Predis\Client | \Koded\Caching\Client\FileClient | \Koded\Caching\Client\MemoryClient | \Koded\Caching\Client\ShmopClient */ |
||
24 | private $client; |
||
25 | |||
26 | 2 | public function getTtl(): ?int |
|
27 | { |
||
28 | 2 | return $this->ttl; |
|
29 | } |
||
30 | |||
31 | 11 | public function client() |
|
32 | { |
||
33 | 11 | return $this->client ?? $this; |
|
34 | } |
||
35 | |||
36 | 175 | private function timestampWithGlobalTtl($ttl, int $default = 0): int |
|
37 | { |
||
38 | 175 | $explicit = normalize_ttl($ttl); |
|
39 | 145 | $now = now()->getTimestamp(); |
|
40 | |||
41 | 145 | if (null === $explicit && $this->ttl > 0) { |
|
|
|||
42 | 2 | return $now + $this->ttl; |
|
43 | } |
||
44 | |||
45 | 144 | if ($explicit > 0) { |
|
46 | 8 | return $now + $explicit; |
|
47 | } |
||
48 | |||
49 | 136 | return $explicit ?? $default; |
|
50 | } |
||
51 | |||
52 | 280 | private function secondsWithGlobalTtl($ttl): int |
|
61 | } |
||
62 | } |