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