Total Complexity | 6 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
8 | final class Msgpack implements CacheInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var CacheInterface |
||
12 | */ |
||
13 | private $cache; |
||
14 | |||
15 | /** |
||
16 | * @param CacheInterface $cache |
||
17 | */ |
||
18 | 4 | public function __construct(CacheInterface $cache) |
|
21 | 4 | } |
|
22 | |||
23 | /** |
||
24 | * @param $key |
||
25 | * @param null $default |
||
|
|||
26 | * @return PromiseInterface |
||
27 | */ |
||
28 | public function get($key, $default = null) |
||
29 | { |
||
30 | 2 | return $this->cache->get($key, $default)->then(function ($result) use ($default) { |
|
31 | 2 | if ($result === null || $result === $default) { |
|
32 | 1 | return $result; |
|
33 | } |
||
34 | |||
35 | 1 | return msgpack_unpack($result); |
|
36 | 2 | }); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param string $key |
||
41 | * @param mixed $value |
||
42 | * @param null $ttl |
||
43 | * @return PromiseInterface |
||
44 | */ |
||
45 | 1 | public function set($key, $value, $ttl = null) |
|
46 | { |
||
47 | 1 | return $this->cache->set($key, msgpack_pack($value), $ttl); |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param string $key |
||
52 | * @return PromiseInterface |
||
53 | */ |
||
54 | 1 | public function delete($key) |
|
57 | } |
||
58 | } |
||
59 |