Completed
Push — master ( e2bfdc...14e5c8 )
by Kevin
02:19
created

VolatileRuntimeStorage::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Kevinrob\GuzzleCache\Storage;
4
5
use Kevinrob\GuzzleCache\CacheEntry;
6
7
/**
8
 * This cache class is backed by a PHP Array.
9
 */
10
class VolatileRuntimeStorage implements CacheStorageInterface
11
{
12
13
    /**
14
     * @var CacheEntry[]
15
     */
16
    protected $cache = [];
17
18
    /**
19
     * @param string $key
20
     *
21
     * @return CacheEntry|null the data or false
22
     */
23 39
    public function fetch($key)
24
    {
25 39
        if (isset($this->cache[$key])) {
26 34
            return $this->cache[$key];
27
        }
28
29 39
        return;
30
    }
31
32
    /**
33
     * @param string $key
34
     * @param CacheEntry $data
35
     *
36
     * @return bool
37
     */
38 35
    public function save($key, CacheEntry $data)
39
    {
40 35
        $this->cache[$key] = $data;
41
42 35
        return true;
43
    }
44
45
    /**
46
     * @param string $key
47
     *
48
     * @return bool
49
     */
50 2
    public function delete($key)
51
    {
52 2
        if (true === array_key_exists($key, $this->cache)) {
53 2
            unset($this->cache[$key]);
54
55 2
            return true;
56
        }
57
58
        return false;
59
    }
60
}
61