Completed
Pull Request — master (#39)
by Jérôme
02:40
created

VolatileRuntimeStorage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 8 2
A save() 0 6 1
A delete() 0 6 1
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
    public function fetch($key)
24
    {
25
        if (isset($this->cache[$key])) {
26
            return $this->cache[$key];
27
        }
28
29
        return;
30
    }
31
32
    /**
33
     * @param string $key
34
     * @param CacheEntry $data
35
     *
36
     * @return bool
37
     */
38
    public function save($key, CacheEntry $data)
39
    {
40
        $this->cache[$key] = $data;
41
42
        return true;
43
    }
44
45
    public function delete($key)
46
    {
47
        unset($this->cache[$key]);
48
49
        return true;
50
    }
51
}
52