@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * Persists data in the cache, uniquely referenced by a key with an optional expiration TTL time. |
26 | 26 | * |
27 | 27 | * @param string $key The key of the item to store. |
28 | - * @param mixed $value The value of the item to store, must be serializable. |
|
28 | + * @param string $value The value of the item to store, must be serializable. |
|
29 | 29 | * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
30 | 30 | * the driver supports TTL then the library may set a default value |
31 | 31 | * for it or let the driver take care of that. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * Fetches a value from the cache. |
77 | 77 | * |
78 | 78 | * @param string $key The unique key of this item in the cache. |
79 | - * @param mixed $default Default value to return if the key does not exist. |
|
79 | + * @param string $default Default value to return if the key does not exist. |
|
80 | 80 | * |
81 | 81 | * @return mixed The value of the item from the cache, or $default in case of cache miss. |
82 | 82 | * |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * Obtains multiple cache items by their unique keys. |
116 | 116 | * |
117 | - * @param iterable $keys A list of keys that can obtained in a single operation. |
|
117 | + * @param string[] $keys A list of keys that can obtained in a single operation. |
|
118 | 118 | * @param mixed $default Default value to return for keys that do not exist. |
119 | 119 | * |
120 | 120 | * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as value. |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * Persists a set of key => value pairs in the cache, with an optional TTL. |
141 | 141 | * |
142 | 142 | * @param iterable $values A list of key => value pairs for a multiple-set operation. |
143 | - * @param null|int|DateInterval $ttl Optional. The TTL value of this item. If no value is sent and |
|
143 | + * @param integer $ttl Optional. The TTL value of this item. If no value is sent and |
|
144 | 144 | * the driver supports TTL then the library may set a default value |
145 | 145 | * for it or let the driver take care of that. |
146 | 146 | * |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | /** |
170 | 170 | * Deletes multiple cache items in a single operation. |
171 | 171 | * |
172 | - * @param iterable $keys A list of string-based keys to be deleted. |
|
172 | + * @param string[] $keys A list of string-based keys to be deleted. |
|
173 | 173 | * |
174 | 174 | * @return bool True if the items were successfully removed. False if there was an error. |
175 | 175 | * |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | /** |
207 | 207 | * Check that provided key is valid. |
208 | 208 | * |
209 | - * @param $key |
|
209 | + * @param string $key |
|
210 | 210 | * @throws InvalidArgumentException |
211 | 211 | */ |
212 | 212 | private function _isValidKey($key){ |
@@ -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; |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use Ds\Cache\Cache; |
6 | 6 | use Ds\Cache\CacheStorageInterface; |
7 | -use Ds\Cache\NullStorage; |
|
8 | 7 | use Psr\SimpleCache\InvalidArgumentException; |
9 | 8 | |
10 | 9 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | { |
40 | 40 | $key = 21021000; |
41 | 41 | $this->expectException(InvalidArgumentException::class); |
42 | - $this->cache->set($key,'value'); |
|
42 | + $this->cache->set($key, 'value'); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $this->cache->delete($key); |
203 | 203 | } |
204 | 204 | |
205 | - public function testGetMultiple(){ |
|
205 | + public function testGetMultiple() { |
|
206 | 206 | |
207 | 207 | $expected = [ |
208 | 208 | 'foo' => 'fooValue', |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $i = 0; |
214 | 214 | |
215 | - foreach ($expected as $key => $value){ |
|
215 | + foreach ($expected as $key => $value) { |
|
216 | 216 | |
217 | 217 | $this->storageMock->expects($this->at($i)) |
218 | 218 | ->method('get') |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | |
230 | 230 | } |
231 | 231 | |
232 | - public function testSetMultiple(){ |
|
232 | + public function testSetMultiple() { |
|
233 | 233 | |
234 | 234 | $keys = [ |
235 | 235 | 'foo' => 'fooValue', |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $i = 0; |
244 | 244 | $expires = 60 * 60; |
245 | 245 | |
246 | - foreach ($keys as $key => $value){ |
|
246 | + foreach ($keys as $key => $value) { |
|
247 | 247 | $this->storageMock->expects($this->at($i)) |
248 | 248 | ->method('set') |
249 | 249 | ->with( |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | $i++; |
256 | 256 | } |
257 | 257 | |
258 | - $actual = $this->cache->setMultiple($keys,$expires); |
|
258 | + $actual = $this->cache->setMultiple($keys, $expires); |
|
259 | 259 | $this->assertEquals($expected, $actual); |
260 | 260 | } |
261 | 261 | |
262 | - public function testDeleteMultiple(){ |
|
262 | + public function testDeleteMultiple() { |
|
263 | 263 | |
264 | - $keys = ['foo','bar','baz']; |
|
264 | + $keys = ['foo', 'bar', 'baz']; |
|
265 | 265 | $deleteStatus = true; |
266 | 266 | $expected = true; |
267 | 267 | |
268 | - foreach ($keys as $i => $key){ |
|
268 | + foreach ($keys as $i => $key) { |
|
269 | 269 | $this->storageMock->expects($this->at($i)) |
270 | 270 | ->method('delete') |
271 | 271 | ->with( |
@@ -278,15 +278,15 @@ discard block |
||
278 | 278 | $this->assertEquals($expected, $actual); |
279 | 279 | } |
280 | 280 | |
281 | - public function testDeleteMultipleFailure(){ |
|
281 | + public function testDeleteMultipleFailure() { |
|
282 | 282 | |
283 | - $keys = ['foo','bar','baz']; |
|
283 | + $keys = ['foo', 'bar', 'baz']; |
|
284 | 284 | $expected = false; |
285 | 285 | $deleteStatus = true; |
286 | 286 | |
287 | - foreach ($keys as $i => $key){ |
|
287 | + foreach ($keys as $i => $key) { |
|
288 | 288 | |
289 | - if ($i === 1){ |
|
289 | + if ($i === 1) { |
|
290 | 290 | $deleteStatus = false; |
291 | 291 | } |
292 | 292 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | $this->assertEquals($expected, $actual); |
303 | 303 | } |
304 | 304 | |
305 | - public function testclear(){ |
|
305 | + public function testclear() { |
|
306 | 306 | $this->storageMock->expects($this->once()) |
307 | 307 | ->method('clear'); |
308 | 308 | |
@@ -312,11 +312,11 @@ discard block |
||
312 | 312 | /** |
313 | 313 | * Private functions |
314 | 314 | */ |
315 | - public function test_isValidKeyValid(){} |
|
316 | - public function test_isValidKeyInvalid(){} |
|
317 | - public function test_checkTraversableArray(){} |
|
318 | - public function test_checkTraversableTraversable(){} |
|
319 | - public function test_checkTraversableException(){} |
|
320 | - public function test_hasFailureNoFailure(){} |
|
321 | - public function test_hasFailureException(){} |
|
315 | + public function test_isValidKeyValid() {} |
|
316 | + public function test_isValidKeyInvalid() {} |
|
317 | + public function test_checkTraversableArray() {} |
|
318 | + public function test_checkTraversableTraversable() {} |
|
319 | + public function test_checkTraversableException() {} |
|
320 | + public function test_hasFailureNoFailure() {} |
|
321 | + public function test_hasFailureException() {} |
|
322 | 322 | } |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * |
12 | 12 | * @package Tests\Cache\Mock |
13 | 13 | */ |
14 | -class AbstractCacheMock extends AbstractCache{ |
|
14 | +class AbstractCacheMock extends AbstractCache { |
|
15 | 15 | } |
16 | 16 | \ No newline at end of file |
@@ -11,7 +11,7 @@ |
||
11 | 11 | * |
12 | 12 | * @package Tests\Cache\Mock |
13 | 13 | */ |
14 | -class AbstractStorageMock extends AbstractStorage{ |
|
14 | +class AbstractStorageMock extends AbstractStorage { |
|
15 | 15 | |
16 | 16 | public function set($key, $value, $ttl = null) |
17 | 17 | { |
@@ -36,7 +36,7 @@ |
||
36 | 36 | { |
37 | 37 | $this->ttl = new \DateInterval('P1M'); |
38 | 38 | $this->memcacheMock = $this->getMockBuilder('\Memcached')->getMock(); |
39 | - $this->memcacheStorage = new MemcacheStorage($this->memcacheMock,'localhost',11211, $this->ttl); |
|
39 | + $this->memcacheStorage = new MemcacheStorage($this->memcacheMock, 'localhost', 11211, $this->ttl); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | public function testAddServer() |
@@ -28,35 +28,35 @@ |
||
28 | 28 | /** |
29 | 29 | * |
30 | 30 | */ |
31 | - public function testHas(){ |
|
31 | + public function testHas() { |
|
32 | 32 | $this->assertEquals($this->cacheStorage->has('key', 'value'), false); |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * |
37 | 37 | */ |
38 | - public function testSet(){ |
|
38 | + public function testSet() { |
|
39 | 39 | $this->assertEquals($this->cacheStorage->set('key', 'value', 10), true); |
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | 43 | * |
44 | 44 | */ |
45 | - public function testGet(){ |
|
45 | + public function testGet() { |
|
46 | 46 | $this->assertEquals($this->cacheStorage->get('key'), null); |
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
50 | 50 | * |
51 | 51 | */ |
52 | - public function testDelete(){ |
|
52 | + public function testDelete() { |
|
53 | 53 | $this->assertEquals($this->cacheStorage->delete('key'), true); |
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * |
58 | 58 | */ |
59 | - public function testClear(){ |
|
59 | + public function testClear() { |
|
60 | 60 | $this->assertEquals($this->cacheStorage->clear(), true); |
61 | 61 | } |
62 | 62 |
@@ -75,7 +75,7 @@ |
||
75 | 75 | * |
76 | 76 | */ |
77 | 77 | public function testClear(){ |
78 | - $this->assertEquals($this->cacheStorage->clear(), true); |
|
78 | + $this->assertEquals($this->cacheStorage->clear(), true); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function setUp() |
29 | 29 | { |
30 | - $this->testDir = __DIR__ . '/cacheTest'; |
|
31 | - $this->cacheStorage = new FileStorage( $this->testDir, new \DateInterval('P1M')); |
|
30 | + $this->testDir = __DIR__.'/cacheTest'; |
|
31 | + $this->cacheStorage = new FileStorage($this->testDir, new \DateInterval('P1M')); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,47 +43,47 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * |
45 | 45 | */ |
46 | - public function testSet(){ |
|
47 | - $actual = $this->cacheStorage->set('key','value',60*60); |
|
46 | + public function testSet() { |
|
47 | + $actual = $this->cacheStorage->set('key', 'value', 60 * 60); |
|
48 | 48 | $this->assertEquals(true, $actual); |
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * |
53 | 53 | */ |
54 | - public function testHasNoValue(){ |
|
54 | + public function testHasNoValue() { |
|
55 | 55 | $this->assertEquals($this->cacheStorage->has('someRandomKey'), false); |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * |
60 | 60 | */ |
61 | - public function testHas(){ |
|
62 | - $this->cacheStorage->set('foo','bar'); |
|
61 | + public function testHas() { |
|
62 | + $this->cacheStorage->set('foo', 'bar'); |
|
63 | 63 | $this->assertEquals($this->cacheStorage->has('foo'), true); |
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * |
68 | 68 | */ |
69 | - public function testHasExpired(){ |
|
70 | - $this->cacheStorage->set('expired','bar', -1200); |
|
69 | + public function testHasExpired() { |
|
70 | + $this->cacheStorage->set('expired', 'bar', -1200); |
|
71 | 71 | $this->assertEquals($this->cacheStorage->has('expired'), false); |
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | 75 | * |
76 | 76 | */ |
77 | - public function testClear(){ |
|
77 | + public function testClear() { |
|
78 | 78 | $this->assertEquals($this->cacheStorage->clear(), true); |
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
82 | 82 | * |
83 | 83 | */ |
84 | - public function testGet(){ |
|
84 | + public function testGet() { |
|
85 | 85 | $expected = 'bat'; |
86 | - $this->cacheStorage->set('baz',$expected); |
|
86 | + $this->cacheStorage->set('baz', $expected); |
|
87 | 87 | $actual = $this->cacheStorage->get('baz'); |
88 | 88 | $this->assertEquals($expected, $actual); |
89 | 89 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | { |
96 | 96 | $dir = $this->testDir; |
97 | 97 | |
98 | - if (is_dir( $dir)){ |
|
98 | + if (is_dir($dir)) { |
|
99 | 99 | array_map('unlink', glob("$dir/*.*")); |
100 | 100 | } |
101 | 101 | \rmdir($dir); |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | /** |
34 | 34 | * Test immutable setter AbstractStorage::withTtl |
35 | 35 | */ |
36 | - public function testWithTtl(){ |
|
36 | + public function testWithTtl() { |
|
37 | 37 | $newDateInterval = new \DateInterval('P2M'); |
38 | 38 | $newTtl = $this->abstractStorage->withTtl($newDateInterval); |
39 | 39 | $this->assertNotSame($this->abstractStorage->getTtl(), $newTtl->getTtl()); |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * Test getter AbstractStorage::getTtl |
44 | 44 | */ |
45 | - public function testGetTtl(){ |
|
45 | + public function testGetTtl() { |
|
46 | 46 | $ttl = $this->abstractStorage->getTtl(); |
47 | 47 | $this->assertSame($this->ttl, $ttl); |
48 | 48 | } |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * Get get ttl when provided with null |
52 | 52 | */ |
53 | - public function testGetTtlTimestampWhenNull(){ |
|
53 | + public function testGetTtlTimestampWhenNull() { |
|
54 | 54 | $dateTime = new \DateTime(); |
55 | - $dateTime->add( $this->ttl ); |
|
55 | + $dateTime->add($this->ttl); |
|
56 | 56 | $expected = $dateTime->getTimestamp(); |
57 | 57 | $actual = $this->abstractStorage->getTtlTimestamp(null); |
58 | 58 | $this->assertEquals($expected, $actual); |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * Test get ttl when provided with an integer. |
63 | 63 | */ |
64 | - public function testGetTtlTimestampWhenInt(){ |
|
65 | - $expected = 60*60*7; |
|
64 | + public function testGetTtlTimestampWhenInt() { |
|
65 | + $expected = 60 * 60 * 7; |
|
66 | 66 | $actual = $this->abstractStorage->getTtlTimestamp($expected); |
67 | 67 | $this->assertEquals($expected, $actual); |
68 | 68 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public function has($key){ |
|
71 | - if (!empty($this->mmc->get($key))){ |
|
70 | + public function has($key) { |
|
71 | + if (!empty($this->mmc->get($key))) { |
|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | return false; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return bool True on success and false on failure. |
115 | 115 | */ |
116 | - public function clear(){ |
|
116 | + public function clear() { |
|
117 | 117 | return $this->flush(); |
118 | 118 | } |
119 | 119 |