@@ -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){ |
@@ -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 |