@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use \Psr\SimpleCache\InvalidArgumentException; |
16 | 16 | |
17 | -class SimpleCacheInvalidArgumentException extends SimpleCacheException implements InvalidArgumentException{} |
|
17 | +class SimpleCacheInvalidArgumentException extends SimpleCacheException implements InvalidArgumentException {} |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use Psr\SimpleCache\CacheException; |
16 | 16 | |
17 | -class SimpleCacheException extends \Exception implements CacheException{} |
|
17 | +class SimpleCacheException extends \Exception implements CacheException {} |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use Redis; |
16 | 16 | |
17 | -class RedisDriver extends CacheDriverAbstract{ |
|
17 | +class RedisDriver extends CacheDriverAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var \Redis |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param \Redis $redis |
28 | 28 | */ |
29 | - public function __construct(Redis $redis){ |
|
29 | + public function __construct(Redis $redis) { |
|
30 | 30 | $this->redis = $redis; |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** @inheritdoc */ |
34 | - public function get(string $key, $default = null){ |
|
34 | + public function get(string $key, $default = null) { |
|
35 | 35 | $value = $this->redis->get($key); |
36 | 36 | |
37 | 37 | return $value ? $value : $default; |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** @inheritdoc */ |
41 | 41 | public function set(string $key, $value, int $ttl = null):bool{ |
42 | 42 | |
43 | - if(is_null($ttl)){ |
|
43 | + if (is_null($ttl)) { |
|
44 | 44 | return $this->redis->set($key, $value); |
45 | 45 | } |
46 | 46 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | |
65 | 65 | $return = []; |
66 | 66 | |
67 | - foreach($keys as $key){ |
|
67 | + foreach ($keys as $key) { |
|
68 | 68 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
69 | 69 | } |
70 | 70 | |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | /** @inheritdoc */ |
75 | 75 | public function setMultiple(array $values, int $ttl = null):bool{ |
76 | 76 | |
77 | - if(is_null($ttl)){ |
|
77 | + if (is_null($ttl)) { |
|
78 | 78 | return $this->redis->msetnx($values); |
79 | 79 | } |
80 | 80 | |
81 | 81 | $return = []; |
82 | 82 | |
83 | - foreach($values as $key => $value){ |
|
83 | + foreach ($values as $key => $value) { |
|
84 | 84 | $return[] = $this->set($key, $value, $ttl); |
85 | 85 | } |
86 | 86 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
14 | 14 | |
15 | -abstract class CacheDriverAbstract implements CacheDriverInterface{ |
|
15 | +abstract class CacheDriverAbstract implements CacheDriverInterface { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | 18 | public function has(string $key):bool{ |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | public function getMultiple(array $keys, $default = null):array{ |
24 | 24 | $data = []; |
25 | 25 | |
26 | - foreach($keys as $key){ |
|
26 | + foreach ($keys as $key) { |
|
27 | 27 | $data[$key] = $this->get($key, $default); |
28 | 28 | } |
29 | 29 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function setMultiple(array $values, int $ttl = null):bool{ |
35 | 35 | $return = []; |
36 | 36 | |
37 | - foreach($values as $key => $value){ |
|
37 | + foreach ($values as $key => $value) { |
|
38 | 38 | $return[] = $this->set($key, $value, $ttl); |
39 | 39 | } |
40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function deleteMultiple(array $keys):bool{ |
46 | 46 | $return = []; |
47 | 47 | |
48 | - foreach($keys as $key){ |
|
48 | + foreach ($keys as $key) { |
|
49 | 49 | $return[] = $this->delete($key); |
50 | 50 | } |
51 | 51 | |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function checkReturn(array $booleans):bool{ |
61 | 61 | |
62 | - foreach($booleans as $bool){ |
|
62 | + foreach ($booleans as $bool) { |
|
63 | 63 | |
64 | - if(!(bool)$bool){ |
|
64 | + if (!(bool)$bool) { |
|
65 | 65 | return false; // @codeCoverageIgnore |
66 | 66 | } |
67 | 67 |
@@ -12,10 +12,10 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
14 | 14 | |
15 | -class APCUDriver extends CacheDriverAbstract{ |
|
15 | +class APCUDriver extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | - public function get(string $key, $default = null){ |
|
18 | + public function get(string $key, $default = null) { |
|
19 | 19 | $value = apcu_fetch($key); |
20 | 20 | |
21 | 21 | return $value ?: $default; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\SimpleCache\SimpleCacheException; |
16 | 16 | use Memcached; |
17 | 17 | |
18 | -class MemcachedDriver extends CacheDriverAbstract{ |
|
18 | +class MemcachedDriver extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \Memcached |
@@ -29,17 +29,17 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @throws \chillerlan\SimpleCache\SimpleCacheException |
31 | 31 | */ |
32 | - public function __construct(Memcached $memcached){ |
|
32 | + public function __construct(Memcached $memcached) { |
|
33 | 33 | $this->memcached = $memcached; |
34 | 34 | |
35 | - if(empty($this->memcached->getServerList())){ |
|
35 | + if (empty($this->memcached->getServerList())) { |
|
36 | 36 | throw new SimpleCacheException('no memcache server available'); |
37 | 37 | } |
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** @inheritdoc */ |
42 | - public function get(string $key, $default = null){ |
|
42 | + public function get(string $key, $default = null) { |
|
43 | 43 | $value = $this->memcached->get($key); |
44 | 44 | |
45 | 45 | return $value ?: $default; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $values = $this->memcached->getMulti($keys); |
66 | 66 | $return = []; |
67 | 67 | |
68 | - foreach($keys as $key){ |
|
68 | + foreach ($keys as $key) { |
|
69 | 69 | $return[$key] = $values[$key] ?? $default; |
70 | 70 | } |
71 | 71 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
14 | 14 | |
15 | -class SessionCacheDriver extends CacheDriverAbstract{ |
|
15 | +class SessionCacheDriver extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var string |
@@ -24,18 +24,18 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @param string|null $key |
26 | 26 | */ |
27 | - public function __construct(string $key = null){ |
|
27 | + public function __construct(string $key = null) { |
|
28 | 28 | $this->key = $key ?? '_session_cache'; |
29 | 29 | |
30 | 30 | $_SESSION[$this->key] = []; |
31 | 31 | } |
32 | 32 | |
33 | 33 | /** @inheritdoc */ |
34 | - public function get(string $key, $default = null){ |
|
34 | + public function get(string $key, $default = null) { |
|
35 | 35 | |
36 | - if(isset($_SESSION[$this->key][$key])){ |
|
36 | + if (isset($_SESSION[$this->key][$key])) { |
|
37 | 37 | |
38 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){ |
|
38 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) { |
|
39 | 39 | return $_SESSION[$this->key][$key]['content']; |
40 | 40 | } |
41 | 41 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\SimpleCache\SimpleCacheException; |
16 | 16 | use stdClass; |
17 | 17 | |
18 | -class FileCacheDriver extends CacheDriverAbstract{ |
|
18 | +class FileCacheDriver extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |
@@ -29,30 +29,30 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @throws \chillerlan\SimpleCache\SimpleCacheException |
31 | 31 | */ |
32 | - public function __construct(string $cachedir){ |
|
32 | + public function __construct(string $cachedir) { |
|
33 | 33 | $this->cachedir = $cachedir; |
34 | 34 | |
35 | - if(!is_dir($cachedir)){ |
|
35 | + if (!is_dir($cachedir)) { |
|
36 | 36 | throw new SimpleCacheException('invalid cachedir "'.$cachedir.'"'); |
37 | 37 | } |
38 | 38 | |
39 | - if(!is_writable($cachedir)){ |
|
39 | + if (!is_writable($cachedir)) { |
|
40 | 40 | throw new SimpleCacheException('cachedir is read-only. permissions?'); // @codeCoverageIgnore |
41 | 41 | } |
42 | 42 | |
43 | 43 | } |
44 | 44 | |
45 | 45 | /** @inheritdoc */ |
46 | - public function get(string $key, $default = null){ |
|
46 | + public function get(string $key, $default = null) { |
|
47 | 47 | $filename = $this->filename($key); |
48 | 48 | |
49 | - if(is_file($filename)){ |
|
49 | + if (is_file($filename)) { |
|
50 | 50 | $content = file_get_contents($filename); |
51 | 51 | |
52 | - if(!empty($content)){ |
|
52 | + if (!empty($content)) { |
|
53 | 53 | $data = unserialize($content); |
54 | 54 | |
55 | - if(is_null($data->ttl) || $data->ttl > time()){ |
|
55 | + if (is_null($data->ttl) || $data->ttl > time()) { |
|
56 | 56 | return $data->content; |
57 | 57 | } |
58 | 58 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | $filename = $this->filename($key); |
70 | 70 | $data = new stdClass; |
71 | 71 | |
72 | - if($ttl !== null){ |
|
72 | + if ($ttl !== null) { |
|
73 | 73 | $data->ttl = time() + $ttl; |
74 | 74 | } |
75 | 75 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | file_put_contents($filename, serialize($data)); |
79 | 79 | |
80 | - if(is_file($filename)){ |
|
80 | + if (is_file($filename)) { |
|
81 | 81 | return true; |
82 | 82 | } |
83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | public function delete(string $key):bool{ |
89 | 89 | $filename = $this->filename($key); |
90 | 90 | |
91 | - if(is_file($filename)){ |
|
91 | + if (is_file($filename)) { |
|
92 | 92 | return unlink($filename); |
93 | 93 | } |
94 | 94 | |
@@ -99,13 +99,13 @@ discard block |
||
99 | 99 | public function clear():bool{ |
100 | 100 | $dir = scandir($this->cachedir); |
101 | 101 | |
102 | - if(is_array($dir) && !empty($dir)){ |
|
102 | + if (is_array($dir) && !empty($dir)) { |
|
103 | 103 | $return = []; |
104 | 104 | |
105 | - foreach($dir as $file){ |
|
105 | + foreach ($dir as $file) { |
|
106 | 106 | $path = $this->cachedir.DIRECTORY_SEPARATOR.$file; |
107 | 107 | |
108 | - if(is_file($path) && strlen($file) === 64){ |
|
108 | + if (is_file($path) && strlen($file) === 64) { |
|
109 | 109 | $return[] = unlink($path); |
110 | 110 | } |
111 | 111 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
14 | 14 | |
15 | -class MemoryCacheDriver extends CacheDriverAbstract{ |
|
15 | +class MemoryCacheDriver extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var array |
@@ -20,11 +20,11 @@ discard block |
||
20 | 20 | protected $cache = []; |
21 | 21 | |
22 | 22 | /** @inheritdoc */ |
23 | - public function get(string $key, $default = null){ |
|
23 | + public function get(string $key, $default = null) { |
|
24 | 24 | |
25 | - if(isset($this->cache[$key])){ |
|
25 | + if (isset($this->cache[$key])) { |
|
26 | 26 | |
27 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){ |
|
27 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()) { |
|
28 | 28 | return $this->cache[$key]['content']; |
29 | 29 | } |
30 | 30 |