@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $config = self::validateConfig($config); |
| 177 | 177 | $driver = self::standardizeDriverName($driver); |
| 178 | 178 | |
| 179 | - $instanceId = $instanceId ?: md5($driver . \serialize(\array_filter($config->toArray(), static function ($val){ |
|
| 179 | + $instanceId = $instanceId ?: md5($driver . \serialize(\array_filter($config->toArray(), static function($val) { |
|
| 180 | 180 | return !\is_callable($val); |
| 181 | 181 | }))); |
| 182 | 182 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | $found = false; |
| 320 | 320 | self::$instances = \array_filter( |
| 321 | 321 | \array_map( |
| 322 | - static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) { |
|
| 322 | + static function(ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found) { |
|
| 323 | 323 | if (\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)) { |
| 324 | 324 | $found = true; |
| 325 | 325 | return null; |
@@ -95,8 +95,7 @@ discard block |
||
| 95 | 95 | /** |
| 96 | 96 | * CacheManager constructor. |
| 97 | 97 | */ |
| 98 | - final protected function __construct() |
|
| 99 | - { |
|
| 98 | + final protected function __construct() { |
|
| 100 | 99 | // The cache manager is not meant to be instantiated |
| 101 | 100 | } |
| 102 | 101 | |
@@ -188,10 +187,12 @@ discard block |
||
| 188 | 187 | $configClass = $driverClass::getConfigClass(); |
| 189 | 188 | self::$instances[$instanceId] = new $driverClass(new $configClass($config->toArray()), $instanceId); |
| 190 | 189 | self::$instances[$instanceId]->setEventManager(EventManager::getInstance()); |
| 191 | - } else { |
|
| 190 | + } |
|
| 191 | + else { |
|
| 192 | 192 | throw new PhpfastcacheDriverNotFoundException(sprintf('The driver "%s" does not exists', $driver)); |
| 193 | 193 | } |
| 194 | - } else { |
|
| 194 | + } |
|
| 195 | + else { |
|
| 195 | 196 | if (self::$badPracticeOmeter[$driver] >= 2) { |
| 196 | 197 | \trigger_error( |
| 197 | 198 | '[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
@@ -216,7 +217,8 @@ discard block |
||
| 216 | 217 | { |
| 217 | 218 | if ($config === null) { |
| 218 | 219 | $config = self::getDefaultConfig(); |
| 219 | - } else { |
|
| 220 | + } |
|
| 221 | + else { |
|
| 220 | 222 | if (!($config instanceof ConfigurationOption)) { |
| 221 | 223 | throw new PhpfastcacheInvalidArgumentException(\sprintf('Unsupported config type: %s', \gettype($config))); |
| 222 | 224 | } |
@@ -271,10 +273,12 @@ discard block |
||
| 271 | 273 | { |
| 272 | 274 | if (!empty(self::$driverCustoms[$driverName])) { |
| 273 | 275 | $driverClass = self::$driverCustoms[$driverName]; |
| 274 | - } else { |
|
| 276 | + } |
|
| 277 | + else { |
|
| 275 | 278 | if (!empty(self::$driverOverrides[$driverName])) { |
| 276 | 279 | $driverClass = self::$driverOverrides[$driverName]; |
| 277 | - } else { |
|
| 280 | + } |
|
| 281 | + else { |
|
| 278 | 282 | $driverClass = self::getNamespacePath() . $driverName . '\Driver'; |
| 279 | 283 | } |
| 280 | 284 | } |
@@ -152,7 +152,7 @@ |
||
| 152 | 152 | } |
| 153 | 153 | try { |
| 154 | 154 | return \array_map( |
| 155 | - static function (ExtendedCacheItemInterface $item) use ($default) { |
|
| 155 | + static function(ExtendedCacheItemInterface $item) use ($default) { |
|
| 156 | 156 | return $item->isHit() ? $item->get() : $default; |
| 157 | 157 | }, |
| 158 | 158 | $this->internalCacheInstance->getItems($keys) |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException |
| 54 | 54 | * @throws \ReflectionException |
| 55 | 55 | */ |
| 56 | - public function __construct($driver, ConfigurationOptionInterface $config = null) |
|
| 57 | - { |
|
| 56 | + public function __construct($driver, ConfigurationOptionInterface $config = null) { |
|
| 58 | 57 | if ($driver instanceof ExtendedCacheItemPoolInterface) { |
| 59 | 58 | if ($config !== null) { |
| 60 | 59 | throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); |
| 61 | 60 | } |
| 62 | 61 | $this->internalCacheInstance = $driver; |
| 63 | - } else { |
|
| 62 | + } |
|
| 63 | + else { |
|
| 64 | 64 | $this->internalCacheInstance = CacheManager::getInstance($driver, $config); |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -72,8 +72,7 @@ discard block |
||
| 72 | 72 | * @throws PhpfastcacheSimpleCacheException |
| 73 | 73 | * @throws \Psr\Cache\InvalidArgumentException |
| 74 | 74 | */ |
| 75 | - public function get($key, $default = null) |
|
| 76 | - { |
|
| 75 | + public function get($key, $default = null) { |
|
| 77 | 76 | try { |
| 78 | 77 | $cacheItem = $this->internalCacheInstance->getItem($key); |
| 79 | 78 | if (!$cacheItem->isExpired() && $cacheItem->get() !== null) { |
@@ -81,7 +80,8 @@ discard block |
||
| 81 | 80 | } |
| 82 | 81 | |
| 83 | 82 | return $default; |
| 84 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 83 | + } |
|
| 84 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 85 | 85 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -102,11 +102,13 @@ discard block |
||
| 102 | 102 | ->set($value); |
| 103 | 103 | if (\is_int($ttl) && $ttl <= 0) { |
| 104 | 104 | $cacheItem->expiresAt((new DateTime('@0'))); |
| 105 | - } elseif ($ttl !== null) { |
|
| 105 | + } |
|
| 106 | + elseif ($ttl !== null) { |
|
| 106 | 107 | $cacheItem->expiresAfter($ttl); |
| 107 | 108 | } |
| 108 | 109 | return $this->internalCacheInstance->save($cacheItem); |
| 109 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 110 | + } |
|
| 111 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 110 | 112 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 111 | 113 | } |
| 112 | 114 | } |
@@ -120,7 +122,8 @@ discard block |
||
| 120 | 122 | { |
| 121 | 123 | try { |
| 122 | 124 | return $this->internalCacheInstance->deleteItem($key); |
| 123 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 125 | + } |
|
| 126 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 124 | 127 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 125 | 128 | } |
| 126 | 129 | } |
@@ -133,7 +136,8 @@ discard block |
||
| 133 | 136 | { |
| 134 | 137 | try { |
| 135 | 138 | return $this->internalCacheInstance->clear(); |
| 136 | - } catch (PhpfastcacheRootException $e) { |
|
| 139 | + } |
|
| 140 | + catch (PhpfastcacheRootException $e) { |
|
| 137 | 141 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 138 | 142 | } |
| 139 | 143 | } |
@@ -145,8 +149,7 @@ discard block |
||
| 145 | 149 | * @throws PhpfastcacheSimpleCacheException |
| 146 | 150 | * @throws \Psr\Cache\InvalidArgumentException |
| 147 | 151 | */ |
| 148 | - public function getMultiple($keys, $default = null) |
|
| 149 | - { |
|
| 152 | + public function getMultiple($keys, $default = null) { |
|
| 150 | 153 | if ($keys instanceof Traversable) { |
| 151 | 154 | $keys = \iterator_to_array($keys); |
| 152 | 155 | } |
@@ -157,7 +160,8 @@ discard block |
||
| 157 | 160 | }, |
| 158 | 161 | $this->internalCacheInstance->getItems($keys) |
| 159 | 162 | ); |
| 160 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 163 | + } |
|
| 164 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 161 | 165 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 162 | 166 | } |
| 163 | 167 | } |
@@ -177,14 +181,16 @@ discard block |
||
| 177 | 181 | |
| 178 | 182 | if (\is_int($ttl) && $ttl <= 0) { |
| 179 | 183 | $cacheItem->expiresAt((new DateTime('@0'))); |
| 180 | - } elseif ($ttl !== null) { |
|
| 184 | + } |
|
| 185 | + elseif ($ttl !== null) { |
|
| 181 | 186 | $cacheItem->expiresAfter($ttl); |
| 182 | 187 | } |
| 183 | 188 | $this->internalCacheInstance->saveDeferred($cacheItem); |
| 184 | 189 | unset($cacheItem); |
| 185 | 190 | } |
| 186 | 191 | return $this->internalCacheInstance->commit(); |
| 187 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 192 | + } |
|
| 193 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 188 | 194 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 189 | 195 | } |
| 190 | 196 | } |
@@ -200,12 +206,15 @@ discard block |
||
| 200 | 206 | try { |
| 201 | 207 | if ($keys instanceof Traversable) { |
| 202 | 208 | return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys)); |
| 203 | - } elseif (\is_array($keys)) { |
|
| 209 | + } |
|
| 210 | + elseif (\is_array($keys)) { |
|
| 204 | 211 | return $this->internalCacheInstance->deleteItems($keys); |
| 205 | - } else { |
|
| 212 | + } |
|
| 213 | + else { |
|
| 206 | 214 | throw new phpFastCacheInvalidArgumentException('$keys must be an array/Traversable instance.'); |
| 207 | 215 | } |
| 208 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 216 | + } |
|
| 217 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 209 | 218 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 210 | 219 | } |
| 211 | 220 | } |
@@ -220,7 +229,8 @@ discard block |
||
| 220 | 229 | try { |
| 221 | 230 | $cacheItem = $this->internalCacheInstance->getItem($key); |
| 222 | 231 | return $cacheItem->isHit() && !$cacheItem->isExpired(); |
| 223 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 232 | + } |
|
| 233 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
| 224 | 234 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
| 225 | 235 | } |
| 226 | 236 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * Register Autoload |
| 31 | 31 | */ |
| 32 | 32 | spl_autoload_register( |
| 33 | - static function ($entity): void { |
|
| 33 | + static function($entity): void { |
|
| 34 | 34 | $module = explode('\\', $entity, 2); |
| 35 | 35 | if (!\in_array($module[0], ['Phpfastcache', 'Psr'])) { |
| 36 | 36 | /** |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | $entityPath = str_replace('\\', '/', $entity); |
| 66 | 66 | |
| 67 | - if(\strpos($entity, PFC_TESTS_NS) === 0){ |
|
| 67 | + if (\strpos($entity, PFC_TESTS_NS) === 0) { |
|
| 68 | 68 | $path = PFC_TESTS_DIR . \str_replace(str_replace('\\', '/', PFC_TESTS_NS), '', $entityPath) . '.' . PFC_PHP_EXT; |
| 69 | - }else{ |
|
| 69 | + } else { |
|
| 70 | 70 | $path = PFC_LIB_DIR . $entityPath . '.' . PFC_PHP_EXT; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -45,7 +45,8 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | if (\is_readable($path)) { |
| 47 | 47 | require_once $path; |
| 48 | - } else { |
|
| 48 | + } |
|
| 49 | + else { |
|
| 49 | 50 | \trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR); |
| 50 | 51 | } |
| 51 | 52 | return; |
@@ -56,7 +57,8 @@ discard block |
||
| 56 | 57 | |
| 57 | 58 | if (\is_readable($path)) { |
| 58 | 59 | require_once $path; |
| 59 | - } else { |
|
| 60 | + } |
|
| 61 | + else { |
|
| 60 | 62 | \trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR); |
| 61 | 63 | } |
| 62 | 64 | return; |
@@ -66,7 +68,8 @@ discard block |
||
| 66 | 68 | |
| 67 | 69 | if(\strpos($entity, PFC_TESTS_NS) === 0){ |
| 68 | 70 | $path = PFC_TESTS_DIR . \str_replace(str_replace('\\', '/', PFC_TESTS_NS), '', $entityPath) . '.' . PFC_PHP_EXT; |
| 69 | - }else{ |
|
| 71 | + } |
|
| 72 | + else{ |
|
| 70 | 73 | $path = PFC_LIB_DIR . $entityPath . '.' . PFC_PHP_EXT; |
| 71 | 74 | } |
| 72 | 75 | |
@@ -91,8 +91,7 @@ discard block |
||
| 91 | 91 | return unlink($source); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $files = new RecursiveIteratorIterator |
|
| 95 | - ( |
|
| 94 | + $files = new RecursiveIteratorIterator( |
|
| 96 | 95 | new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
| 97 | 96 | RecursiveIteratorIterator::CHILD_FIRST |
| 98 | 97 | ); |
@@ -102,7 +101,7 @@ discard block |
||
| 102 | 101 | * @var SplFileInfo $fileinfo |
| 103 | 102 | */ |
| 104 | 103 | $realpath = $fileinfo->getRealPath(); |
| 105 | - if($realpath){ |
|
| 104 | + if ($realpath) { |
|
| 106 | 105 | if ($fileinfo->isDir()) { |
| 107 | 106 | if (self::rrmdir($fileinfo->getRealPath()) === false) { |
| 108 | 107 | return false; |
@@ -111,7 +110,7 @@ discard block |
||
| 111 | 110 | return false; |
| 112 | 111 | } |
| 113 | 112 | } |
| 114 | - else{ |
|
| 113 | + else { |
|
| 115 | 114 | return false; |
| 116 | 115 | } |
| 117 | 116 | } |
@@ -148,7 +147,7 @@ discard block |
||
| 148 | 147 | /** |
| 149 | 148 | * Allows to dereference char |
| 150 | 149 | */ |
| 151 | - $__FILE__ = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. |
|
| 150 | + $__FILE__ = preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__); // remove file protocols such as "phar://" etc. |
|
| 152 | 151 | $prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
| 153 | 152 | return $prefix . implode(DIRECTORY_SEPARATOR, $absolutes); |
| 154 | 153 | } |
@@ -41,7 +41,8 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | if ($file->isFile()) { |
| 43 | 43 | $size += filesize($file->getRealPath()); |
| 44 | - } else { |
|
| 44 | + } |
|
| 45 | + else { |
|
| 45 | 46 | if ($includeDirAllocSize) { |
| 46 | 47 | $size += $file->getSize(); |
| 47 | 48 | } |
@@ -107,7 +108,8 @@ discard block |
||
| 107 | 108 | if (self::rrmdir($fileinfo->getRealPath()) === false) { |
| 108 | 109 | return false; |
| 109 | 110 | } |
| 110 | - } elseif (unlink($realpath) === false) { |
|
| 111 | + } |
|
| 112 | + elseif (unlink($realpath) === false) { |
|
| 111 | 113 | return false; |
| 112 | 114 | } |
| 113 | 115 | } |
@@ -140,7 +142,8 @@ discard block |
||
| 140 | 142 | } |
| 141 | 143 | if ('..' === $part) { |
| 142 | 144 | array_pop($absolutes); |
| 143 | - } else { |
|
| 145 | + } |
|
| 146 | + else { |
|
| 144 | 147 | $absolutes[] = $part; |
| 145 | 148 | } |
| 146 | 149 | } |
@@ -99,14 +99,14 @@ |
||
| 99 | 99 | case T_NAMESPACE: |
| 100 | 100 | $namespace = ''; |
| 101 | 101 | // If there is a namespace, extract it (PHP 8 test) |
| 102 | - if(\defined('T_NAME_QUALIFIED')){ |
|
| 102 | + if (\defined('T_NAME_QUALIFIED')) { |
|
| 103 | 103 | while (isset($tokens[++$i][1])) { |
| 104 | 104 | if ($tokens[$i][0] === T_NAME_QUALIFIED) { |
| 105 | 105 | $namespace = $tokens[$i][1]; |
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | - }else{ |
|
| 109 | + } else { |
|
| 110 | 110 | while (isset($tokens[++$i][1])) { |
| 111 | 111 | if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR], true)) { |
| 112 | 112 | $namespace .= $tokens[$i][1]; |
@@ -106,7 +106,8 @@ discard block |
||
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | - }else{ |
|
| 109 | + } |
|
| 110 | + else{ |
|
| 110 | 111 | while (isset($tokens[++$i][1])) { |
| 111 | 112 | if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR], true)) { |
| 112 | 113 | $namespace .= $tokens[$i][1]; |
@@ -127,7 +128,8 @@ discard block |
||
| 127 | 128 | if (T_DOUBLE_COLON === $tokens[$j][0]) { |
| 128 | 129 | $isClassConstant = true; |
| 129 | 130 | break; |
| 130 | - } elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 131 | + } |
|
| 132 | + elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 131 | 133 | break; |
| 132 | 134 | } |
| 133 | 135 | } |
@@ -139,7 +141,8 @@ discard block |
||
| 139 | 141 | $t = $tokens[$i]; |
| 140 | 142 | if (T_STRING === $t[0]) { |
| 141 | 143 | $class .= $t[1]; |
| 142 | - } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 144 | + } |
|
| 145 | + elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 143 | 146 | break; |
| 144 | 147 | } |
| 145 | 148 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | if (\is_string($key)) { |
| 67 | 67 | $this->key = $key; |
| 68 | 68 | $this->driver = $driver; |
| 69 | - if($driver->getConfig()->isUseStaticItemCaching()){ |
|
| 69 | + if ($driver->getConfig()->isUseStaticItemCaching()) { |
|
| 70 | 70 | $this->driver->setItem($this); |
| 71 | 71 | } |
| 72 | 72 | $this->expirationDate = new DateTime(); |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | $this->data[] = $data; |
| 283 | 283 | } else { |
| 284 | 284 | if (\is_string($data)) { |
| 285 | - $this->data .= (string)$data; |
|
| 285 | + $this->data .= (string) $data; |
|
| 286 | 286 | } else { |
| 287 | 287 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
| 288 | 288 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | \array_unshift($this->data, $data); |
| 304 | 304 | } else { |
| 305 | 305 | if (\is_string($data)) { |
| 306 | - $this->data = (string)$data . $this->data; |
|
| 306 | + $this->data = (string) $data . $this->data; |
|
| 307 | 307 | } else { |
| 308 | 308 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
| 309 | 309 | } |
@@ -61,8 +61,7 @@ discard block |
||
| 61 | 61 | * @param $key |
| 62 | 62 | * @throws PhpfastcacheInvalidArgumentException |
| 63 | 63 | */ |
| 64 | - public function __construct(ExtendedCacheItemPoolInterface $driver, $key) |
|
| 65 | - { |
|
| 64 | + public function __construct(ExtendedCacheItemPoolInterface $driver, $key) { |
|
| 66 | 65 | if (\is_string($key)) { |
| 67 | 66 | $this->key = $key; |
| 68 | 67 | $this->driver = $driver; |
@@ -74,7 +73,8 @@ discard block |
||
| 74 | 73 | $this->creationDate = new DateTime(); |
| 75 | 74 | $this->modificationDate = new DateTime(); |
| 76 | 75 | } |
| 77 | - } else { |
|
| 76 | + } |
|
| 77 | + else { |
|
| 78 | 78 | throw new PhpfastcacheInvalidArgumentTypeException('string', $key); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -89,7 +89,8 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | if ($keyHashFunction) { |
| 91 | 91 | $this->encodedKey = $keyHashFunction($this->getKey()); |
| 92 | - } else { |
|
| 92 | + } |
|
| 93 | + else { |
|
| 93 | 94 | $this->encodedKey = $this->getKey(); |
| 94 | 95 | } |
| 95 | 96 | } |
@@ -247,7 +248,8 @@ discard block |
||
| 247 | 248 | if (\is_int($step)) { |
| 248 | 249 | $this->fetched = true; |
| 249 | 250 | $this->data += $step; |
| 250 | - } else { |
|
| 251 | + } |
|
| 252 | + else { |
|
| 251 | 253 | throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); |
| 252 | 254 | } |
| 253 | 255 | |
@@ -264,7 +266,8 @@ discard block |
||
| 264 | 266 | if (\is_int($step)) { |
| 265 | 267 | $this->fetched = true; |
| 266 | 268 | $this->data -= $step; |
| 267 | - } else { |
|
| 269 | + } |
|
| 270 | + else { |
|
| 268 | 271 | throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); |
| 269 | 272 | } |
| 270 | 273 | |
@@ -280,10 +283,12 @@ discard block |
||
| 280 | 283 | { |
| 281 | 284 | if (\is_array($this->data)) { |
| 282 | 285 | $this->data[] = $data; |
| 283 | - } else { |
|
| 286 | + } |
|
| 287 | + else { |
|
| 284 | 288 | if (\is_string($data)) { |
| 285 | 289 | $this->data .= (string)$data; |
| 286 | - } else { |
|
| 290 | + } |
|
| 291 | + else { |
|
| 287 | 292 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
| 288 | 293 | } |
| 289 | 294 | } |
@@ -301,10 +306,12 @@ discard block |
||
| 301 | 306 | { |
| 302 | 307 | if (\is_array($this->data)) { |
| 303 | 308 | \array_unshift($this->data, $data); |
| 304 | - } else { |
|
| 309 | + } |
|
| 310 | + else { |
|
| 305 | 311 | if (\is_string($data)) { |
| 306 | 312 | $this->data = (string)$data . $this->data; |
| 307 | - } else { |
|
| 313 | + } |
|
| 314 | + else { |
|
| 308 | 315 | throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); |
| 309 | 316 | } |
| 310 | 317 | } |
@@ -325,7 +332,8 @@ discard block |
||
| 325 | 332 | |
| 326 | 333 | if (\is_object($data) || \is_array($data)) { |
| 327 | 334 | $data = \json_encode($data, $option, $depth); |
| 328 | - } else { |
|
| 335 | + } |
|
| 336 | + else { |
|
| 329 | 337 | $data = \json_encode([$data], $option, $depth); |
| 330 | 338 | } |
| 331 | 339 | |
@@ -337,8 +345,7 @@ discard block |
||
| 337 | 345 | * @return mixed |
| 338 | 346 | */ |
| 339 | 347 | #[\ReturnTypeWillChange] // PHP 8.1 compatibility |
| 340 | - public function jsonSerialize() |
|
| 341 | - { |
|
| 348 | + public function jsonSerialize() { |
|
| 342 | 349 | return $this->get(); |
| 343 | 350 | } |
| 344 | 351 | |
@@ -358,8 +365,7 @@ discard block |
||
| 358 | 365 | * |
| 359 | 366 | * Prevent recursions for Debug (php 5.6+) |
| 360 | 367 | */ |
| 361 | - final public function __debugInfo() |
|
| 362 | - { |
|
| 368 | + final public function __debugInfo() { |
|
| 363 | 369 | $info = \get_object_vars($this); |
| 364 | 370 | $info['driver'] = 'object(' . \get_class($info['driver']) . ')'; |
| 365 | 371 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function getItemsAsJsonString(array $keys = [], int $option = 0, int $depth = 512): string |
| 42 | 42 | { |
| 43 | - $callback = static function (CacheItemInterface $item) { |
|
| 43 | + $callback = static function(CacheItemInterface $item) { |
|
| 44 | 44 | return $item->get(); |
| 45 | 45 | }; |
| 46 | 46 | return \json_encode(\array_map($callback, \array_values($this->getItems($keys))), $option, $depth); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | ); |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if(!$this->getConfig()->isUseStaticItemCaching()){ |
|
| 94 | + if (!$this->getConfig()->isUseStaticItemCaching()) { |
|
| 95 | 95 | throw new PhpfastcacheLogicException( |
| 96 | 96 | 'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.' |
| 97 | 97 | ); |
@@ -49,8 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @inheritdoc |
| 51 | 51 | */ |
| 52 | - public function detachAllItems() |
|
| 53 | - { |
|
| 52 | + public function detachAllItems() { |
|
| 54 | 53 | foreach ($this->itemInstances as $item) { |
| 55 | 54 | $this->detachItem($item); |
| 56 | 55 | } |
@@ -60,8 +59,7 @@ discard block |
||
| 60 | 59 | * @param CacheItemInterface $item |
| 61 | 60 | * @return void |
| 62 | 61 | */ |
| 63 | - public function detachItem(CacheItemInterface $item) |
|
| 64 | - { |
|
| 62 | + public function detachItem(CacheItemInterface $item) { |
|
| 65 | 63 | if (isset($this->itemInstances[$item->getKey()])) { |
| 66 | 64 | $this->deregisterItem($item->getKey()); |
| 67 | 65 | } |
@@ -71,8 +69,7 @@ discard block |
||
| 71 | 69 | * @param string $item |
| 72 | 70 | * @internal This method de-register an item from $this->itemInstances |
| 73 | 71 | */ |
| 74 | - protected function deregisterItem(string $item) |
|
| 75 | - { |
|
| 72 | + protected function deregisterItem(string $item) { |
|
| 76 | 73 | unset($this->itemInstances[$item]); |
| 77 | 74 | |
| 78 | 75 | if (\gc_enabled()) { |
@@ -83,8 +80,7 @@ discard block |
||
| 83 | 80 | /** |
| 84 | 81 | * @inheritdoc |
| 85 | 82 | */ |
| 86 | - public function attachItem(CacheItemInterface $item) |
|
| 87 | - { |
|
| 83 | + public function attachItem(CacheItemInterface $item) { |
|
| 88 | 84 | if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
| 89 | 85 | throw new PhpfastcacheLogicException( |
| 90 | 86 | '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.' |
@@ -108,8 +104,7 @@ discard block |
||
| 108 | 104 | * @param CacheItemInterface $item |
| 109 | 105 | * @return bool|null |
| 110 | 106 | */ |
| 111 | - public function isAttached(CacheItemInterface $item) |
|
| 112 | - { |
|
| 107 | + public function isAttached(CacheItemInterface $item) { |
|
| 113 | 108 | if (isset($this->itemInstances[$item->getKey()])) { |
| 114 | 109 | return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]); |
| 115 | 110 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function getItemsByTagsAsJsonString(array $tagNames, int $option = 0, int $depth = 512, int $strategy = TaggableCacheItemPoolInterface::TAG_STRATEGY_ONE): string |
| 36 | 36 | { |
| 37 | - $callback = static function (CacheItemInterface $item) { |
|
| 37 | + $callback = static function(CacheItemInterface $item) { |
|
| 38 | 38 | return $item->get(); |
| 39 | 39 | }; |
| 40 | 40 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | if (\is_string($tagName)) { |
| 88 | 88 | $driverResponse = $this->getItem($this->getTagKey($tagName)); |
| 89 | 89 | if ($driverResponse->isHit()) { |
| 90 | - $tagsItems = (array)$driverResponse->get(); |
|
| 90 | + $tagsItems = (array) $driverResponse->get(); |
|
| 91 | 91 | |
| 92 | 92 | /** |
| 93 | 93 | * getItems() may provides expired item(s) |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | return \array_filter( |
| 103 | 103 | $this->getItems(\array_unique(\array_keys($tagsItems))), |
| 104 | - static function (ExtendedCacheItemInterface $item) { |
|
| 104 | + static function(ExtendedCacheItemInterface $item) { |
|
| 105 | 105 | return $item->isHit(); |
| 106 | 106 | } |
| 107 | 107 | ); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return (bool)$return; |
|
| 138 | + return (bool) $return; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - return (bool)$return; |
|
| 155 | + return (bool) $return; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - return (bool)$return; |
|
| 190 | + return (bool) $return; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $this->saveDeferred($item); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - return (bool)$this->commit(); |
|
| 204 | + return (bool) $this->commit(); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a string and $step an integer'); |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - return (bool)$return; |
|
| 223 | + return (bool) $return; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | $this->saveDeferred($item); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return (bool)$this->commit(); |
|
| 237 | + return (bool) $this->commit(); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a string and $step an integer'); |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - return (bool)$return; |
|
| 256 | + return (bool) $return; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | $this->saveDeferred($item); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - return (bool)$this->commit(); |
|
| 270 | + return (bool) $this->commit(); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - return (bool)$return; |
|
| 289 | + return (bool) $return; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $this->saveDeferred($item); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - return (bool)$this->commit(); |
|
| 303 | + return (bool) $this->commit(); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * that has slow performances |
| 362 | 362 | */ |
| 363 | 363 | |
| 364 | - $tagsItem->set(\array_merge((array)$data, [$item->getKey() => $expTimestamp])) |
|
| 364 | + $tagsItem->set(\array_merge((array) $data, [$item->getKey() => $expTimestamp])) |
|
| 365 | 365 | ->expiresAt($item->getExpirationDate()); |
| 366 | 366 | |
| 367 | 367 | $this->driverWrite($tagsItem); |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | $tagsItems = $this->getItems($this->getTagKeys($item->getRemovedTags())); |
| 376 | 376 | |
| 377 | 377 | foreach ($tagsItems as $tagsItem) { |
| 378 | - $data = (array)$tagsItem->get(); |
|
| 378 | + $data = (array) $tagsItem->get(); |
|
| 379 | 379 | |
| 380 | 380 | unset($data[$item->getKey()]); |
| 381 | 381 | $tagsItem->set($data); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | protected function getTagKeys(array $keys): array |
| 407 | 407 | { |
| 408 | 408 | return \array_map( |
| 409 | - function (string $key) { |
|
| 409 | + function(string $key) { |
|
| 410 | 410 | return $this->getTagKey($key); |
| 411 | 411 | }, |
| 412 | 412 | $keys |
@@ -50,7 +50,8 @@ discard block |
||
| 50 | 50 | foreach (\array_unique($tagNames) as $tagName) { |
| 51 | 51 | if (\is_string($tagName)) { |
| 52 | 52 | $items[] = $this->fetchItemsByTagFromBackend($tagName); |
| 53 | - } else { |
|
| 53 | + } |
|
| 54 | + else { |
|
| 54 | 55 | throw new PhpfastcacheInvalidArgumentException('$tagName must be a a string'); |
| 55 | 56 | } |
| 56 | 57 | } |
@@ -310,8 +311,7 @@ discard block |
||
| 310 | 311 | * @param array $wrapper |
| 311 | 312 | * @return mixed |
| 312 | 313 | */ |
| 313 | - protected function driverUnwrapTags(array $wrapper) |
|
| 314 | - { |
|
| 314 | + protected function driverUnwrapTags(array $wrapper) { |
|
| 315 | 315 | return $wrapper[self::DRIVER_TAGS_WRAPPER_INDEX]; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -320,8 +320,7 @@ discard block |
||
| 320 | 320 | * @throws PhpfastcacheInvalidArgumentException |
| 321 | 321 | * @throws PhpfastcacheLogicException |
| 322 | 322 | */ |
| 323 | - protected function cleanItemTags(ExtendedCacheItemInterface $item) |
|
| 324 | - { |
|
| 323 | + protected function cleanItemTags(ExtendedCacheItemInterface $item) { |
|
| 325 | 324 | $this->driverWriteTags($item->removeTags($item->getTags())); |
| 326 | 325 | } |
| 327 | 326 | |
@@ -391,7 +390,8 @@ discard block |
||
| 391 | 390 | $tagsItem->expiresAt((new DateTime())->setTimestamp(max($data))); |
| 392 | 391 | $this->driverWrite($tagsItem); |
| 393 | 392 | $tagsItem->setHit(true); |
| 394 | - } else { |
|
| 393 | + } |
|
| 394 | + else { |
|
| 395 | 395 | $this->deleteItem($tagsItem->getKey()); |
| 396 | 396 | } |
| 397 | 397 | } |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | ->setSize(Directory::dirSize($path)) |
| 65 | 65 | ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
| 66 | 66 | |
| 67 | - if($this->getConfig()->isUseStaticItemCaching()){ |
|
| 67 | + if ($this->getConfig()->isUseStaticItemCaching()) { |
|
| 68 | 68 | $stat->setData(implode(', ', \array_keys($this->itemInstances))); |
| 69 | - }else{ |
|
| 69 | + } else { |
|
| 70 | 70 | $stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.'); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | throw new PhpfastcacheIOException("Cannot read file located at: {$file}"); |
| 295 | 295 | } |
| 296 | 296 | if (\function_exists('file_get_contents')) { |
| 297 | - return (string)\file_get_contents($file); |
|
| 297 | + return (string) \file_get_contents($file); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | $string = ''; |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | dirname($file) . \DIRECTORY_SEPARATOR . 'tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()( |
| 339 | 339 | \bin2hex(\random_bytes(16)) |
| 340 | 340 | ) |
| 341 | - ) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999); |
|
| 341 | + ) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999); |
|
| 342 | 342 | |
| 343 | 343 | $handle = \fopen($tmpFilename, 'w+b'); |
| 344 | 344 | if (\is_resource($handle)) { |
@@ -359,6 +359,6 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return (bool)($octetWritten ?? false); |
|
| 362 | + return (bool) ($octetWritten ?? false); |
|
| 363 | 363 | } |
| 364 | 364 | } |
@@ -66,7 +66,8 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | if($this->getConfig()->isUseStaticItemCaching()){ |
| 68 | 68 | $stat->setData(implode(', ', \array_keys($this->itemInstances))); |
| 69 | - }else{ |
|
| 69 | + } |
|
| 70 | + else{ |
|
| 70 | 71 | $stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.'); |
| 71 | 72 | } |
| 72 | 73 | |
@@ -123,7 +124,8 @@ discard block |
||
| 123 | 124 | if (!$securityKey || \mb_strtolower($securityKey) === 'auto') { |
| 124 | 125 | if (isset($_SERVER['HTTP_HOST'])) { |
| 125 | 126 | $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $_SERVER['HTTP_HOST']))); |
| 126 | - } else { |
|
| 127 | + } |
|
| 128 | + else { |
|
| 127 | 129 | $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); |
| 128 | 130 | } |
| 129 | 131 | } |
@@ -143,7 +145,8 @@ discard block |
||
| 143 | 145 | |
| 144 | 146 | if (empty($this->getConfig()->getPath())) { |
| 145 | 147 | $path = $tmp_dir; |
| 146 | - } else { |
|
| 148 | + } |
|
| 149 | + else { |
|
| 147 | 150 | $path = \rtrim($this->getConfig()->getPath(), '/') . DIRECTORY_SEPARATOR; |
| 148 | 151 | } |
| 149 | 152 | |
@@ -170,7 +173,8 @@ discard block |
||
| 170 | 173 | if (@mkdir($full_path, $this->getDefaultChmod(), true) === false && !\is_dir($full_path)) { |
| 171 | 174 | throw new PhpfastcacheIOException('The directory ' . $full_path . ' could not be created.'); |
| 172 | 175 | } |
| 173 | - } else { |
|
| 176 | + } |
|
| 177 | + else { |
|
| 174 | 178 | if (!@\is_writable($full_path)) { |
| 175 | 179 | if (!@\chmod($full_path, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) { |
| 176 | 180 | /** |
@@ -238,15 +242,15 @@ discard block |
||
| 238 | 242 | * @param bool $create |
| 239 | 243 | * @throws PhpfastcacheIOException |
| 240 | 244 | */ |
| 241 | - protected function htaccessGen($path, $create = true) |
|
| 242 | - { |
|
| 245 | + protected function htaccessGen($path, $create = true) { |
|
| 243 | 246 | if ($create === true) { |
| 244 | 247 | if (!\is_writable($path)) { |
| 245 | 248 | try { |
| 246 | 249 | if (!\chmod($path, 0777)) { |
| 247 | 250 | throw new PhpfastcacheIOException('Chmod failed on : ' . $path); |
| 248 | 251 | } |
| 249 | - } catch (PhpfastcacheIOException $e) { |
|
| 252 | + } |
|
| 253 | + catch (PhpfastcacheIOException $e) { |
|
| 250 | 254 | throw new PhpfastcacheIOException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 0, $e); |
| 251 | 255 | } |
| 252 | 256 | } |
@@ -351,7 +355,8 @@ discard block |
||
| 351 | 355 | if (!\rename($tmpFilename, $file)) { |
| 352 | 356 | throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file)); |
| 353 | 357 | } |
| 354 | - } else { |
|
| 358 | + } |
|
| 359 | + else { |
|
| 355 | 360 | $handle = \fopen($file, 'w+b'); |
| 356 | 361 | if (\is_resource($handle)) { |
| 357 | 362 | $octetWritten = \fwrite($handle, $data); |