Passed
Push — master ( 0db423...f9fe2f )
by Paweł
03:15
created

CacheStorage::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 17.03.2018
6
 */
7
8
namespace app\components\http;
9
10
11
use Kevinrob\GuzzleCache\CacheEntry;
12
use Kevinrob\GuzzleCache\Storage\CacheStorageInterface;
13
use yii\caching\Cache;
14
use yii\di\Instance;
15
16
class CacheStorage implements CacheStorageInterface
17
{
18
19
    public $cache;
20
21
    /**
22
     * YiiCacheStorage constructor.
23
     *
24
     * @param mixed $cache Cache component.
25
     */
26
    public function __construct($cache = 'cache')
27
    {
28
        $this->cache = $cache;
29
    }
30
31
    public function fetch($key)
32
    {
33
        /** @var \yii\caching\Cache $cache */
34
        $cache = Instance::ensure($this->cache, Cache::class);
35
36
        return $cache->get($key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $cache->get($key) also could return the type false which is incompatible with the return type mandated by Kevinrob\GuzzleCache\Sto...orageInterface::fetch() of null|Kevinrob\GuzzleCache\CacheEntry.
Loading history...
37
    }
38
39
    public function save($key, CacheEntry $data)
40
    {
41
        /** @var \yii\caching\Cache $cache */
42
        $cache = Instance::ensure($this->cache, Cache::class);
43
44
        return $cache->set($key, $data);
45
    }
46
47
    public function delete($key)
48
    {
49
        /** @var \yii\caching\Cache $cache */
50
        $cache = Instance::ensure($this->cache, Cache::class);
51
52
        return $cache->delete($key);
53
    }
54
}