ArrayStore::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 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