Test Failed
Push — master ( af1a14...381874 )
by Dan
02:05
created

Cache::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Ds\Cache;
4
5
/**
6
 * Class Cache
7
 * @package Ds\Cache
8
 */
9
class Cache implements CacheInterface
10
{
11
    /**
12
     * @var CacheStorageInterface
13
     */
14
    protected $cache;
15
16
    /**
17
     * Create new instance with $CacheStorage
18
     *
19
     * @param  CacheStorageInterface $cacheStorage
20
     * @return CacheInterface
21
     */
22 1
    public function withCacheStorage(CacheStorageInterface $cacheStorage)
23
    {
24 1
        $new = clone $this;
25 1
        $new->cache = $cacheStorage;
26 1
        return $new;
27
    }
28
29
    /**
30
     * Get Cache Storage
31
     *
32
     * @return CacheStorageInterface
33
     */
34 3
    public function getCacheStorage()
35
    {
36 3
        return $this->cache;
37
    }
38
39
    /**
40
     * Cache constructor.
41
     *
42
     * @param CacheStorageInterface|null $cacheStorage
43
     */
44 7
    public function __construct(CacheStorageInterface $cacheStorage = null)
45
    {
46 7
        $this->cache = $cacheStorage;
47
48 7
        if ($cacheStorage === null) {
49 1
            $this->cache = new NullStorage();
50
        }
51 7
    }
52
53
    /**
54
     * Check if cache key exists.
55
     *
56
     * @param  $key
57
     * @return bool
58
     */
59 1
    public function has($key)
60
    {
61 1
        return $this->cache->has($key);
62
    }
63
64
    /**
65
     * Save Cache Value.
66
     *
67
     * @param  string $key
68
     * @param  mixed  $value
69
     * @param  int    $expires
70
     * @return void
71
     */
72 1
    public function set($key, $value, $expires)
73
    {
74 1
        return $this->cache->set($key, $value, $expires);
75
    }
76
77
    /**
78
     * Get Cache Value from key.
79
     *
80
     * @param  string $key
81
     * @return mixed
82
     */
83 1
    public function get($key = '')
84
    {
85 1
        return $this->cache->get($key);
86
    }
87
88
    /**
89
     * Delete Cache Key.
90
     *
91
     * @param $key
92
     */
93 1
    public function delete($key)
94
    {
95 1
        $this->cache->delete($key);
96 1
    }
97
}
98