ArrayBackend   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 67
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 7 2
A save() 0 4 1
A has() 0 4 1
A remove() 0 4 1
A clear() 0 4 1
1
<?php
2
3
namespace Flying\Struct\Storage;
4
5
/**
6
 * Structures storage backend using plain array
7
 */
8
class ArrayBackend implements BackendInterface
9
{
10
    /**
11
     * Storage contents
12
     *
13
     * @var array
14
     */
15
    private $storage = [];
16
17
    /**
18
     * Load information by given key from storage
19
     *
20
     * @param string $key
21
     * @return mixed
22
     */
23 4
    public function load($key)
24
    {
25 4
        if (array_key_exists($key, $this->storage)) {
26 4
            return $this->storage[$key];
27
        }
28 1
        return null;
29
    }
30
31
    /**
32
     * Save given contents into storage
33
     *
34
     * @param string $key
35
     * @param mixed $contents
36
     * @return void
37
     */
38 7
    public function save($key, $contents)
39
    {
40 7
        $this->storage[$key] = $contents;
41 7
    }
42
43
    /**
44
     * Check if storage has an entry with given key
45
     *
46
     * @param string $key
47
     * @return boolean
48
     */
49 81
    public function has($key)
50
    {
51 81
        return array_key_exists($key, $this->storage);
52
    }
53
54
    /**
55
     * Remove storage entry with given key
56
     *
57
     * @param string $key
58
     * @return void
59
     */
60 2
    public function remove($key)
61
    {
62 2
        unset($this->storage[$key]);
63 2
    }
64
65
    /**
66
     * Clear storage contents
67
     *
68
     * @return void
69
     */
70 1
    public function clear()
71
    {
72 1
        $this->storage = [];
73 1
    }
74
}
75