@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | |
132 | 132 | /** |
133 | - * @param $keyword |
|
133 | + * @param false|string $keyword |
|
134 | 134 | * @param bool $skip |
135 | 135 | * @return string |
136 | 136 | * @throws phpFastCacheIOException |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | /** |
199 | 199 | * @param $filename |
200 | - * @return mixed |
|
200 | + * @return string |
|
201 | 201 | */ |
202 | 202 | protected static function cleanFileName($filename) |
203 | 203 | { |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | /** |
215 | - * @param $path |
|
215 | + * @param string $path |
|
216 | 216 | * @param bool $create |
217 | 217 | * @throws phpFastCacheIOException |
218 | 218 | */ |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | |
251 | 251 | /** |
252 | - * @param $file |
|
252 | + * @param string $file |
|
253 | 253 | * @return string |
254 | 254 | * @throws phpFastCacheIOException |
255 | 255 | */ |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | protected static function cleanFileName($filename) |
203 | 203 | { |
204 | 204 | $regex = [ |
205 | - '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
206 | - '/\.$/', |
|
207 | - '/^\./', |
|
205 | + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
206 | + '/\.$/', |
|
207 | + '/^\./', |
|
208 | 208 | ]; |
209 | 209 | $replace = ['-', '', '']; |
210 | 210 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5( |
297 | 297 | str_shuffle(uniqid($this->getDriverName(), false)) |
298 | 298 | . str_shuffle(uniqid($this->getDriverName(), false)) |
299 | - )); |
|
299 | + )); |
|
300 | 300 | |
301 | 301 | $f = fopen($tmpFilename, 'w+'); |
302 | 302 | flock($f, LOCK_EX); |
@@ -338,11 +338,11 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | $stat->setData(implode(', ', array_keys($this->itemInstances))) |
341 | - ->setRawData([ |
|
341 | + ->setRawData([ |
|
342 | 342 | 'tmp' => $this->tmp |
343 | - ]) |
|
344 | - ->setSize(Directory::dirSize($path)) |
|
345 | - ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
343 | + ]) |
|
344 | + ->setSize(Directory::dirSize($path)) |
|
345 | + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
346 | 346 | |
347 | 347 | return $stat; |
348 | 348 | } |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | return $full_path_tmp; |
96 | 96 | } |
97 | 97 | return $full_path; |
98 | - }else{ |
|
98 | + } else{ |
|
99 | 99 | if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
100 | 100 | if (!@file_exists($full_path)) { |
101 | 101 | @mkdir($full_path, $this->getDefaultChmod(), true); |
102 | - }else if (!@is_writable($full_path)) { |
|
102 | + } else if (!@is_writable($full_path)) { |
|
103 | 103 | if (!@chmod($full_path, $this->getDefaultChmod()) && $this->config[ 'autoTmpFallback' ]) |
104 | 104 | { |
105 | 105 | /** |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | if(!rename($tmpFilename, $file)){ |
300 | 300 | throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
301 | 301 | } |
302 | - }else{ |
|
302 | + } else{ |
|
303 | 303 | $f = fopen($file, 'w+'); |
304 | 304 | $octetWritten = fwrite($f, $data); |
305 | 305 | fclose($f); |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | * Calculate the security key |
52 | 52 | */ |
53 | 53 | { |
54 | - $securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : ''; |
|
54 | + $securityKey = array_key_exists('securityKey', $this->config) ? $this->config['securityKey'] : ''; |
|
55 | 55 | if (!$securityKey || $securityKey === 'auto') { |
56 | - if (isset($_SERVER[ 'HTTP_HOST' ])) { |
|
57 | - $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ]))); |
|
56 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
57 | + $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER['HTTP_HOST']))); |
|
58 | 58 | } else { |
59 | 59 | $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); |
60 | 60 | } |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | */ |
74 | 74 | $tmp_dir = rtrim($tmp_dir, '/') . DIRECTORY_SEPARATOR; |
75 | 75 | |
76 | - if (empty($this->config[ 'path' ]) || !is_string($this->config[ 'path' ])) { |
|
76 | + if (empty($this->config['path']) || !is_string($this->config['path'])) { |
|
77 | 77 | $path = $tmp_dir; |
78 | 78 | } else { |
79 | - $path = rtrim($this->config[ 'path' ], '/') . DIRECTORY_SEPARATOR; |
|
79 | + $path = rtrim($this->config['path'], '/') . DIRECTORY_SEPARATOR; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | $path_suffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName(); |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | * return the temp dir |
92 | 92 | */ |
93 | 93 | if ($readonly === true) { |
94 | - if($this->config[ 'autoTmpFallback' ] && (!@file_exists($full_path) || !@is_writable($full_path))){ |
|
94 | + if ($this->config['autoTmpFallback'] && (!@file_exists($full_path) || !@is_writable($full_path))) { |
|
95 | 95 | return $full_path_tmp; |
96 | 96 | } |
97 | 97 | return $full_path; |
98 | - }else{ |
|
99 | - if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
|
98 | + } else { |
|
99 | + if (!isset($this->tmp[$full_path_hash]) || (!@file_exists($full_path) || !@is_writable($full_path))) { |
|
100 | 100 | if (!@file_exists($full_path)) { |
101 | 101 | @mkdir($full_path, $this->getDefaultChmod(), true); |
102 | - }else if (!@is_writable($full_path)) { |
|
103 | - if (!@chmod($full_path, $this->getDefaultChmod()) && $this->config[ 'autoTmpFallback' ]) |
|
102 | + } else if (!@is_writable($full_path)) { |
|
103 | + if (!@chmod($full_path, $this->getDefaultChmod()) && $this->config['autoTmpFallback']) |
|
104 | 104 | { |
105 | 105 | /** |
106 | 106 | * Switch back to tmp dir |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | throw new phpFastCacheIOException('Path "' . $full_path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'); |
123 | 123 | } |
124 | 124 | |
125 | - $this->tmp[ $full_path_hash ] = $full_path; |
|
126 | - $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config[ 'htaccess' ] : false); |
|
125 | + $this->tmp[$full_path_hash] = $full_path; |
|
126 | + $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config['htaccess'] : false); |
|
127 | 127 | } |
128 | 128 | } |
129 | 129 | |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function getDefaultChmod() |
181 | 181 | { |
182 | - if (!isset($this->config[ 'default_chmod' ]) || $this->config[ 'default_chmod' ] == '' || is_null($this->config[ 'default_chmod' ])) { |
|
182 | + if (!isset($this->config['default_chmod']) || $this->config['default_chmod'] == '' || is_null($this->config['default_chmod'])) { |
|
183 | 183 | return 0777; |
184 | 184 | } else { |
185 | - return $this->config[ 'default_chmod' ]; |
|
185 | + return $this->config['default_chmod']; |
|
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | if ($create === true) { |
213 | 213 | if (!is_writable($path)) { |
214 | 214 | try { |
215 | - if(!chmod($path, 0777)){ |
|
215 | + if (!chmod($path, 0777)) { |
|
216 | 216 | throw new phpFastCacheIOException('Chmod failed on : ' . $path); |
217 | 217 | } |
218 | 218 | } catch (phpFastCacheIOException $e) { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation); |
285 | 285 | |
286 | - if($secureFileManipulation){ |
|
286 | + if ($secureFileManipulation) { |
|
287 | 287 | $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5( |
288 | 288 | str_shuffle(uniqid($this->getDriverName(), false)) |
289 | 289 | . str_shuffle(uniqid($this->getDriverName(), false)) |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | flock($f, LOCK_UN); |
296 | 296 | fclose($f); |
297 | 297 | |
298 | - if(!rename($tmpFilename, $file)){ |
|
298 | + if (!rename($tmpFilename, $file)) { |
|
299 | 299 | throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
300 | 300 | } |
301 | - }else{ |
|
301 | + } else { |
|
302 | 302 | $f = fopen($file, 'w+'); |
303 | 303 | $octetWritten = fwrite($f, $data); |
304 | 304 | fclose($f); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | - * @return array |
|
238 | + * @return ExtendedCacheItemPoolInterface[] |
|
239 | 239 | */ |
240 | 240 | public static function getDefaultConfig() |
241 | 241 | { |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * @return array |
|
246 | + * @return string[] |
|
247 | 247 | */ |
248 | 248 | public static function getStaticSystemDrivers() |
249 | 249 | { |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
271 | - * @return array |
|
271 | + * @return string[] |
|
272 | 272 | */ |
273 | 273 | public static function getStaticAllDrivers() |
274 | 274 | { |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | try{ |
110 | 110 | self::$instances[ $instance ] = new $class($config); |
111 | 111 | self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
112 | - }catch(phpFastCacheDriverCheckException $e){ |
|
112 | + } catch(phpFastCacheDriverCheckException $e){ |
|
113 | 113 | $fallback = self::standardizeDriverName($config['fallback']); |
114 | 114 | if($fallback && $fallback !== $driver){ |
115 | 115 | $class = self::getNamespacePath() . $fallback . '\Driver'; |
116 | 116 | self::$instances[ $instance ] = new $class($config); |
117 | 117 | self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
118 | 118 | trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); |
119 | - }else{ |
|
119 | + } else{ |
|
120 | 120 | throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); |
121 | 121 | } |
122 | 122 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | self::$config = array_merge(self::$config, $name); |
230 | 230 | } else if (is_string($name)){ |
231 | 231 | self::$config[ $name ] = $value; |
232 | - }else{ |
|
232 | + } else{ |
|
233 | 233 | throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name'); |
234 | 234 | } |
235 | 235 | } |
@@ -64,95 +64,95 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * Specify if the item must provide detailed creation/modification dates |
66 | 66 | */ |
67 | - 'itemDetailedDate' => false, |
|
67 | + 'itemDetailedDate' => false, |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Automatically attempt to fallback to temporary directory |
71 | 71 | * if the cache fails to write on the specified directory |
72 | 72 | */ |
73 | - 'autoTmpFallback' => false, |
|
73 | + 'autoTmpFallback' => false, |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * Provide a secure file manipulation mechanism, |
77 | 77 | * on intensive usage the performance can be affected. |
78 | 78 | */ |
79 | - 'secureFileManipulation' => false, |
|
79 | + 'secureFileManipulation' => false, |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Ignore Symfony notice for Symfony project which |
83 | 83 | * do not makes use of PhpFastCache's Symfony Bundle |
84 | 84 | */ |
85 | - 'ignoreSymfonyNotice' => false, |
|
85 | + 'ignoreSymfonyNotice' => false, |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Default time-to-live in second |
89 | 89 | */ |
90 | - 'defaultTtl' => 900, |
|
90 | + 'defaultTtl' => 900, |
|
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Default key hash function |
94 | 94 | * (md5 by default) |
95 | 95 | */ |
96 | - 'defaultKeyHashFunction' => '', |
|
96 | + 'defaultKeyHashFunction' => '', |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * The securityKey that will be used |
100 | 100 | * to create sub-directory |
101 | 101 | * (Files-based drivers only) |
102 | 102 | */ |
103 | - 'securityKey' => 'auto', |
|
103 | + 'securityKey' => 'auto', |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Auto-generate .htaccess if it's missing |
107 | 107 | * (Files-based drivers only) |
108 | 108 | */ |
109 | - 'htaccess' => true, |
|
109 | + 'htaccess' => true, |
|
110 | 110 | |
111 | 111 | /** |
112 | 112 | * Default files chmod |
113 | 113 | * 0777 recommended |
114 | 114 | * (Files-based drivers only) |
115 | 115 | */ |
116 | - 'default_chmod' => 0777, |
|
116 | + 'default_chmod' => 0777, |
|
117 | 117 | |
118 | 118 | /** |
119 | 119 | * The path where we will writecache files |
120 | 120 | * default value if empty: sys_get_temp_dir() |
121 | 121 | * (Files-based drivers only) |
122 | 122 | */ |
123 | - 'path' => '', |
|
123 | + 'path' => '', |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * Driver fallback in case of failure. |
127 | 127 | * Caution, in case of failure an E_WARNING |
128 | 128 | * error will always be raised |
129 | 129 | */ |
130 | - 'fallback' => false, |
|
130 | + 'fallback' => false, |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Maximum size (bytes) of object store in memory |
134 | 134 | * (Memcache(d) drivers only) |
135 | 135 | */ |
136 | - 'limited_memory_each_object' => 4096, |
|
136 | + 'limited_memory_each_object' => 4096, |
|
137 | 137 | |
138 | 138 | /** |
139 | 139 | * Compress stored data, if the backend supports it |
140 | 140 | * (Memcache(d) drivers only) |
141 | 141 | */ |
142 | - 'compress_data' => false, |
|
142 | + 'compress_data' => false, |
|
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Prevent cache slams when |
146 | 146 | * making use of heavy cache |
147 | 147 | * items |
148 | 148 | */ |
149 | - 'preventCacheSlams' => false, |
|
149 | + 'preventCacheSlams' => false, |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Cache slams timeout |
153 | 153 | * in seconds |
154 | 154 | */ |
155 | - 'cacheSlamsTimeout' => 15, |
|
155 | + 'cacheSlamsTimeout' => 15, |
|
156 | 156 | |
157 | 157 | ]; |
158 | 158 | |
@@ -335,24 +335,24 @@ discard block |
||
335 | 335 | public static function getStaticSystemDrivers() |
336 | 336 | { |
337 | 337 | return [ |
338 | - 'Apc', |
|
339 | - 'Apcu', |
|
340 | - 'Cassandra', |
|
341 | - 'Couchbase', |
|
342 | - 'Couchdb', |
|
343 | - 'Devnull', |
|
344 | - 'Files', |
|
345 | - 'Leveldb', |
|
346 | - 'Memcache', |
|
347 | - 'Memcached', |
|
348 | - 'Memstatic', |
|
349 | - 'Mongodb', |
|
350 | - 'Predis', |
|
351 | - 'Redis', |
|
352 | - 'Ssdb', |
|
353 | - 'Sqlite', |
|
354 | - 'Wincache', |
|
355 | - 'Xcache', |
|
338 | + 'Apc', |
|
339 | + 'Apcu', |
|
340 | + 'Cassandra', |
|
341 | + 'Couchbase', |
|
342 | + 'Couchdb', |
|
343 | + 'Devnull', |
|
344 | + 'Files', |
|
345 | + 'Leveldb', |
|
346 | + 'Memcache', |
|
347 | + 'Memcached', |
|
348 | + 'Memstatic', |
|
349 | + 'Mongodb', |
|
350 | + 'Predis', |
|
351 | + 'Redis', |
|
352 | + 'Ssdb', |
|
353 | + 'Sqlite', |
|
354 | + 'Wincache', |
|
355 | + 'Xcache', |
|
356 | 356 | ]; |
357 | 357 | } |
358 | 358 | |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | public static function getStaticAllDrivers() |
363 | 363 | { |
364 | 364 | return array_merge(self::getStaticSystemDrivers(), [ |
365 | - 'Devtrue', |
|
366 | - 'Devfalse', |
|
367 | - 'Cookie', |
|
365 | + 'Devtrue', |
|
366 | + 'Devfalse', |
|
367 | + 'Cookie', |
|
368 | 368 | ]); |
369 | 369 | } |
370 | 370 |
@@ -187,32 +187,32 @@ discard block |
||
187 | 187 | } |
188 | 188 | |
189 | 189 | $instance = crc32($driver . serialize($config)); |
190 | - if (!isset(self::$instances[ $instance ])) { |
|
190 | + if (!isset(self::$instances[$instance])) { |
|
191 | 191 | $badPracticeOmeter[$driver] = 1; |
192 | - if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){ |
|
192 | + if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) { |
|
193 | 193 | trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE); |
194 | 194 | } |
195 | 195 | $class = self::getNamespacePath() . $driver . '\Driver'; |
196 | - try{ |
|
197 | - self::$instances[ $instance ] = new $class($config); |
|
198 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
199 | - }catch(phpFastCacheDriverCheckException $e){ |
|
196 | + try { |
|
197 | + self::$instances[$instance] = new $class($config); |
|
198 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
199 | + } catch (phpFastCacheDriverCheckException $e) { |
|
200 | 200 | $fallback = self::standardizeDriverName($config['fallback']); |
201 | - if($fallback && $fallback !== $driver){ |
|
201 | + if ($fallback && $fallback !== $driver) { |
|
202 | 202 | $class = self::getNamespacePath() . $fallback . '\Driver'; |
203 | - self::$instances[ $instance ] = new $class($config); |
|
204 | - self::$instances[ $instance ]->setEventManager(EventManager::getInstance()); |
|
203 | + self::$instances[$instance] = new $class($config); |
|
204 | + self::$instances[$instance]->setEventManager(EventManager::getInstance()); |
|
205 | 205 | trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING); |
206 | - }else{ |
|
206 | + } else { |
|
207 | 207 | throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e); |
208 | 208 | } |
209 | 209 | } |
210 | - } else if(++$badPracticeOmeter[$driver] >= 5){ |
|
210 | + } else if (++$badPracticeOmeter[$driver] >= 5) { |
|
211 | 211 | trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
212 | 212 | See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); |
213 | 213 | } |
214 | 214 | |
215 | - return self::$instances[ $instance ]; |
|
215 | + return self::$instances[$instance]; |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | */ |
274 | 274 | public static function __callStatic($name, $arguments) |
275 | 275 | { |
276 | - $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []); |
|
276 | + $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []); |
|
277 | 277 | |
278 | 278 | return self::getInstance($name, $options); |
279 | 279 | } |
@@ -314,9 +314,9 @@ discard block |
||
314 | 314 | { |
315 | 315 | if (is_array($name)) { |
316 | 316 | self::$config = array_merge(self::$config, $name); |
317 | - } else if (is_string($name)){ |
|
318 | - self::$config[ $name ] = $value; |
|
319 | - }else{ |
|
317 | + } else if (is_string($name)) { |
|
318 | + self::$config[$name] = $value; |
|
319 | + } else { |
|
320 | 320 | throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name'); |
321 | 321 | } |
322 | 322 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | */ |
376 | 376 | public static function standardizeDriverName($driverName) |
377 | 377 | { |
378 | - if(!is_string($driverName)){ |
|
378 | + if (!is_string($driverName)) { |
|
379 | 379 | throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName))); |
380 | 380 | } |
381 | 381 | return ucfirst(strtolower(trim($driverName))); |
@@ -390,70 +390,70 @@ discard block |
||
390 | 390 | protected static function validateConfig(array $config) |
391 | 391 | { |
392 | 392 | foreach ($config as $configName => $configValue) { |
393 | - switch($configName) |
|
393 | + switch ($configName) |
|
394 | 394 | { |
395 | 395 | case 'itemDetailedDate': |
396 | - if(!is_bool($configValue)){ |
|
396 | + if (!is_bool($configValue)) { |
|
397 | 397 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
398 | 398 | } |
399 | 399 | break; |
400 | 400 | case 'autoTmpFallback': |
401 | - if(!is_bool($configValue)){ |
|
401 | + if (!is_bool($configValue)) { |
|
402 | 402 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
403 | 403 | } |
404 | 404 | break; |
405 | 405 | case 'secureFileManipulation': |
406 | - if(!is_bool($configValue)){ |
|
406 | + if (!is_bool($configValue)) { |
|
407 | 407 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
408 | 408 | } |
409 | 409 | break; |
410 | 410 | case 'ignoreSymfonyNotice': |
411 | - if(!is_bool($configValue)){ |
|
411 | + if (!is_bool($configValue)) { |
|
412 | 412 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
413 | 413 | } |
414 | 414 | break; |
415 | 415 | case 'defaultTtl': |
416 | - if(!is_numeric($configValue)){ |
|
416 | + if (!is_numeric($configValue)) { |
|
417 | 417 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric"); |
418 | 418 | } |
419 | 419 | break; |
420 | 420 | case 'defaultKeyHashFunction': |
421 | - if(!is_string($configValue) && !function_exists($configValue)){ |
|
421 | + if (!is_string($configValue) && !function_exists($configValue)) { |
|
422 | 422 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string"); |
423 | 423 | } |
424 | 424 | break; |
425 | 425 | case 'securityKey': |
426 | - if(!is_string($configValue)){ |
|
426 | + if (!is_string($configValue)) { |
|
427 | 427 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string"); |
428 | 428 | } |
429 | 429 | break; |
430 | 430 | case 'htaccess': |
431 | - if(!is_bool($configValue)){ |
|
431 | + if (!is_bool($configValue)) { |
|
432 | 432 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
433 | 433 | } |
434 | 434 | break; |
435 | 435 | case 'default_chmod': |
436 | - if(!is_int($configValue)){ |
|
436 | + if (!is_int($configValue)) { |
|
437 | 437 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer"); |
438 | 438 | } |
439 | 439 | break; |
440 | 440 | case 'path': |
441 | - if(!is_string($configValue)){ |
|
441 | + if (!is_string($configValue)) { |
|
442 | 442 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string"); |
443 | 443 | } |
444 | 444 | break; |
445 | 445 | case 'fallback': |
446 | - if(!is_bool($configValue)){ |
|
446 | + if (!is_bool($configValue)) { |
|
447 | 447 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
448 | 448 | } |
449 | 449 | break; |
450 | 450 | case 'limited_memory_each_object': |
451 | - if(!is_int($configValue)){ |
|
451 | + if (!is_int($configValue)) { |
|
452 | 452 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer"); |
453 | 453 | } |
454 | 454 | break; |
455 | 455 | case 'compress_data': |
456 | - if(!is_bool($configValue)){ |
|
456 | + if (!is_bool($configValue)) { |
|
457 | 457 | throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean"); |
458 | 458 | } |
459 | 459 | break; |
@@ -63,8 +63,8 @@ |
||
63 | 63 | { |
64 | 64 | try { |
65 | 65 | $cacheItem = $this->internalCacheInstance |
66 | - ->getItem($key) |
|
67 | - ->set($value); |
|
66 | + ->getItem($key) |
|
67 | + ->set($value); |
|
68 | 68 | if (is_int($ttl) || $ttl instanceof \DateInterval) { |
69 | 69 | $cacheItem->expiresAfter($ttl); |
70 | 70 | } |
@@ -110,7 +110,7 @@ |
||
110 | 110 | public function getMultiple($keys, $default = null) |
111 | 111 | { |
112 | 112 | try { |
113 | - return array_map(function (ExtendedCacheItemInterface $item) { |
|
113 | + return array_map(function(ExtendedCacheItemInterface $item) { |
|
114 | 114 | return $item->get(); |
115 | 115 | }, $this->internalCacheInstance->getItems($keys)); |
116 | 116 | } catch (phpFastCacheInvalidArgumentException $e) { |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | /** |
239 | 239 | * @param \Psr\Cache\CacheItemInterface $item |
240 | - * @return mixed |
|
240 | + * @return boolean |
|
241 | 241 | * @throws phpFastCacheInvalidArgumentException |
242 | 242 | * @throws \RuntimeException |
243 | 243 | */ |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * @return mixed|null |
|
297 | + * @return boolean |
|
298 | 298 | * @throws phpFastCacheInvalidArgumentException |
299 | 299 | */ |
300 | 300 | public function commit() |
@@ -148,9 +148,9 @@ |
||
148 | 148 | * Reset the Item |
149 | 149 | */ |
150 | 150 | $item->set(null) |
151 | - ->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])) |
|
152 | - ->setHit(false) |
|
153 | - ->setTags([]); |
|
151 | + ->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])) |
|
152 | + ->setHit(false) |
|
153 | + ->setTags([]); |
|
154 | 154 | if($this->config['itemDetailedDate']){ |
155 | 155 | |
156 | 156 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function getItem($key) |
63 | 63 | { |
64 | 64 | if (is_string($key)) { |
65 | - if (preg_match('~([' . preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)){ |
|
65 | + if (preg_match('~([' . preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) { |
|
66 | 66 | throw new phpFastCacheInvalidArgumentException('Unsupported key character detected: "' . $matches[1] . '". Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers'); |
67 | 67 | } |
68 | 68 | if (!array_key_exists($key, $this->itemInstances)) { |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | $driverArray = $this->driverRead($item); |
82 | 82 | |
83 | 83 | if ($driverArray) { |
84 | - if(!is_array($driverArray)){ |
|
84 | + if (!is_array($driverArray)) { |
|
85 | 85 | throw new phpFastCacheCoreException(sprintf('The driverRead method returned an unexpected variable type: %s', gettype($driverArray))); |
86 | 86 | } |
87 | 87 | $driverData = $this->driverUnwrapData($driverArray); |
88 | 88 | |
89 | - if($this->getConfig()[ 'preventCacheSlams' ]){ |
|
90 | - while($driverData instanceof ItemBatch) { |
|
91 | - if($driverData->getItemDate()->getTimestamp() + $this->getConfig()[ 'cacheSlamsTimeout' ] < time()){ |
|
89 | + if ($this->getConfig()['preventCacheSlams']) { |
|
90 | + while ($driverData instanceof ItemBatch) { |
|
91 | + if ($driverData->getItemDate()->getTimestamp() + $this->getConfig()['cacheSlamsTimeout'] < time()) { |
|
92 | 92 | /** |
93 | 93 | * The timeout has been reached |
94 | 94 | * Consider that the batch has |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $item->set($driverData); |
121 | 121 | $item->expiresAt($this->driverUnwrapEdate($driverArray)); |
122 | 122 | |
123 | - if($this->config['itemDetailedDate']){ |
|
123 | + if ($this->config['itemDetailedDate']) { |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * If the itemDetailedDate has been |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | * Reset the Item |
149 | 149 | */ |
150 | 150 | $item->set(null) |
151 | - ->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])) |
|
151 | + ->expiresAfter(abs((int) $this->getConfig()['defaultTtl'])) |
|
152 | 152 | ->setHit(false) |
153 | 153 | ->setTags([]); |
154 | - if($this->config['itemDetailedDate']){ |
|
154 | + if ($this->config['itemDetailedDate']) { |
|
155 | 155 | |
156 | 156 | /** |
157 | 157 | * If the itemDetailedDate has been |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | } else { |
165 | 165 | $item->setHit(true); |
166 | 166 | } |
167 | - }else{ |
|
168 | - $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])); |
|
167 | + } else { |
|
168 | + $item->expiresAfter(abs((int) $this->getConfig()['defaultTtl'])); |
|
169 | 169 | } |
170 | 170 | } |
171 | 171 | } |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | * @param $this ExtendedCacheItemPoolInterface |
179 | 179 | * @param $this ExtendedCacheItemInterface |
180 | 180 | */ |
181 | - $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[ $key ]); |
|
181 | + $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[$key]); |
|
182 | 182 | |
183 | - return $this->itemInstances[ $key ]; |
|
183 | + return $this->itemInstances[$key]; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | public function setItem(CacheItemInterface $item) |
192 | 192 | { |
193 | 193 | if ($this->getClassNamespace() . '\\Item' === get_class($item)) { |
194 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
194 | + $this->itemInstances[$item->getKey()] = $item; |
|
195 | 195 | |
196 | 196 | return $this; |
197 | 197 | } else { |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | { |
209 | 209 | $collection = []; |
210 | 210 | foreach ($keys as $key) { |
211 | - $collection[ $key ] = $this->getItem($key); |
|
211 | + $collection[$key] = $this->getItem($key); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | return $collection; |
@@ -305,8 +305,8 @@ discard block |
||
305 | 305 | * @var ExtendedCacheItemInterface $item |
306 | 306 | */ |
307 | 307 | if (!array_key_exists($item->getKey(), $this->itemInstances)) { |
308 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
309 | - } else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
308 | + $this->itemInstances[$item->getKey()] = $item; |
|
309 | + } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
310 | 310 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
311 | 311 | } |
312 | 312 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | $this->eventManager->dispatch('CacheSaveItem', $this, $item); |
319 | 319 | |
320 | 320 | |
321 | - if($this->getConfig()[ 'preventCacheSlams' ]){ |
|
321 | + if ($this->getConfig()['preventCacheSlams']) { |
|
322 | 322 | /** |
323 | 323 | * @var $itemBatch ExtendedCacheItemInterface |
324 | 324 | */ |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | $itemBatch = $class->newInstanceArgs([$this, $item->getKey()]); |
327 | 327 | $itemBatch->setEventManager($this->eventManager) |
328 | 328 | ->set(new ItemBatch($item->getKey(), new \DateTime())) |
329 | - ->expiresAfter($this->getConfig()[ 'cacheSlamsTimeout' ]); |
|
329 | + ->expiresAfter($this->getConfig()['cacheSlamsTimeout']); |
|
330 | 330 | |
331 | 331 | /** |
332 | 332 | * To avoid SPL mismatches |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | public function saveDeferred(CacheItemInterface $item) |
359 | 359 | { |
360 | 360 | if (!array_key_exists($item->getKey(), $this->itemInstances)) { |
361 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
362 | - }else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
361 | + $this->itemInstances[$item->getKey()] = $item; |
|
362 | + } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
363 | 363 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
364 | 364 | } |
365 | 365 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | */ |
371 | 371 | $this->eventManager->dispatch('CacheSaveDeferredItem', $this, $item); |
372 | 372 | |
373 | - return $this->deferredList[ $item->getKey() ] = $item; |
|
373 | + return $this->deferredList[$item->getKey()] = $item; |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | foreach ($this->deferredList as $key => $item) { |
391 | 391 | $result = $this->save($item); |
392 | 392 | if ($return !== false) { |
393 | - unset($this->deferredList[ $key ]); |
|
393 | + unset($this->deferredList[$key]); |
|
394 | 394 | $return = $result; |
395 | 395 | } |
396 | 396 | } |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | } else { |
165 | 165 | $item->setHit(true); |
166 | 166 | } |
167 | - }else{ |
|
167 | + } else{ |
|
168 | 168 | $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])); |
169 | 169 | } |
170 | 170 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | { |
360 | 360 | if (!array_key_exists($item->getKey(), $this->itemInstances)) { |
361 | 361 | $this->itemInstances[ $item->getKey() ] = $item; |
362 | - }else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
362 | + } else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){ |
|
363 | 363 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
364 | 364 | } |
365 | 365 |
@@ -38,6 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @inheritdoc |
41 | + * @param string $tagName |
|
41 | 42 | */ |
42 | 43 | public function getItemsByTag($tagName) |
43 | 44 | { |
@@ -408,7 +409,7 @@ discard block |
||
408 | 409 | |
409 | 410 | /** |
410 | 411 | * @internal This method de-register an item from $this->itemInstances |
411 | - * @param CacheItemInterface|string $item |
|
412 | + * @param CacheItemInterface $item |
|
412 | 413 | * @throws phpFastCacheInvalidArgumentException |
413 | 414 | */ |
414 | 415 | protected function deregisterItem($item) |
@@ -14,7 +14,6 @@ |
||
14 | 14 | |
15 | 15 | namespace phpFastCache\Core\Pool; |
16 | 16 | |
17 | -use InvalidArgumentException; |
|
18 | 17 | use phpFastCache\Core\Item\ExtendedCacheItemInterface; |
19 | 18 | use phpFastCache\EventManager; |
20 | 19 | use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
33 | 33 | { |
34 | - $callback = function (CacheItemInterface $item) { |
|
34 | + $callback = function(CacheItemInterface $item) { |
|
35 | 35 | return $item->get(); |
36 | 36 | }; |
37 | 37 | return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth); |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | if (is_string($tagName)) { |
46 | 46 | $driverResponse = $this->getItem($this->getTagKey($tagName)); |
47 | 47 | if ($driverResponse->isHit()) { |
48 | - $items = (array)$driverResponse->get(); |
|
48 | + $items = (array) $driverResponse->get(); |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * getItems() may provides expired item(s) |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * #headache |
59 | 59 | */ |
60 | - return array_filter($this->getItems(array_unique(array_keys($items))), function (ExtendedCacheItemInterface $item) { |
|
60 | + return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item) { |
|
61 | 61 | return $item->isHit(); |
62 | 62 | }); |
63 | 63 | } else { |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | { |
76 | 76 | $items = []; |
77 | 77 | foreach (array_unique($tagNames) as $tagName) { |
78 | - if(is_string($tagName)){ |
|
78 | + if (is_string($tagName)) { |
|
79 | 79 | $items = array_merge($items, $this->getItemsByTag($tagName)); |
80 | - }else{ |
|
80 | + } else { |
|
81 | 81 | throw new phpFastCacheInvalidArgumentException('$tagName must be a a string'); |
82 | 82 | } |
83 | 83 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | foreach ($items as $key => $item) { |
97 | 97 | if (array_diff($tagNames, $item->getTags())) { |
98 | - unset($items[ $key ]); |
|
98 | + unset($items[$key]); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
110 | 110 | { |
111 | - $callback = function (CacheItemInterface $item) { |
|
111 | + $callback = function(CacheItemInterface $item) { |
|
112 | 112 | return $item->get(); |
113 | 113 | }; |
114 | 114 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | */ |
380 | 380 | public function detachItem(CacheItemInterface $item) |
381 | 381 | { |
382 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
382 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
383 | 383 | $this->deregisterItem($item); |
384 | 384 | } |
385 | 385 | } |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | */ |
400 | 400 | public function attachItem(CacheItemInterface $item) |
401 | 401 | { |
402 | - if (isset($this->itemInstances[ $item->getKey() ]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
402 | + if (isset($this->itemInstances[$item->getKey()]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
403 | 403 | throw new phpFastCacheLogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.'); |
404 | 404 | } else { |
405 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
405 | + $this->itemInstances[$item->getKey()] = $item; |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | protected function deregisterItem($item) |
416 | 416 | { |
417 | 417 | if ($item instanceof CacheItemInterface) { |
418 | - unset($this->itemInstances[ $item->getKey() ]); |
|
418 | + unset($this->itemInstances[$item->getKey()]); |
|
419 | 419 | |
420 | 420 | } else if (is_string($item)) { |
421 | - unset($this->itemInstances[ $item ]); |
|
421 | + unset($this->itemInstances[$item]); |
|
422 | 422 | } else { |
423 | 423 | throw new phpFastCacheInvalidArgumentException('Invalid type for $item variable'); |
424 | 424 | } |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function isAttached(CacheItemInterface $item) |
439 | 439 | { |
440 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
441 | - return spl_object_hash($item) === spl_object_hash($this->itemInstances[ $item->getKey() ]); |
|
440 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
441 | + return spl_object_hash($item) === spl_object_hash($this->itemInstances[$item->getKey()]); |
|
442 | 442 | } |
443 | 443 | return null; |
444 | 444 | } |
@@ -458,8 +458,8 @@ discard block |
||
458 | 458 | */ |
459 | 459 | public function saveMultiple(...$items) |
460 | 460 | { |
461 | - if (isset($items[ 0 ]) && is_array($items[ 0 ])) { |
|
462 | - foreach ($items[ 0 ] as $item) { |
|
461 | + if (isset($items[0]) && is_array($items[0])) { |
|
462 | + foreach ($items[0] as $item) { |
|
463 | 463 | $this->save($item); |
464 | 464 | } |
465 | 465 | return true; |
@@ -77,7 +77,7 @@ |
||
77 | 77 | foreach (array_unique($tagNames) as $tagName) { |
78 | 78 | if(is_string($tagName)){ |
79 | 79 | $items = array_merge($items, $this->getItemsByTag($tagName)); |
80 | - }else{ |
|
80 | + } else{ |
|
81 | 81 | throw new phpFastCacheInvalidArgumentException('$tagName must be a a string'); |
82 | 82 | } |
83 | 83 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | /** |
64 | 64 | * @param \Psr\Cache\CacheItemInterface $item |
65 | - * @return mixed |
|
65 | + * @return boolean |
|
66 | 66 | * @throws phpFastCacheInvalidArgumentException |
67 | 67 | */ |
68 | 68 | protected function driverWrite(CacheItemInterface $item) |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * been really upserted |
107 | 107 | */ |
108 | 108 | return $result instanceof Cassandra\Rows; |
109 | - }catch(\Cassandra\Exception\InvalidArgumentException $e){ |
|
109 | + } catch(\Cassandra\Exception\InvalidArgumentException $e){ |
|
110 | 110 | throw new phpFastCacheInvalidArgumentException($e, 0, $e); |
111 | 111 | } |
112 | 112 | } else { |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | if($results instanceof Cassandra\Rows && $results->count() === 1){ |
136 | 136 | return $this->decode($results->first()['cache_data']); |
137 | - }else{ |
|
137 | + } else{ |
|
138 | 138 | return null; |
139 | 139 | } |
140 | 140 | } catch (Cassandra\Exception $e) { |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | if(!empty($this->config['ssl']['enabled'])){ |
220 | 220 | if(!empty($this->config['ssl']['verify'])){ |
221 | 221 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
222 | - }else{ |
|
222 | + } else{ |
|
223 | 223 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); |
224 | 224 | } |
225 | 225 |
@@ -75,16 +75,16 @@ discard block |
||
75 | 75 | try{ |
76 | 76 | $cacheData = $this->encode($this->driverPreWrap($item)); |
77 | 77 | $options = new Cassandra\ExecutionOptions([ |
78 | - 'arguments' => [ |
|
78 | + 'arguments' => [ |
|
79 | 79 | 'cache_uuid' => new Cassandra\Uuid(), |
80 | 80 | 'cache_id' => $item->getKey(), |
81 | 81 | 'cache_data' => $cacheData, |
82 | 82 | 'cache_creation_date' => new Cassandra\Timestamp((new \DateTime())->getTimestamp()), |
83 | 83 | 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()), |
84 | 84 | 'cache_length' => strlen($cacheData) |
85 | - ], |
|
86 | - 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
87 | - 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL |
|
85 | + ], |
|
86 | + 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
87 | + 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL |
|
88 | 88 | ]); |
89 | 89 | |
90 | 90 | $query = sprintf('INSERT INTO %s.%s |
@@ -122,13 +122,13 @@ discard block |
||
122 | 122 | { |
123 | 123 | try { |
124 | 124 | $options = new Cassandra\ExecutionOptions([ |
125 | - 'arguments' => ['cache_id' => $item->getKey()], |
|
126 | - 'page_size' => 1 |
|
125 | + 'arguments' => ['cache_id' => $item->getKey()], |
|
126 | + 'page_size' => 1 |
|
127 | 127 | ]); |
128 | 128 | $query = sprintf( |
129 | - 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
130 | - self::CASSANDRA_KEY_SPACE, |
|
131 | - self::CASSANDRA_TABLE |
|
129 | + 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
130 | + self::CASSANDRA_KEY_SPACE, |
|
131 | + self::CASSANDRA_TABLE |
|
132 | 132 | ); |
133 | 133 | $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
134 | 134 | |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | if ($item instanceof Item) { |
156 | 156 | try { |
157 | 157 | $options = new Cassandra\ExecutionOptions([ |
158 | - 'arguments' => [ |
|
158 | + 'arguments' => [ |
|
159 | 159 | 'cache_id' => $item->getKey(), |
160 | - ], |
|
160 | + ], |
|
161 | 161 | ]); |
162 | 162 | $result = $this->instance->execute(new Cassandra\SimpleStatement(sprintf( |
163 | - 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
164 | - self::CASSANDRA_KEY_SPACE, |
|
165 | - self::CASSANDRA_TABLE |
|
163 | + 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
164 | + self::CASSANDRA_KEY_SPACE, |
|
165 | + self::CASSANDRA_TABLE |
|
166 | 166 | )), $options); |
167 | 167 | |
168 | 168 | /** |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | { |
187 | 187 | try { |
188 | 188 | $this->instance->execute(new Cassandra\SimpleStatement(sprintf( |
189 | - 'TRUNCATE %s.%s;', |
|
190 | - self::CASSANDRA_KEY_SPACE, self::CASSANDRA_TABLE |
|
189 | + 'TRUNCATE %s.%s;', |
|
190 | + self::CASSANDRA_KEY_SPACE, self::CASSANDRA_TABLE |
|
191 | 191 | ))); |
192 | 192 | |
193 | 193 | return true; |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
214 | 214 | |
215 | 215 | $clusterBuilder = Cassandra::cluster() |
216 | - ->withContactPoints($host) |
|
217 | - ->withPort($port); |
|
216 | + ->withContactPoints($host) |
|
217 | + ->withPort($port); |
|
218 | 218 | |
219 | 219 | if(!empty($this->config['ssl']['enabled'])){ |
220 | 220 | if(!empty($this->config['ssl']['verify'])){ |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | */ |
243 | 243 | |
244 | 244 | $this->instance->execute(new Cassandra\SimpleStatement(sprintf( |
245 | - "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
246 | - self::CASSANDRA_KEY_SPACE |
|
245 | + "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
246 | + self::CASSANDRA_KEY_SPACE |
|
247 | 247 | ))); |
248 | 248 | $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE))); |
249 | 249 | $this->instance->execute(new Cassandra\SimpleStatement(sprintf(' |
@@ -290,15 +290,15 @@ discard block |
||
290 | 290 | public function getStats() |
291 | 291 | { |
292 | 292 | $result = $this->instance->execute(new Cassandra\SimpleStatement(sprintf( |
293 | - 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
294 | - self::CASSANDRA_KEY_SPACE, |
|
295 | - self::CASSANDRA_TABLE |
|
293 | + 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
294 | + self::CASSANDRA_KEY_SPACE, |
|
295 | + self::CASSANDRA_TABLE |
|
296 | 296 | ))); |
297 | 297 | |
298 | 298 | return (new DriverStatistic()) |
299 | - ->setSize($result->first()[ 'cache_size' ]) |
|
300 | - ->setRawData([]) |
|
301 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
302 | - ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
299 | + ->setSize($result->first()[ 'cache_size' ]) |
|
300 | + ->setRawData([]) |
|
301 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
302 | + ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | \ No newline at end of file |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * Check for Cross-Driver type confusion |
73 | 73 | */ |
74 | 74 | if ($item instanceof Item) { |
75 | - try{ |
|
75 | + try { |
|
76 | 76 | $cacheData = $this->encode($this->driverPreWrap($item)); |
77 | 77 | $options = new Cassandra\ExecutionOptions([ |
78 | 78 | 'arguments' => [ |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * been really upserted |
107 | 107 | */ |
108 | 108 | return $result instanceof Cassandra\Rows; |
109 | - }catch(\Cassandra\Exception\InvalidArgumentException $e){ |
|
109 | + } catch (\Cassandra\Exception\InvalidArgumentException $e) { |
|
110 | 110 | throw new phpFastCacheInvalidArgumentException($e, 0, $e); |
111 | 111 | } |
112 | 112 | } else { |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | ); |
133 | 133 | $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
134 | 134 | |
135 | - if($results instanceof Cassandra\Rows && $results->count() === 1){ |
|
135 | + if ($results instanceof Cassandra\Rows && $results->count() === 1) { |
|
136 | 136 | return $this->decode($results->first()['cache_data']); |
137 | - }else{ |
|
137 | + } else { |
|
138 | 138 | return null; |
139 | 139 | } |
140 | 140 | } catch (Cassandra\Exception $e) { |
@@ -206,20 +206,20 @@ discard block |
||
206 | 206 | if ($this->instance instanceof CassandraSession) { |
207 | 207 | throw new phpFastCacheLogicException('Already connected to Couchbase server'); |
208 | 208 | } else { |
209 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
210 | - $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : 9042; |
|
211 | - $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 2; |
|
212 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
213 | - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
209 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
210 | + $port = isset($this->config['port']) ? $this->config['port'] : 9042; |
|
211 | + $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 2; |
|
212 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
213 | + $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
214 | 214 | |
215 | 215 | $clusterBuilder = Cassandra::cluster() |
216 | 216 | ->withContactPoints($host) |
217 | 217 | ->withPort($port); |
218 | 218 | |
219 | - if(!empty($this->config['ssl']['enabled'])){ |
|
220 | - if(!empty($this->config['ssl']['verify'])){ |
|
219 | + if (!empty($this->config['ssl']['enabled'])) { |
|
220 | + if (!empty($this->config['ssl']['verify'])) { |
|
221 | 221 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
222 | - }else{ |
|
222 | + } else { |
|
223 | 223 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); |
224 | 224 | } |
225 | 225 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | $clusterBuilder->withConnectTimeout($timeout); |
230 | 230 | |
231 | - if($username){ |
|
231 | + if ($username) { |
|
232 | 232 | $clusterBuilder->withCredentials($username, $password); |
233 | 233 | } |
234 | 234 | |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | ))); |
297 | 297 | |
298 | 298 | return (new DriverStatistic()) |
299 | - ->setSize($result->first()[ 'cache_size' ]) |
|
299 | + ->setSize($result->first()['cache_size']) |
|
300 | 300 | ->setRawData([]) |
301 | 301 | ->setData(implode(', ', array_keys($this->itemInstances))) |
302 | 302 | ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | |
61 | 61 | /** |
62 | 62 | * @param \Psr\Cache\CacheItemInterface $item |
63 | - * @return mixed |
|
63 | + * @return boolean |
|
64 | 64 | * @throws phpFastCacheInvalidArgumentException |
65 | 65 | */ |
66 | 66 | protected function driverWrite(CacheItemInterface $item) |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | /** |
147 | 147 | * @param string $optionName |
148 | 148 | * @param mixed $optionValue |
149 | - * @return bool |
|
149 | + * @return boolean|null |
|
150 | 150 | * @throws phpFastCacheInvalidArgumentException |
151 | 151 | */ |
152 | 152 | public static function isValidOption($optionName, $optionValue) |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
182 | - * @return array |
|
182 | + * @return string[] |
|
183 | 183 | */ |
184 | 184 | public static function getValidOptions() |
185 | 185 | { |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | - * @return array |
|
190 | + * @return string[] |
|
191 | 191 | */ |
192 | 192 | public static function getRequiredOptions() |
193 | 193 | { |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | public function dispatch($eventName, ...$args) |
70 | 70 | { |
71 | 71 | $eventName = 'on' . ucfirst($eventName); |
72 | - if(array_key_exists($eventName, $this->events)){ |
|
73 | - foreach ($this->events[ $eventName ] as $event) { |
|
72 | + if (array_key_exists($eventName, $this->events)) { |
|
73 | + foreach ($this->events[$eventName] as $event) { |
|
74 | 74 | call_user_func_array($event, $args); |
75 | 75 | } |
76 | 76 | } |
@@ -84,17 +84,17 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function __call($name, $arguments) |
86 | 86 | { |
87 | - if(strpos($name, 'on') === 0){ |
|
88 | - if(is_callable($arguments[0])){ |
|
89 | - if(isset($arguments[1]) && is_string($arguments[0])){ |
|
87 | + if (strpos($name, 'on') === 0) { |
|
88 | + if (is_callable($arguments[0])) { |
|
89 | + if (isset($arguments[1]) && is_string($arguments[0])) { |
|
90 | 90 | $this->events[$name][$arguments[1]] = $arguments[0]; |
91 | - }else { |
|
91 | + } else { |
|
92 | 92 | $this->events[$name][] = $arguments[0]; |
93 | 93 | } |
94 | - }else{ |
|
94 | + } else { |
|
95 | 95 | throw new phpFastCacheInvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
96 | 96 | } |
97 | - }else{ |
|
97 | + } else { |
|
98 | 98 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
99 | 99 | } |
100 | 100 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function unbindEventCallback($eventName, $callbackName) |
108 | 108 | { |
109 | - if(isset($this->events[$eventName][$callbackName])){ |
|
109 | + if (isset($this->events[$eventName][$callbackName])) { |
|
110 | 110 | unset($this->events[$eventName][$callbackName]); |
111 | 111 | return true; |
112 | 112 | } |
@@ -88,13 +88,13 @@ |
||
88 | 88 | if(is_callable($arguments[0])){ |
89 | 89 | if(isset($arguments[1]) && is_string($arguments[0])){ |
90 | 90 | $this->events[$name][$arguments[1]] = $arguments[0]; |
91 | - }else { |
|
91 | + } else { |
|
92 | 92 | $this->events[$name][] = $arguments[0]; |
93 | 93 | } |
94 | - }else{ |
|
94 | + } else{ |
|
95 | 95 | throw new phpFastCacheInvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
96 | 96 | } |
97 | - }else{ |
|
97 | + } else{ |
|
98 | 98 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
99 | 99 | } |
100 | 100 | } |
@@ -43,7 +43,7 @@ |
||
43 | 43 | $this->driver->setItem($this); |
44 | 44 | } else { |
45 | 45 | throw new phpFastCacheInvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', |
46 | - gettype($key))); |
|
46 | + gettype($key))); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 |