@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Phpfastcache\Core\Item\ExtendedCacheItemInterface; |
| 19 | 19 | use Phpfastcache\Event\EventInterface; |
| 20 | 20 | use Phpfastcache\Exceptions\{ |
| 21 | - PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException |
|
| 21 | + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException |
|
| 22 | 22 | }; |
| 23 | 23 | use Psr\Cache\CacheItemInterface; |
| 24 | 24 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512): string |
| 38 | 38 | { |
| 39 | - $callback = function (CacheItemInterface $item) { |
|
| 39 | + $callback = function(CacheItemInterface $item) { |
|
| 40 | 40 | return $item->get(); |
| 41 | 41 | }; |
| 42 | 42 | return \json_encode(\array_map($callback, \array_values($this->getItems($keys))), $option, $depth); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if (\is_string($tagName)) { |
| 51 | 51 | $driverResponse = $this->getItem($this->getTagKey($tagName)); |
| 52 | 52 | if ($driverResponse->isHit()) { |
| 53 | - $items = (array)$driverResponse->get(); |
|
| 53 | + $items = (array) $driverResponse->get(); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * getItems() may provides expired item(s) |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * #headache |
| 64 | 64 | */ |
| 65 | - return \array_filter($this->getItems(\array_unique(\array_keys($items))), function (ExtendedCacheItemInterface $item) { |
|
| 65 | + return \array_filter($this->getItems(\array_unique(\array_keys($items))), function(ExtendedCacheItemInterface $item) { |
|
| 66 | 66 | return $item->isHit(); |
| 67 | 67 | }); |
| 68 | 68 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | foreach ($items as $key => $item) { |
| 101 | 101 | if (\array_diff($tagNames, $item->getTags())) { |
| 102 | - unset($items[ $key ]); |
|
| 102 | + unset($items[$key]); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
| 114 | 114 | { |
| 115 | - $callback = function (CacheItemInterface $item) { |
|
| 115 | + $callback = function(CacheItemInterface $item) { |
|
| 116 | 116 | return $item->get(); |
| 117 | 117 | }; |
| 118 | 118 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | */ |
| 384 | 384 | public function detachItem(CacheItemInterface $item) |
| 385 | 385 | { |
| 386 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
| 386 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
| 387 | 387 | $this->deregisterItem($item); |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | public function attachItem(CacheItemInterface $item) |
| 405 | 405 | { |
| 406 | - if (isset($this->itemInstances[ $item->getKey() ]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
| 406 | + if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
| 407 | 407 | 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.'); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
| 410 | + $this->itemInstances[$item->getKey()] = $item; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | |
@@ -419,10 +419,10 @@ discard block |
||
| 419 | 419 | protected function deregisterItem($item) |
| 420 | 420 | { |
| 421 | 421 | if ($item instanceof CacheItemInterface) { |
| 422 | - unset($this->itemInstances[ $item->getKey() ]); |
|
| 422 | + unset($this->itemInstances[$item->getKey()]); |
|
| 423 | 423 | |
| 424 | 424 | } else if (\is_string($item)) { |
| 425 | - unset($this->itemInstances[ $item ]); |
|
| 425 | + unset($this->itemInstances[$item]); |
|
| 426 | 426 | } else { |
| 427 | 427 | throw new PhpfastcacheInvalidArgumentException('Invalid type for $item variable'); |
| 428 | 428 | } |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function isAttached(CacheItemInterface $item) |
| 451 | 451 | { |
| 452 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
| 453 | - return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[ $item->getKey() ]); |
|
| 452 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
| 453 | + return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]); |
|
| 454 | 454 | } |
| 455 | 455 | return null; |
| 456 | 456 | } |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | public function saveMultiple(...$items): bool |
| 475 | 475 | { |
| 476 | - if (isset($items[ 0 ]) && \is_array($items[ 0 ])) { |
|
| 477 | - foreach ($items[ 0 ] as $item) { |
|
| 476 | + if (isset($items[0]) && \is_array($items[0])) { |
|
| 477 | + foreach ($items[0] as $item) { |
|
| 478 | 478 | $this->save($item); |
| 479 | 479 | } |
| 480 | 480 | return true; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | use Phpfastcache\Entities\DriverStatistic; |
| 22 | 22 | use Phpfastcache\Event\EventInterface; |
| 23 | 23 | use Phpfastcache\Exceptions\{ |
| 24 | - PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException |
|
| 24 | + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException |
|
| 25 | 25 | }; |
| 26 | 26 | use Psr\Cache\{CacheItemInterface, CacheItemPoolInterface}; |
| 27 | 27 | |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | $securityKey = $this->getConfig()->getSecurityKey(); |
| 58 | 58 | if (!$securityKey || \mb_strtolower($securityKey) === 'auto') { |
| 59 | - if (isset($_SERVER[ 'HTTP_HOST' ])) { |
|
| 60 | - $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ]))); |
|
| 59 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
| 60 | + $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $_SERVER['HTTP_HOST']))); |
|
| 61 | 61 | } else { |
| 62 | 62 | $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); |
| 63 | 63 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | return $full_path; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if (!isset($this->tmp[ $full_path_hash ]) || (!@\file_exists($full_path) || !@\is_writable($full_path))) { |
|
| 103 | + if (!isset($this->tmp[$full_path_hash]) || (!@\file_exists($full_path) || !@\is_writable($full_path))) { |
|
| 104 | 104 | if (!@\file_exists($full_path)) { |
| 105 | 105 | @mkdir($full_path, $this->getDefaultChmod(), true); |
| 106 | 106 | } else if (!@\is_writable($full_path)) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | 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 !'); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $this->tmp[ $full_path_hash ] = $full_path; |
|
| 128 | + $this->tmp[$full_path_hash] = $full_path; |
|
| 129 | 129 | $this->htaccessGen($full_path, \array_key_exists('htaccess', $this->getConfig()) ? $this->getConfig()->getHtaccess() : false); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | protected static function cleanFileName($filename): string |
| 195 | 195 | { |
| 196 | 196 | $regex = [ |
| 197 | - '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
| 198 | - '/\.$/', |
|
| 199 | - '/^\./', |
|
| 197 | + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
| 198 | + '/\.$/', |
|
| 199 | + '/^\./', |
|
| 200 | 200 | ]; |
| 201 | 201 | $replace = ['-', '', '']; |
| 202 | 202 | |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | $tmpFilename = Directory::getAbsolutePath(\dirname($file) . '/tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()( |
| 293 | 293 | \str_shuffle(\uniqid($this->getDriverName(), false)) |
| 294 | 294 | . \str_shuffle(\uniqid($this->getDriverName(), false)) |
| 295 | - )); |
|
| 295 | + )); |
|
| 296 | 296 | |
| 297 | 297 | $f = \fopen($tmpFilename, 'w+'); |
| 298 | 298 | \flock($f, \LOCK_EX); |
@@ -334,11 +334,11 @@ discard block |
||
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | $stat->setData(\implode(', ', \array_keys($this->itemInstances))) |
| 337 | - ->setRawData([ |
|
| 337 | + ->setRawData([ |
|
| 338 | 338 | 'tmp' => $this->tmp, |
| 339 | - ]) |
|
| 340 | - ->setSize(Directory::dirSize($path)) |
|
| 341 | - ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 339 | + ]) |
|
| 340 | + ->setSize(Directory::dirSize($path)) |
|
| 341 | + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 342 | 342 | |
| 343 | 343 | return $stat; |
| 344 | 344 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | |
| 50 | 50 | if (!$cacheItem->isHit()) { |
| 51 | 51 | $cacheItem->set($callback()); |
| 52 | - if($expiresAfter){ |
|
| 52 | + if ($expiresAfter) { |
|
| 53 | 53 | $cacheItem->expiresAfter($expiresAfter); |
| 54 | 54 | } |
| 55 | 55 | $this->cacheInstance->save($cacheItem); |
@@ -16,7 +16,7 @@ |
||
| 16 | 16 | namespace Phpfastcache\Helper; |
| 17 | 17 | |
| 18 | 18 | use Phpfastcache\{ |
| 19 | - CacheManager, Event\EventInterface, EventManager |
|
| 19 | + CacheManager, Event\EventInterface, EventManager |
|
| 20 | 20 | }; |
| 21 | 21 | use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
| 22 | 22 | use Phpfastcache\Entities\DriverStatistic; |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function __construct() |
| 41 | 41 | { |
| 42 | - $this->instances =& CacheManager::getInternalInstances(); |
|
| 42 | + $this->instances = & CacheManager::getInternalInstances(); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -47,11 +47,11 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | protected function getGenericCallback(): \Closure |
| 49 | 49 | { |
| 50 | - return function ($method, $args) { |
|
| 50 | + return function($method, $args) { |
|
| 51 | 51 | $return = []; |
| 52 | 52 | foreach ($this->instances as $instance) { |
| 53 | 53 | $reflectionMethod = new \ReflectionMethod(\get_class($instance), $method); |
| 54 | - $return[ $instance->getDriverName() ] = $reflectionMethod->invokeArgs($instance, $args); |
|
| 54 | + $return[$instance->getDriverName()] = $reflectionMethod->invokeArgs($instance, $args); |
|
| 55 | 55 | } |
| 56 | 56 | return $return; |
| 57 | 57 | }; |
@@ -64,32 +64,32 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | static $version; |
| 66 | 66 | |
| 67 | - if($version && $cacheable){ |
|
| 67 | + if ($version && $cacheable) { |
|
| 68 | 68 | return $version; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if(\function_exists('shell_exec')){ |
|
| 71 | + if (\function_exists('shell_exec')) { |
|
| 72 | 72 | $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags'; |
| 73 | 73 | $stdout = shell_exec($command); |
| 74 | - if(\is_string($stdout)){ |
|
| 74 | + if (\is_string($stdout)) { |
|
| 75 | 75 | $version = \trim($stdout); |
| 76 | 76 | return $version; |
| 77 | 77 | } |
| 78 | - if(!$fallbackOnChangelog){ |
|
| 78 | + if (!$fallbackOnChangelog) { |
|
| 79 | 79 | throw new PhpfastcacheLogicException('The git command used to retrieve the PhpFastCache version has failed.'); |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if(!$fallbackOnChangelog){ |
|
| 83 | + if (!$fallbackOnChangelog) { |
|
| 84 | 84 | throw new PhpfastcacheLogicException('shell_exec is disabled therefore the PhpFastCache version cannot be retrieved.'); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
| 88 | - if(\file_exists($changelogFilename)){ |
|
| 88 | + if (\file_exists($changelogFilename)) { |
|
| 89 | 89 | $versionPrefix = '## '; |
| 90 | 90 | $changelog = \explode("\n", self::getPhpFastCacheChangelog()); |
| 91 | - foreach ($changelog as $line){ |
|
| 92 | - if(\strpos($line, $versionPrefix) === 0){ |
|
| 91 | + foreach ($changelog as $line) { |
|
| 92 | + if (\strpos($line, $versionPrefix) === 0) { |
|
| 93 | 93 | $version = \trim(\str_replace($versionPrefix, '', $line)); |
| 94 | 94 | return $version; |
| 95 | 95 | } |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | static $hash; |
| 109 | 109 | |
| 110 | - if($hash && $cacheable){ |
|
| 110 | + if ($hash && $cacheable) { |
|
| 111 | 111 | return $hash; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - if(\function_exists('shell_exec')){ |
|
| 114 | + if (\function_exists('shell_exec')) { |
|
| 115 | 115 | $stdout = \shell_exec('git rev-parse --short HEAD'); |
| 116 | - if(\is_string($stdout)){ |
|
| 116 | + if (\is_string($stdout)) { |
|
| 117 | 117 | $hash = \trim($stdout); |
| 118 | 118 | return "#{$hash}"; |
| 119 | 119 | } |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | public static function getChangelog(): string |
| 132 | 132 | { |
| 133 | 133 | $changelogFilename = __DIR__ . '/../../CHANGELOG_API.md'; |
| 134 | - if(\file_exists($changelogFilename)){ |
|
| 134 | + if (\file_exists($changelogFilename)) { |
|
| 135 | 135 | $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
| 136 | - if($string){ |
|
| 136 | + if ($string) { |
|
| 137 | 137 | return $string; |
| 138 | 138 | } |
| 139 | 139 | throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache API changelog as it seems to be empty.'); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | public static function getPhpFastCacheChangelog(): string |
| 151 | 151 | { |
| 152 | 152 | $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
| 153 | - if(\file_exists($changelogFilename)){ |
|
| 153 | + if (\file_exists($changelogFilename)) { |
|
| 154 | 154 | $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); |
| 155 | - if($string){ |
|
| 155 | + if ($string) { |
|
| 156 | 156 | return $string; |
| 157 | 157 | } |
| 158 | 158 | throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache changelog as it seems to be empty.'); |