@@ -95,23 +95,23 @@ |
||
95 | 95 | */ |
96 | 96 | public function has($key){ |
97 | 97 | |
98 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
99 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
98 | + $cacheFile = implode('.',[$key,$this->ext]); |
|
99 | + $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
100 | 100 | |
101 | - if (!file_exists($cacheLocation)){ |
|
102 | - return false; |
|
103 | - } |
|
101 | + if (!file_exists($cacheLocation)){ |
|
102 | + return false; |
|
103 | + } |
|
104 | 104 | |
105 | - $data = \file_get_contents($cacheLocation); |
|
106 | - $cacheData = json_decode($data, TRUE); |
|
105 | + $data = \file_get_contents($cacheLocation); |
|
106 | + $cacheData = json_decode($data, TRUE); |
|
107 | 107 | |
108 | - //cache has expired |
|
109 | - if ($cacheData[0] < time() ){ |
|
110 | - \unlink($cacheLocation); |
|
111 | - return false; |
|
112 | - } |
|
108 | + //cache has expired |
|
109 | + if ($cacheData[0] < time() ){ |
|
110 | + \unlink($cacheLocation); |
|
111 | + return false; |
|
112 | + } |
|
113 | 113 | |
114 | - return true; |
|
114 | + return true; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct($file, DateInterval $ttl) |
40 | 40 | { |
41 | - if (!is_string($file)){ |
|
41 | + if (!is_string($file)) { |
|
42 | 42 | throw new \Exception('Directory must be a valid string'); |
43 | 43 | } |
44 | 44 | |
45 | 45 | $this->fs = $file; |
46 | 46 | |
47 | - if(!@mkdir($this->fs, 0755) && !is_dir($this->fs)){ |
|
47 | + if (!@mkdir($this->fs, 0755) && !is_dir($this->fs)) { |
|
48 | 48 | throw new \Exception('unable to create directory'); |
49 | 49 | } |
50 | 50 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | |
69 | 69 | $cacheItem = $this->_createCacheItem($key, $value, $ttl); |
70 | 70 | |
71 | - \file_put_contents($cacheItem['file'],$cacheItem['data']); |
|
71 | + \file_put_contents($cacheItem['file'], $cacheItem['data']); |
|
72 | 72 | |
73 | - if (!file_exists($cacheItem['file'])){ |
|
73 | + if (!file_exists($cacheItem['file'])) { |
|
74 | 74 | return false; |
75 | 75 | } |
76 | 76 | |
@@ -86,16 +86,16 @@ discard block |
||
86 | 86 | * @return array |
87 | 87 | * @throws \Exception |
88 | 88 | */ |
89 | - private function _createCacheItem($key, $value, $ttl){ |
|
89 | + private function _createCacheItem($key, $value, $ttl) { |
|
90 | 90 | |
91 | - if (!is_string($key)){ |
|
91 | + if (!is_string($key)) { |
|
92 | 92 | throw new \Exception('$key must be a valid string'); |
93 | 93 | } |
94 | 94 | |
95 | - $filename = implode('.',[$key,$this->ext]); |
|
95 | + $filename = implode('.', [$key, $this->ext]); |
|
96 | 96 | |
97 | 97 | return [ |
98 | - 'file' => $this->fs . DIRECTORY_SEPARATOR . $filename, |
|
98 | + 'file' => $this->fs.DIRECTORY_SEPARATOR.$filename, |
|
99 | 99 | 'data' => json_encode([$ttl, $value]) |
100 | 100 | ]; |
101 | 101 | } |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - public function has($key){ |
|
115 | + public function has($key) { |
|
116 | 116 | |
117 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
118 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
117 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
118 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
119 | 119 | |
120 | - if (!file_exists($cacheLocation)){ |
|
120 | + if (!file_exists($cacheLocation)) { |
|
121 | 121 | return false; |
122 | 122 | } |
123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $cacheData = json_decode($data, TRUE); |
126 | 126 | |
127 | 127 | //cache has expired |
128 | - if ($cacheData[0] < time() ){ |
|
128 | + if ($cacheData[0] < time()) { |
|
129 | 129 | \unlink($cacheLocation); |
130 | 130 | return false; |
131 | 131 | } |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
142 | 142 | * |
143 | 143 | */ |
144 | - public function get($key){ |
|
144 | + public function get($key) { |
|
145 | 145 | |
146 | - $cacheFile = implode('.',[$key,$this->ext]); |
|
147 | - $cacheLocation = $this->fs . DIRECTORY_SEPARATOR . $cacheFile; |
|
146 | + $cacheFile = implode('.', [$key, $this->ext]); |
|
147 | + $cacheLocation = $this->fs.DIRECTORY_SEPARATOR.$cacheFile; |
|
148 | 148 | |
149 | - if ($this->has($key)){ |
|
149 | + if ($this->has($key)) { |
|
150 | 150 | $data = \file_get_contents($cacheLocation); |
151 | 151 | $cacheData = json_decode($data, TRUE); |
152 | 152 | return $cacheData[1]; |
@@ -174,14 +174,14 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @return bool True on success and false on failure. |
176 | 176 | */ |
177 | - public function clear(){ |
|
178 | - if (is_dir( $this->fs )){ |
|
177 | + public function clear() { |
|
178 | + if (is_dir($this->fs)) { |
|
179 | 179 | array_map('unlink', glob("$this->fs/*.*")); |
180 | 180 | } |
181 | 181 | |
182 | 182 | $data = glob("$this->fs/*.*"); |
183 | 183 | |
184 | - if (!empty($data)){ |
|
184 | + if (!empty($data)) { |
|
185 | 185 | return false; |
186 | 186 | } |
187 | 187 |
@@ -28,16 +28,16 @@ |
||
28 | 28 | * @param DateInterval $ttl |
29 | 29 | * @throws CacheException |
30 | 30 | */ |
31 | - public function __construct(DateInterval $ttl) |
|
32 | - { |
|
33 | - $foundApc = \extension_loaded('apc'); |
|
31 | + public function __construct(DateInterval $ttl) |
|
32 | + { |
|
33 | + $foundApc = \extension_loaded('apc'); |
|
34 | 34 | |
35 | - if (!$foundApc){ |
|
36 | - throw new CacheException('APC Extension not found.'); |
|
37 | - } |
|
35 | + if (!$foundApc){ |
|
36 | + throw new CacheException('APC Extension not found.'); |
|
37 | + } |
|
38 | 38 | |
39 | - parent::__construct($ttl); |
|
40 | - } |
|
39 | + parent::__construct($ttl); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Determines whether an item is present in the cache. |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | $foundApc = \extension_loaded('apc'); |
34 | 34 | |
35 | - if (!$foundApc){ |
|
35 | + if (!$foundApc) { |
|
36 | 36 | throw new CacheException('APC Extension not found.'); |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return bool |
53 | 53 | */ |
54 | - public function has($key){ |
|
54 | + public function has($key) { |
|
55 | 55 | return \apc_exists($key); |
56 | 56 | } |
57 | 57 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function delete($key) |
96 | 96 | { |
97 | - if (\apc_exists($key)){ |
|
97 | + if (\apc_exists($key)) { |
|
98 | 98 | \apc_delete($key); |
99 | 99 | } |
100 | 100 | } |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return bool True on success and false on failure. |
106 | 106 | */ |
107 | - public function clear(){ |
|
107 | + public function clear() { |
|
108 | 108 | |
109 | 109 | \apc_clear_cache(); |
110 | 110 | $apcResult = $this->getInfo(); |
111 | 111 | |
112 | - if (!empty($apcResult['cache_list'])){ |
|
112 | + if (!empty($apcResult['cache_list'])) { |
|
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return array |
124 | 124 | */ |
125 | - public function getInfo(){ |
|
125 | + public function getInfo() { |
|
126 | 126 | return apc_cache_info(); |
127 | 127 | } |
128 | 128 |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param DateInterval $ttl |
42 | 42 | * @return CacheStorageInterface |
43 | 43 | */ |
44 | - public function withTtl(DateInterval $ttl){ |
|
44 | + public function withTtl(DateInterval $ttl) { |
|
45 | 45 | $new = clone $this; |
46 | 46 | $new->ttl = $ttl; |
47 | 47 | return $new; |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | * @param null|int $ttl |
54 | 54 | * @return int |
55 | 55 | */ |
56 | - public function getTtlTimestamp($ttl = null){ |
|
56 | + public function getTtlTimestamp($ttl = null) { |
|
57 | 57 | |
58 | - if (null === $ttl){ |
|
58 | + if (null === $ttl) { |
|
59 | 59 | $dateTime = new DateTime(); |
60 | - $dateTime->add( $this->ttl ); |
|
60 | + $dateTime->add($this->ttl); |
|
61 | 61 | $ttl = $dateTime->getTimestamp(); |
62 | 62 | } |
63 | 63 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return DateInterval |
71 | 71 | */ |
72 | - public function getTtl(){ |
|
72 | + public function getTtl() { |
|
73 | 73 | return $this->ttl; |
74 | 74 | } |
75 | 75 |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | public function set($key, $value, $ttl = null) |
39 | 39 | { |
40 | 40 | //convert to timestamp from now. |
41 | - if ($ttl instanceof \DateInterval){ |
|
41 | + if ($ttl instanceof \DateInterval) { |
|
42 | 42 | $dateTime = new \DateTime(); |
43 | - $dateTime->add( $ttl ); |
|
43 | + $dateTime->add($ttl); |
|
44 | 44 | $ttl = $dateTime->getTimestamp() - time(); |
45 | 45 | } |
46 | 46 | |
47 | - if (!is_int($ttl) || $ttl === null){ |
|
47 | + if (!is_int($ttl) || $ttl === null) { |
|
48 | 48 | throw new InvalidArgumentException('$ttl can only be an instance of \DateInterval, int or null'); |
49 | 49 | } |
50 | 50 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | { |
88 | 88 | $this->_isValidKey($key); |
89 | 89 | |
90 | - if ($this->cache->has($key)){ |
|
90 | + if ($this->cache->has($key)) { |
|
91 | 91 | return $this->cache->get($key); |
92 | 92 | } |
93 | 93 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $this->_checkTraversable($keys); |
129 | 129 | $result = []; |
130 | 130 | |
131 | - foreach ((array)$keys as $key){ |
|
131 | + foreach ((array)$keys as $key) { |
|
132 | 132 | $cachedItem = $this->cache->get($key); |
133 | 133 | $result[$key] = (null !== $cachedItem) ? $cachedItem : $default; |
134 | 134 | } |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | $this->_checkTraversable($values); |
156 | 156 | $results = []; |
157 | 157 | |
158 | - foreach ((array)$values as $key => $value){ |
|
158 | + foreach ((array)$values as $key => $value) { |
|
159 | 159 | $results[] = $this->cache->set($key, $value, $ttl); |
160 | 160 | } |
161 | 161 | |
162 | - if ($this->_hasFailure($results)){ |
|
162 | + if ($this->_hasFailure($results)) { |
|
163 | 163 | return false; |
164 | 164 | } |
165 | 165 | |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | $this->_checkTraversable($keys); |
183 | 183 | $results = []; |
184 | 184 | |
185 | - foreach ((array)$keys as $key){ |
|
185 | + foreach ((array)$keys as $key) { |
|
186 | 186 | $results[] = $this->cache->delete($key); |
187 | 187 | } |
188 | 188 | |
189 | - if ($this->_hasFailure($results)){ |
|
189 | + if ($this->_hasFailure($results)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
@@ -209,15 +209,15 @@ discard block |
||
209 | 209 | * @param $key |
210 | 210 | * @throws InvalidArgumentException |
211 | 211 | */ |
212 | - private function _isValidKey($key){ |
|
213 | - if (!is_string($key)){ |
|
212 | + private function _isValidKey($key) { |
|
213 | + if (!is_string($key)) { |
|
214 | 214 | throw new InvalidArgumentException('provided key must be a valid string'); |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | 218 | private function isAssoc(array $arr) |
219 | 219 | { |
220 | - if (array() === $arr){ |
|
220 | + if (array() === $arr) { |
|
221 | 221 | return false; |
222 | 222 | } |
223 | 223 | return array_keys($arr) !== range(0, count($arr) - 1); |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | * @throws InvalidArgumentException |
231 | 231 | * @internal |
232 | 232 | */ |
233 | - private function _checkTraversable($data){ |
|
233 | + private function _checkTraversable($data) { |
|
234 | 234 | |
235 | - if (is_array($data)){ |
|
235 | + if (is_array($data)) { |
|
236 | 236 | return; |
237 | 237 | } |
238 | 238 | |
239 | - if ($data instanceof \Traversable ){ |
|
239 | + if ($data instanceof \Traversable) { |
|
240 | 240 | return; |
241 | 241 | } |
242 | 242 | |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @return bool |
251 | 251 | * @internal |
252 | 252 | */ |
253 | - private function _hasFailure(array $results){ |
|
254 | - if (in_array(false, $results)){ |
|
253 | + private function _hasFailure(array $results) { |
|
254 | + if (in_array(false, $results)) { |
|
255 | 255 | return true; |
256 | 256 | } |
257 | 257 | return false; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
25 | 25 | * |
26 | 26 | * @param string $key The key of the item to store. |
27 | - * @param mixed $value The value of the item to store, must be serializable. |
|
27 | + * @param string $value The value of the item to store, must be serializable. |
|
28 | 28 | * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
29 | 29 | * the driver supports TTL then the library may set a default value |
30 | 30 | * for it or let the driver take care of that. |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | * Fetches a value from the cache. |
76 | 76 | * |
77 | 77 | * @param string $key The unique key of this item in the cache. |
78 | - * @param mixed $default Default value to return if the key does not exist. |
|
78 | + * @param string $default Default value to return if the key does not exist. |
|
79 | 79 | * |
80 | 80 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
81 | 81 | * |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * Obtains multiple cache items by their unique keys. |
115 | 115 | * |
116 | - * @param \iterable $keys A list of keys that can obtained in a single operation. |
|
116 | + * @param string[] $keys A list of keys that can obtained in a single operation. |
|
117 | 117 | * @param mixed $default Default value to return for keys that do not exist. |
118 | 118 | * |
119 | 119 | * @return \iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
140 | 140 | * |
141 | 141 | * @param \iterable $values A list of key => value pairs for a multiple-set operation. |
142 | - * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
142 | + * @param integer $ttl Optional. The TTL value of this item. If no value is sent and |
|
143 | 143 | * the driver supports TTL then the library may set a default value |
144 | 144 | * for it or let the driver take care of that. |
145 | 145 | * |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * Deletes multiple cache items in a single operation. |
170 | 170 | * |
171 | - * @param \iterable $keys A list of string-based keys to be deleted. |
|
171 | + * @param string[] $keys A list of string-based keys to be deleted. |
|
172 | 172 | * |
173 | 173 | * @return bool True if the items were successfully removed. False if there was an error. |
174 | 174 | * |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | /** |
206 | 206 | * Check that provided key is valid. |
207 | 207 | * |
208 | - * @param $key |
|
208 | + * @param string $key |
|
209 | 209 | * @throws InvalidArgumentException |
210 | 210 | */ |
211 | 211 | private function _isValidKey($key){ |