ArrayStore   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 7
Bugs 0 Features 2
Metric Value
wmc 8
c 7
b 0
f 2
lcom 1
cbo 0
dl 0
loc 59
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 9 2
A set() 0 6 1
A get() 0 4 2
A has() 0 4 1
A delete() 0 4 1
A flush() 0 4 1
1
<?php
2
/**
3
 * Array Store
4
 *
5
 * @package SugiPHP.Cache
6
 * @author  Plamen Popov <[email protected]>
7
 * @license http://opensource.org/licenses/mit-license.php (MIT License)
8
 */
9
10
namespace SugiPHP\Cache;
11
12
/**
13
 * Array Store
14
 * Main purpose of this class is to be used in unit testing.
15
 * Note that no expiration time is implemented! Store will be flushed after the script is over.
16
 */
17
class ArrayStore implements StoreInterface
18
{
19
    protected $store = array();
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function add($key, $value, $ttl = 0)
25
    {
26
        if ($this->has($key)) {
27
            return false;
28
        }
29
        $this->store[$key] = $value;
30
31
        return true;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function set($key, $value, $ttl = 0)
38
    {
39
        $this->store[$key] = $value;
40
41
        return true;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function get($key)
48
    {
49
        return isset($this->store[$key]) ? $this->store[$key] : null;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function has($key)
56
    {
57
        return isset($this->store[$key]);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function delete($key)
64
    {
65
        unset($this->store[$key]);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function flush()
72
    {
73
        $this->store = array();
74
    }
75
}
76