@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | |
17 | -class SessionCache extends CacheDriverAbstract{ |
|
17 | +class SessionCache extends CacheDriverAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var string |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @throws \chillerlan\SimpleCache\CacheException |
30 | 30 | */ |
31 | - public function __construct(SettingsContainerInterface $options = null){ |
|
31 | + public function __construct(SettingsContainerInterface $options = null) { |
|
32 | 32 | parent::__construct($options); |
33 | 33 | |
34 | 34 | $this->key = $this->options->cacheSessionkey; |
35 | 35 | |
36 | - if(!is_string($this->key) || empty($this->key)){ |
|
36 | + if (!is_string($this->key) || empty($this->key)) { |
|
37 | 37 | $msg = 'invalid session cache key'; |
38 | 38 | |
39 | 39 | $this->logger->error($msg); |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** @inheritdoc */ |
48 | - public function get($key, $default = null){ |
|
48 | + public function get($key, $default = null) { |
|
49 | 49 | $key = $this->checkKey($key); |
50 | 50 | |
51 | - if(isset($_SESSION[$this->key][$key])){ |
|
51 | + if (isset($_SESSION[$this->key][$key])) { |
|
52 | 52 | |
53 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){ |
|
53 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) { |
|
54 | 54 | return $_SESSION[$this->key][$key]['content']; |
55 | 55 | } |
56 | 56 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use FilesystemIterator, RecursiveDirectoryIterator, RecursiveIteratorIterator, stdClass; |
17 | 17 | |
18 | -class FileCache extends CacheDriverAbstract{ |
|
18 | +class FileCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |
@@ -29,19 +29,19 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @throws \chillerlan\SimpleCache\CacheException |
31 | 31 | */ |
32 | - public function __construct(SettingsContainerInterface $options = null){ |
|
32 | + public function __construct(SettingsContainerInterface $options = null) { |
|
33 | 33 | parent::__construct($options); |
34 | 34 | |
35 | 35 | $this->cachedir = rtrim($this->options->cacheFilestorage, '/\\').DIRECTORY_SEPARATOR; |
36 | 36 | |
37 | - if(!is_dir($this->cachedir)){ |
|
37 | + if (!is_dir($this->cachedir)) { |
|
38 | 38 | $msg = 'invalid cachedir "'.$this->cachedir.'"'; |
39 | 39 | |
40 | 40 | $this->logger->error($msg); |
41 | 41 | throw new CacheException($msg); |
42 | 42 | } |
43 | 43 | |
44 | - if(!is_writable($this->cachedir)){ |
|
44 | + if (!is_writable($this->cachedir)) { |
|
45 | 45 | $msg = 'cachedir is read-only. permissions?'; |
46 | 46 | |
47 | 47 | $this->logger->error($msg); |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | /** @inheritdoc */ |
54 | - public function get($key, $default = null){ |
|
54 | + public function get($key, $default = null) { |
|
55 | 55 | $filename = $this->getFilepath($this->checkKey($key)); |
56 | 56 | |
57 | - if(is_file($filename)){ |
|
57 | + if (is_file($filename)) { |
|
58 | 58 | $content = file_get_contents($filename); |
59 | 59 | |
60 | - if(!empty($content)){ |
|
60 | + if (!empty($content)) { |
|
61 | 61 | $data = unserialize($content); |
62 | 62 | |
63 | - if($data->ttl === null || $data->ttl > time()){ |
|
63 | + if ($data->ttl === null || $data->ttl > time()) { |
|
64 | 64 | return $data->content; |
65 | 65 | } |
66 | 66 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $file = $this->getFilepath($this->checkKey($key)); |
80 | 80 | $dir = dirname($file); |
81 | 81 | |
82 | - if(!is_dir($dir)){ |
|
82 | + if (!is_dir($dir)) { |
|
83 | 83 | mkdir($dir, 0755, true); |
84 | 84 | } |
85 | 85 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $data->ttl = null; |
88 | 88 | $data->content = $value; |
89 | 89 | |
90 | - if($ttl !== null){ |
|
90 | + if ($ttl !== null) { |
|
91 | 91 | $data->ttl = time() + $ttl; |
92 | 92 | } |
93 | 93 | |
94 | 94 | file_put_contents($file, serialize($data)); |
95 | 95 | |
96 | - if(is_file($file)){ |
|
96 | + if (is_file($file)) { |
|
97 | 97 | return true; |
98 | 98 | } |
99 | 99 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function delete($key):bool{ |
105 | 105 | $filename = $this->getFilepath($this->checkKey($key)); |
106 | 106 | |
107 | - if(is_file($filename)){ |
|
107 | + if (is_file($filename)) { |
|
108 | 108 | return unlink($filename); |
109 | 109 | } |
110 | 110 | |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | |
114 | 114 | /** @inheritdoc */ |
115 | 115 | public function clear():bool{ |
116 | - $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS); |
|
116 | + $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); |
|
117 | 117 | $return = []; |
118 | 118 | |
119 | - foreach(new RecursiveIteratorIterator($iterator) as $path){ |
|
119 | + foreach (new RecursiveIteratorIterator($iterator) as $path) { |
|
120 | 120 | |
121 | 121 | // skip files in the parent directory - cache files are only under /a/ab/[hash] |
122 | - if(strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false){ |
|
122 | + if (strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false) { |
|
123 | 123 | continue; |
124 | 124 | } |
125 | 125 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class MemoryCache extends CacheDriverAbstract{ |
|
15 | +class MemoryCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var array |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | protected $cache = []; |
21 | 21 | |
22 | 22 | /** @inheritdoc */ |
23 | - public function get($key, $default = null){ |
|
23 | + public function get($key, $default = null) { |
|
24 | 24 | $key = $this->checkKey($key); |
25 | 25 | |
26 | - if(isset($this->cache[$key])){ |
|
26 | + if (isset($this->cache[$key])) { |
|
27 | 27 | |
28 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){ |
|
28 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()) { |
|
29 | 29 | return $this->cache[$key]['content']; |
30 | 30 | } |
31 | 31 |
@@ -12,13 +12,13 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class APCUCache extends CacheDriverAbstract{ |
|
15 | +class APCUCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | - public function get($key, $default = null){ |
|
18 | + public function get($key, $default = null) { |
|
19 | 19 | $value = apcu_fetch($this->checkKey($key)); |
20 | 20 | |
21 | - if($value !== false){ |
|
21 | + if ($value !== false) { |
|
22 | 22 | return $value; |
23 | 23 | } |
24 | 24 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use Redis; |
17 | 17 | |
18 | -class RedisCache extends CacheDriverAbstract{ |
|
18 | +class RedisCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \Redis |
@@ -28,17 +28,17 @@ discard block |
||
28 | 28 | * @param \Redis $redis |
29 | 29 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
30 | 30 | */ |
31 | - public function __construct(Redis $redis, SettingsContainerInterface $options = null){ |
|
31 | + public function __construct(Redis $redis, SettingsContainerInterface $options = null) { |
|
32 | 32 | parent::__construct($options); |
33 | 33 | |
34 | 34 | $this->redis = $redis; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** @inheritdoc */ |
38 | - public function get($key, $default = null){ |
|
38 | + public function get($key, $default = null) { |
|
39 | 39 | $value = $this->redis->get($this->checkKey($key)); |
40 | 40 | |
41 | - if($value !== false){ |
|
41 | + if ($value !== false) { |
|
42 | 42 | return $value; |
43 | 43 | } |
44 | 44 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $key = $this->checkKey($key); |
51 | 51 | $ttl = $this->getTTL($ttl); |
52 | 52 | |
53 | - if($ttl === null){ |
|
53 | + if ($ttl === null) { |
|
54 | 54 | return $this->redis->set($key, $value); |
55 | 55 | } |
56 | 56 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $return = []; |
80 | 80 | |
81 | - foreach($keys as $key){ |
|
81 | + foreach ($keys as $key) { |
|
82 | 82 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
83 | 83 | } |
84 | 84 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $values = $this->getData($values); |
91 | 91 | $ttl = $this->getTTL($ttl); |
92 | 92 | |
93 | - if($ttl === null){ |
|
93 | + if ($ttl === null) { |
|
94 | 94 | $this->checkKeyArray(array_keys($values)); |
95 | 95 | |
96 | 96 | return $this->redis->msetnx($values); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $return = []; |
100 | 100 | |
101 | - foreach($values as $key => $value){ |
|
101 | + foreach ($values as $key => $value) { |
|
102 | 102 | $return[] = $this->set($key, $value, $ttl); |
103 | 103 | } |
104 | 104 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null) { |
|
34 | 34 | $this->options = $options ?? new CacheOptions; |
35 | 35 | $this->logger = new NullLogger; |
36 | 36 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function getMultiple($keys, $default = null):array{ |
45 | 45 | $data = []; |
46 | 46 | |
47 | - foreach($this->getData($keys) as $key){ |
|
47 | + foreach ($this->getData($keys) as $key) { |
|
48 | 48 | $data[$key] = $this->get($key, $default); |
49 | 49 | } |
50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function setMultiple($values, $ttl = null):bool{ |
56 | 56 | $return = []; |
57 | 57 | |
58 | - foreach($this->getData($values) as $key => $value){ |
|
58 | + foreach ($this->getData($values) as $key => $value) { |
|
59 | 59 | $return[] = $this->set($key, $value, $ttl); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function deleteMultiple($keys):bool{ |
67 | 67 | $return = []; |
68 | 68 | |
69 | - foreach($this->getData($keys) as $key){ |
|
69 | + foreach ($this->getData($keys) as $key) { |
|
70 | 70 | $return[] = $this->delete($key); |
71 | 71 | } |
72 | 72 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function checkKey($key):string{ |
83 | 83 | |
84 | - if(!is_string($key) || empty($key)){ |
|
84 | + if (!is_string($key) || empty($key)) { |
|
85 | 85 | $msg = 'invalid cache key: "'.$key.'"'; |
86 | 86 | $this->logger->error($msg); |
87 | 87 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function checkKeyArray(array $keys):void{ |
100 | 100 | |
101 | - foreach($keys as $key){ |
|
101 | + foreach ($keys as $key) { |
|
102 | 102 | $this->checkKey($key); |
103 | 103 | } |
104 | 104 | |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function getData($data):array{ |
114 | 114 | |
115 | - if(is_array($data)){ |
|
115 | + if (is_array($data)) { |
|
116 | 116 | return $data; |
117 | 117 | } |
118 | - elseif($data instanceof Traversable){ |
|
118 | + elseif ($data instanceof Traversable) { |
|
119 | 119 | return iterator_to_array($data); // @codeCoverageIgnore |
120 | 120 | } |
121 | 121 | |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | * @return int|null |
132 | 132 | * @throws \Psr\SimpleCache\InvalidArgumentException |
133 | 133 | */ |
134 | - protected function getTTL($ttl):?int{ |
|
134 | + protected function getTTL($ttl): ?int{ |
|
135 | 135 | |
136 | - if($ttl instanceof DateInterval){ |
|
136 | + if ($ttl instanceof DateInterval) { |
|
137 | 137 | return (new DateTime)->add($ttl)->getTimeStamp() - time(); |
138 | 138 | } |
139 | - else if((is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
139 | + else if ((is_int($ttl) && $ttl > 0) || $ttl === null) { |
|
140 | 140 | return $ttl; |
141 | 141 | } |
142 | 142 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function checkReturn(array $booleans):bool{ |
155 | 155 | |
156 | - foreach($booleans as $bool){ |
|
156 | + foreach ($booleans as $bool) { |
|
157 | 157 | |
158 | - if(!(bool)$bool){ |
|
158 | + if (!(bool)$bool) { |
|
159 | 159 | return false; // @codeCoverageIgnore |
160 | 160 | } |
161 | 161 |
@@ -114,8 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | if(is_array($data)){ |
116 | 116 | return $data; |
117 | - } |
|
118 | - elseif($data instanceof Traversable){ |
|
117 | + } elseif($data instanceof Traversable){ |
|
119 | 118 | return iterator_to_array($data); // @codeCoverageIgnore |
120 | 119 | } |
121 | 120 | |
@@ -135,8 +134,7 @@ discard block |
||
135 | 134 | |
136 | 135 | if($ttl instanceof DateInterval){ |
137 | 136 | return (new DateTime)->add($ttl)->getTimeStamp() - time(); |
138 | - } |
|
139 | - else if((is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
137 | + } else if((is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
140 | 138 | return $ttl; |
141 | 139 | } |
142 | 140 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use Memcached; |
17 | 17 | |
18 | -class MemcachedCache extends CacheDriverAbstract{ |
|
18 | +class MemcachedCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \Memcached |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @throws \chillerlan\SimpleCache\CacheException |
32 | 32 | */ |
33 | - public function __construct(Memcached $memcached, SettingsContainerInterface $options = null){ |
|
33 | + public function __construct(Memcached $memcached, SettingsContainerInterface $options = null) { |
|
34 | 34 | parent::__construct($options); |
35 | 35 | |
36 | 36 | $this->memcached = $memcached; |
37 | 37 | |
38 | - if(empty($this->memcached->getServerList())){ |
|
38 | + if (empty($this->memcached->getServerList())) { |
|
39 | 39 | $msg = 'no memcache server available'; |
40 | 40 | |
41 | 41 | $this->logger->error($msg); |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** @inheritdoc */ |
48 | - public function get($key, $default = null){ |
|
48 | + public function get($key, $default = null) { |
|
49 | 49 | $value = $this->memcached->get($this->checkKey($key)); |
50 | 50 | |
51 | - if($value !== false){ |
|
51 | + if ($value !== false) { |
|
52 | 52 | return $value; |
53 | 53 | } |
54 | 54 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $values = $this->memcached->getMulti($keys); |
80 | 80 | $return = []; |
81 | 81 | |
82 | - foreach($keys as $key){ |
|
82 | + foreach ($keys as $key) { |
|
83 | 83 | $return[$key] = $values[$key] ?? $default; |
84 | 84 | } |
85 | 85 |