@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | if (!is_object($driverInstance)) { |
| 25 | 25 | echo '[FAIL] CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance) . "\n"; |
| 26 | 26 | $status = 1; |
| 27 | -}else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 27 | +} else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 28 | 28 | echo '[FAIL] CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance) . "\n"; |
| 29 | 29 | $status = 1; |
| 30 | -}else{ |
|
| 30 | +} else{ |
|
| 31 | 31 | $key = 'test_attaching_detaching'; |
| 32 | 32 | |
| 33 | 33 | $itemDetached = $driverInstance->getItem($key); |
@@ -37,8 +37,7 @@ discard block |
||
| 37 | 37 | if(!$driverInstance->isAttached($itemDetached)) |
| 38 | 38 | { |
| 39 | 39 | echo '[PASS] ExtendedCacheItemPoolInterface::isAttached() identified $itemDetached as being detached.' . "\n"; |
| 40 | - } |
|
| 41 | - else |
|
| 40 | + } else |
|
| 42 | 41 | { |
| 43 | 42 | echo '[FAIL] ExtendedCacheItemPoolInterface::isAttached() failed to identify $itemDetached as to be detached.' . "\n"; |
| 44 | 43 | $status = 1; |
@@ -48,7 +47,7 @@ discard block |
||
| 48 | 47 | $driverInstance->attachItem($itemDetached); |
| 49 | 48 | echo '[FAIL] ExtendedCacheItemPoolInterface::attachItem() attached $itemDetached without trowing an error.' . "\n"; |
| 50 | 49 | $status = 1; |
| 51 | - }catch(\LogicException $e){ |
|
| 50 | + } catch(\LogicException $e){ |
|
| 52 | 51 | echo '[PASS] ExtendedCacheItemPoolInterface::attachItem() failed to attach $itemDetached by trowing a LogicException exception.' . "\n"; |
| 53 | 52 | } |
| 54 | 53 | |
@@ -24,17 +24,17 @@ discard block |
||
| 24 | 24 | if (!is_object($driverInstance)) { |
| 25 | 25 | echo '[FAIL] CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance) . "\n"; |
| 26 | 26 | $status = 1; |
| 27 | -}else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 27 | +} else if (!($driverInstance instanceof CacheItemPoolInterface)) { |
|
| 28 | 28 | echo '[FAIL] CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance) . "\n"; |
| 29 | 29 | $status = 1; |
| 30 | -}else{ |
|
| 30 | +} else { |
|
| 31 | 31 | $key = 'test_attaching_detaching'; |
| 32 | 32 | |
| 33 | 33 | $itemDetached = $driverInstance->getItem($key); |
| 34 | 34 | $driverInstance->detachItem($itemDetached); |
| 35 | 35 | $itemAttached = $driverInstance->getItem($key); |
| 36 | 36 | |
| 37 | - if($driverInstance->isAttached($itemDetached) !== true) |
|
| 37 | + if ($driverInstance->isAttached($itemDetached) !== true) |
|
| 38 | 38 | { |
| 39 | 39 | echo '[PASS] ExtendedCacheItemPoolInterface::isAttached() identified $itemDetached as being detached.' . "\n"; |
| 40 | 40 | } |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | $status = 1; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - try{ |
|
| 47 | + try { |
|
| 48 | 48 | $driverInstance->attachItem($itemDetached); |
| 49 | 49 | echo '[FAIL] ExtendedCacheItemPoolInterface::attachItem() attached $itemDetached without trowing an error.' . "\n"; |
| 50 | 50 | $status = 1; |
| 51 | - }catch(\LogicException $e){ |
|
| 51 | + } catch (\LogicException $e) { |
|
| 52 | 52 | echo '[PASS] ExtendedCacheItemPoolInterface::attachItem() failed to attach $itemDetached by trowing a LogicException exception.' . "\n"; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | protected function driverConnect() |
| 128 | 128 | { |
| 129 | 129 | $server = isset($this->config[ 'redis' ]) ? $this->config[ 'redis' ] : [ |
| 130 | - 'host' => '127.0.0.1', |
|
| 131 | - 'port' => '6379', |
|
| 132 | - 'password' => '', |
|
| 133 | - 'database' => '', |
|
| 130 | + 'host' => '127.0.0.1', |
|
| 131 | + 'port' => '6379', |
|
| 132 | + 'password' => '', |
|
| 133 | + 'database' => '', |
|
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | 136 | $config = [ |
| 137 | - 'host' => $server[ 'host' ], |
|
| 137 | + 'host' => $server[ 'host' ], |
|
| 138 | 138 | ]; |
| 139 | 139 | |
| 140 | 140 | $port = isset($server[ 'port' ]) ? $server[ 'port' ] : ''; |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | $date = (isset($info['Server'][ 'uptime_in_seconds' ]) ? (new \DateTime())->setTimestamp(time() - $info['Server'][ 'uptime_in_seconds' ]) : 'unknown date'); |
| 185 | 185 | |
| 186 | 186 | return (new driverStatistic()) |
| 187 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 188 | - ->setRawData($this->instance->info()) |
|
| 189 | - ->setSize($size) |
|
| 190 | - ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $version, $date->format(DATE_RFC2822))); |
|
| 187 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 188 | + ->setRawData($this->instance->info()) |
|
| 189 | + ->setSize($size) |
|
| 190 | + ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $version, $date->format(DATE_RFC2822))); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | \ No newline at end of file |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | protected function driverConnect() |
| 128 | 128 | { |
| 129 | - $server = isset($this->config[ 'redis' ]) ? $this->config[ 'redis' ] : [ |
|
| 129 | + $server = isset($this->config['redis']) ? $this->config['redis'] : [ |
|
| 130 | 130 | 'host' => '127.0.0.1', |
| 131 | 131 | 'port' => '6379', |
| 132 | 132 | 'password' => '', |
@@ -134,32 +134,32 @@ discard block |
||
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | 136 | $config = [ |
| 137 | - 'host' => $server[ 'host' ], |
|
| 137 | + 'host' => $server['host'], |
|
| 138 | 138 | ]; |
| 139 | 139 | |
| 140 | - $port = isset($server[ 'port' ]) ? $server[ 'port' ] : ''; |
|
| 140 | + $port = isset($server['port']) ? $server['port'] : ''; |
|
| 141 | 141 | if ($port != '') { |
| 142 | - $config[ 'port' ] = $port; |
|
| 142 | + $config['port'] = $port; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $password = isset($server[ 'password' ]) ? $server[ 'password' ] : ''; |
|
| 145 | + $password = isset($server['password']) ? $server['password'] : ''; |
|
| 146 | 146 | if ($password != '') { |
| 147 | - $config[ 'password' ] = $password; |
|
| 147 | + $config['password'] = $password; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $database = isset($server[ 'database' ]) ? $server[ 'database' ] : ''; |
|
| 150 | + $database = isset($server['database']) ? $server['database'] : ''; |
|
| 151 | 151 | if ($database != '') { |
| 152 | - $config[ 'database' ] = $database; |
|
| 152 | + $config['database'] = $database; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : ''; |
|
| 155 | + $timeout = isset($server['timeout']) ? $server['timeout'] : ''; |
|
| 156 | 156 | if ($timeout != '') { |
| 157 | - $config[ 'timeout' ] = $timeout; |
|
| 157 | + $config['timeout'] = $timeout; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - $read_write_timeout = isset($server[ 'read_write_timeout' ]) ? $server[ 'read_write_timeout' ] : ''; |
|
| 160 | + $read_write_timeout = isset($server['read_write_timeout']) ? $server['read_write_timeout'] : ''; |
|
| 161 | 161 | if ($read_write_timeout != '') { |
| 162 | - $config[ 'read_write_timeout' ] = $read_write_timeout; |
|
| 162 | + $config['read_write_timeout'] = $read_write_timeout; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $this->instance = new PredisClient($config); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | $info = $this->instance->info(); |
| 182 | 182 | $size = (isset($info['Memory']['used_memory']) ? $info['Memory']['used_memory'] : 0); |
| 183 | 183 | $version = (isset($info['Server']['redis_version']) ? $info['Server']['redis_version'] : 0); |
| 184 | - $date = (isset($info['Server'][ 'uptime_in_seconds' ]) ? (new \DateTime())->setTimestamp(time() - $info['Server'][ 'uptime_in_seconds' ]) : 'unknown date'); |
|
| 184 | + $date = (isset($info['Server']['uptime_in_seconds']) ? (new \DateTime())->setTimestamp(time() - $info['Server']['uptime_in_seconds']) : 'unknown date'); |
|
| 185 | 185 | |
| 186 | 186 | return (new driverStatistic()) |
| 187 | 187 | ->setData(implode(', ', array_keys($this->itemInstances))) |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @param \Psr\Cache\CacheItemInterface $item |
| 60 | - * @return mixed |
|
| 60 | + * @return boolean |
|
| 61 | 61 | * @throws \InvalidArgumentException |
| 62 | 62 | */ |
| 63 | 63 | public function driverWrite(CacheItemInterface $item) |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | protected function driverRead(CacheItemInterface $item) |
| 80 | 80 | { |
| 81 | 81 | return [ |
| 82 | - self::DRIVER_DATA_WRAPPER_INDEX => true, |
|
| 83 | - self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
| 84 | - self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), |
|
| 82 | + self::DRIVER_DATA_WRAPPER_INDEX => true, |
|
| 83 | + self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
| 84 | + self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), |
|
| 85 | 85 | ]; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | { |
| 132 | 132 | $stat = new driverStatistic(); |
| 133 | 133 | $stat->setInfo('[Devtrue] A void info string') |
| 134 | - ->setSize(0) |
|
| 135 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 136 | - ->setRawData(true); |
|
| 134 | + ->setSize(0) |
|
| 135 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 136 | + ->setRawData(true); |
|
| 137 | 137 | |
| 138 | 138 | return $stat; |
| 139 | 139 | } |
@@ -133,8 +133,8 @@ |
||
| 133 | 133 | $stats = (array) zend_shm_cache_info(); |
| 134 | 134 | return (new driverStatistic()) |
| 135 | 135 | ->setData(implode(', ', array_keys($this->namespaces))) |
| 136 | - ->setInfo(sprintf("The Zend memory have %d item(s) in cache.\n For more information see RawData.",$stats[ 'items_total' ])) |
|
| 136 | + ->setInfo(sprintf("The Zend memory have %d item(s) in cache.\n For more information see RawData.", $stats['items_total'])) |
|
| 137 | 137 | ->setRawData($stats) |
| 138 | - ->setSize($stats[ 'memory_total' ]); |
|
| 138 | + ->setSize($stats['memory_total']); |
|
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | \ No newline at end of file |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | } else { |
| 84 | 84 | $item->setHit(true); |
| 85 | 85 | } |
| 86 | - }else{ |
|
| 86 | + } else{ |
|
| 87 | 87 | $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ])); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct() |
| 23 | 23 | { |
| 24 | - $this->instances =& CacheManager::getInternalInstances(); |
|
| 24 | + $this->instances = & CacheManager::getInternalInstances(); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -29,22 +29,22 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | protected function getGenericCallback() |
| 31 | 31 | { |
| 32 | - return function($method, $args){ |
|
| 32 | + return function($method, $args) { |
|
| 33 | 33 | $getterMethod = (strpos($method, 'get') === 0); |
| 34 | 34 | $return = false; |
| 35 | 35 | |
| 36 | - if($getterMethod){ |
|
| 36 | + if ($getterMethod) { |
|
| 37 | 37 | $return = []; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | foreach ($this->instances as $instance) |
| 41 | 41 | { |
| 42 | 42 | $reflectionMethod = new \ReflectionMethod(get_class($instance), $method); |
| 43 | - if($getterMethod){ |
|
| 44 | - $return[ $instance->getDriverName() ] = $reflectionMethod->invokeArgs($instance, $args); |
|
| 45 | - }else{ |
|
| 43 | + if ($getterMethod) { |
|
| 44 | + $return[$instance->getDriverName()] = $reflectionMethod->invokeArgs($instance, $args); |
|
| 45 | + } else { |
|
| 46 | 46 | $result = $reflectionMethod->invokeArgs($instance, $args); |
| 47 | - if($result !== false){ |
|
| 47 | + if ($result !== false) { |
|
| 48 | 48 | $return = $result; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -84,13 +84,13 @@ |
||
| 84 | 84 | if(is_callable($arguments[0])){ |
| 85 | 85 | if(isset($arguments[1]) && is_string($arguments[0])){ |
| 86 | 86 | $this->events[$name][$arguments[1]] = $arguments[0]; |
| 87 | - }else { |
|
| 87 | + } else { |
|
| 88 | 88 | $this->events[$name][] = $arguments[0]; |
| 89 | 89 | } |
| 90 | - }else{ |
|
| 90 | + } else{ |
|
| 91 | 91 | throw new \InvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
| 92 | 92 | } |
| 93 | - }else{ |
|
| 93 | + } else{ |
|
| 94 | 94 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | public function dispatch($eventName, ...$args) |
| 67 | 67 | { |
| 68 | 68 | $eventName = 'on' . ucfirst($eventName); |
| 69 | - if(array_key_exists($eventName, $this->events)){ |
|
| 70 | - foreach ($this->events[ $eventName ] as $event) { |
|
| 69 | + if (array_key_exists($eventName, $this->events)) { |
|
| 70 | + foreach ($this->events[$eventName] as $event) { |
|
| 71 | 71 | call_user_func_array($event, $args); |
| 72 | 72 | } |
| 73 | 73 | } |
@@ -81,17 +81,17 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function __call($name, $arguments) |
| 83 | 83 | { |
| 84 | - if(strpos($name, 'on') === 0){ |
|
| 85 | - if(is_callable($arguments[0])){ |
|
| 86 | - if(isset($arguments[1]) && is_string($arguments[0])){ |
|
| 84 | + if (strpos($name, 'on') === 0) { |
|
| 85 | + if (is_callable($arguments[0])) { |
|
| 86 | + if (isset($arguments[1]) && is_string($arguments[0])) { |
|
| 87 | 87 | $this->events[$name][$arguments[1]] = $arguments[0]; |
| 88 | - }else { |
|
| 88 | + } else { |
|
| 89 | 89 | $this->events[$name][] = $arguments[0]; |
| 90 | 90 | } |
| 91 | - }else{ |
|
| 91 | + } else { |
|
| 92 | 92 | throw new \InvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0]))); |
| 93 | 93 | } |
| 94 | - }else{ |
|
| 94 | + } else { |
|
| 95 | 95 | throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function unbindEventCallback($eventName, $callbackName) |
| 105 | 105 | { |
| 106 | - if(isset($this->events[$eventName][$callbackName])){ |
|
| 106 | + if (isset($this->events[$eventName][$callbackName])) { |
|
| 107 | 107 | unset($this->events[$eventName][$callbackName]); |
| 108 | 108 | return true; |
| 109 | 109 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (!class_exists('phpFastCache\CacheManager')) { |
| 16 | 16 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 17 | 17 | $status = 255; |
| 18 | -}else{ |
|
| 18 | +} else { |
|
| 19 | 19 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (!class_exists('phpFastCache\CacheManager')) { |
| 16 | 16 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 17 | 17 | $status = 255; |
| 18 | -}else{ |
|
| 18 | +} else{ |
|
| 19 | 19 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -25,21 +25,21 @@ |
||
| 25 | 25 | $actOnAll = new ActOnAll(); |
| 26 | 26 | $statsAry = $actOnAll->getStats(); |
| 27 | 27 | |
| 28 | -if(is_array($statsAry)){ |
|
| 29 | - if(count($statsAry) !== 3){ |
|
| 28 | +if (is_array($statsAry)) { |
|
| 29 | + if (count($statsAry) !== 3) { |
|
| 30 | 30 | $status = 1; |
| 31 | 31 | echo 'Wrong count of driverStatistics objects: Got ' . count($statsAry) . " element(s), expected 3\n"; |
| 32 | 32 | goto endOfTest; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | foreach ($statsAry as $stat) { |
| 36 | - if(!is_object($stat) || !($stat instanceof driverStatistic)){ |
|
| 36 | + if (!is_object($stat) || !($stat instanceof driverStatistic)) { |
|
| 37 | 37 | echo "\$statsAry contains one element that is not an driverStatistic object\n"; |
| 38 | 38 | goto endOfTest; |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | echo "[PASS] ActOnAll helper passed all tests\n"; |
| 42 | -}else{ |
|
| 42 | +} else { |
|
| 43 | 43 | $status = 1; |
| 44 | 44 | echo "\$statsAry is not an array\n"; |
| 45 | 45 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (!class_exists('phpFastCache\CacheManager')) { |
| 16 | 16 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 17 | 17 | $status = 255; |
| 18 | -}else{ |
|
| 18 | +} else{ |
|
| 19 | 19 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | $status = 0; |
| 17 | 17 | echo "Testing EventManager\n"; |
| 18 | 18 | |
| 19 | -EventManager::getInstance()->onCacheSaveItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){ |
|
| 20 | - if($item->get() === 1000){ |
|
| 19 | +EventManager::getInstance()->onCacheSaveItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item) { |
|
| 20 | + if ($item->get() === 1000) { |
|
| 21 | 21 | $item->increment(337); |
| 22 | 22 | } |
| 23 | 23 | }); |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | $cacheInstance->save($item); |
| 31 | 31 | |
| 32 | 32 | |
| 33 | -if($cacheInstance->getItem($cacheKey)->get() === 1337){ |
|
| 33 | +if ($cacheInstance->getItem($cacheKey)->get() === 1337) { |
|
| 34 | 34 | echo "[PASS] The dispatched event executed the custom callback to alter to item.\n"; |
| 35 | -}else{ |
|
| 35 | +} else { |
|
| 36 | 36 | echo "[FAIL] The dispatched event did not worked well, the expected value '1337', got '" . (int) $cacheInstance->getItem($cacheKey)->get() . "'\n"; |
| 37 | 37 | $status = 1; |
| 38 | 38 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | if (!class_exists('phpFastCache\CacheManager')) { |
| 16 | 16 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 17 | 17 | $status = 255; |
| 18 | -}else{ |
|
| 18 | +} else{ |
|
| 19 | 19 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 20 | 20 | } |
| 21 | 21 | |