Base   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 112
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
clear() 0 1 ?
delete() 0 1 ?
A info() 0 8 1
keys() 0 1 ?
load() 0 1 ?
A loadArray() 0 12 2
A log() 0 10 2
save() 0 1 ?
1
<?php
2
3
/**
4
 * Provides caching functionality
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Cache
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\cache;
17
18
/**
19
 * Provides caching functionality
20
 *
21
 * @category  Core
22
 * @package   Cache
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
abstract class Base extends \csphere\core\service\Drivers
30
{
31
    /**
32
     * Stores the logger object
33
     **/
34
    protected $logger = null;
35
36
    /**
37
     * Clears the cache content
38
     *
39
     * @return boolean
40
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
41
42
    abstract public function clear();
43
44
    /**
45
     * Removes a cached key
46
     *
47
     * @param string $key Name of the key
48
     * @param int    $ttl Time to life used for the key
49
     *
50
     * @return boolean
51
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
52
53
    abstract public function delete($key, $ttl = 0);
54
55
    /**
56
     * Returns a formatted array with statistics
57
     *
58
     * @return array
59
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
60
61
    public function info()
62
    {
63
        $info = $this->config;
64
65
        unset($info['password'], $info['timeout']);
66
67
        return $info;
68
    }
69
70
    /**
71
     * Returns a formatted array with all keys and additional information
72
     *
73
     * @return array
74
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
75
76
    abstract public function keys();
77
78
    /**
79
     * Fetches the desired key
80
     *
81
     * @param string $key Name of the key
82
     * @param int    $ttl Time to life used for the key
83
     *
84
     * @return array
85
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
86
87
    abstract public function load($key, $ttl = 0);
88
89
    /**
90
     * Fetches the desired keys
91
     *
92
     * @param array $keys Name of the keys
93
     *
94
     * @return array
95
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
96
97
    public function loadArray(array $keys)
98
    {
99
        $result = [];
100
101
        // Run through all keys
102
        foreach ($keys AS $key) {
103
104
            $result[$key] = $this->load($key);
105
        }
106
107
        return $result;
108
    }
109
110
    /**
111
     * Logs cache inserts
112
     *
113
     * @param string $key The cache key that is stored
114
     *
115
     * @return void
116
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
117
118
    protected function log($key)
119
    {
120
        // Get logger if not done yet
121
        if ($this->logger == null) {
122
123
            $this->logger = $this->loader->load('logs');
124
        }
125
126
        $this->logger->log('cache', $key);
127
    }
128
129
    /**
130
     * Stores the key with its value in the cache
131
     *
132
     * @param string $key   Name of the key
133
     * @param array  $value Content to be stored
134
     * @param int    $ttl   Time to life used for the key
135
     *
136
     * @return boolean
137
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
138
139
    abstract public function save($key, $value, $ttl = 0);
140
}
141