| @@ -36,9 +36,9 @@ discard block | ||
| 36 | 36 | } | 
| 37 | 37 | |
| 38 | 38 | /** | 
| 39 | - * @param string $databaseDir | |
| 40 | - * @return void | |
| 41 | - */ | |
| 39 | + * @param string $databaseDir | |
| 40 | + * @return void | |
| 41 | + */ | |
| 42 | 42 | private static function createDatabaseDir(string $databaseDir) | 
| 43 | 43 |      { | 
| 44 | 44 |          if (!is_dir($databaseDir)) { | 
| @@ -47,9 +47,9 @@ discard block | ||
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| 50 | - * @param string $dbFile | |
| 51 | - * @return void | |
| 52 | - */ | |
| 50 | + * @param string $dbFile | |
| 51 | + * @return void | |
| 52 | + */ | |
| 53 | 53 | private static function createDatabaseFile(string $dbFile) | 
| 54 | 54 |      { | 
| 55 | 55 |          if (!file_exists($dbFile)) { | 
| @@ -58,9 +58,9 @@ discard block | ||
| 58 | 58 | } | 
| 59 | 59 | |
| 60 | 60 | /** | 
| 61 | - * @param string $database | |
| 62 | - * @return string | |
| 63 | - */ | |
| 61 | + * @param string $database | |
| 62 | + * @return string | |
| 63 | + */ | |
| 64 | 64 | private static function checkExtension(string $database) | 
| 65 | 65 |      { | 
| 66 | 66 |          if (strpos($database, '.sqlite') === false) { | 
| @@ -9,8 +9,8 @@ | ||
| 9 | 9 | */ | 
| 10 | 10 | interface CacheerInterface | 
| 11 | 11 |  { | 
| 12 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600); | |
| 13 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600); | |
| 12 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600); | |
| 13 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600); | |
| 14 | 14 | public function flushCache(); | 
| 15 | 15 | public function clearCache(string $cacheKey, string $namespace = ''); | 
| 16 | 16 | public function has(string $cacheKey, string $namespace = ''); | 
| @@ -18,8 +18,8 @@ discard block | ||
| 18 | 18 | } | 
| 19 | 19 | |
| 20 | 20 | /** | 
| 21 | - * @return string|false | |
| 22 | - */ | |
| 21 | + * @return string|false | |
| 22 | + */ | |
| 23 | 23 | public function toJson() | 
| 24 | 24 |      { | 
| 25 | 25 | return json_encode( | 
| @@ -31,24 +31,24 @@ discard block | ||
| 31 | 31 | } | 
| 32 | 32 | |
| 33 | 33 | /** | 
| 34 | - * @return array | |
| 35 | - */ | |
| 34 | + * @return array | |
| 35 | + */ | |
| 36 | 36 | public function toArray() | 
| 37 | 37 |      { | 
| 38 | 38 | return (array)$this->data; | 
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | 41 | /** | 
| 42 | - * @return string | |
| 43 | - */ | |
| 42 | + * @return string | |
| 43 | + */ | |
| 44 | 44 | public function toString() | 
| 45 | 45 |      { | 
| 46 | 46 | return (string)$this->data; | 
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| 50 | - * @return object | |
| 51 | - */ | |
| 50 | + * @return object | |
| 51 | + */ | |
| 52 | 52 | public function toObject() | 
| 53 | 53 |      { | 
| 54 | 54 | return (object)$this->data; | 
| @@ -23,49 +23,49 @@ discard block | ||
| 23 | 23 | } | 
| 24 | 24 | |
| 25 | 25 | /** | 
| 26 | - * @return void | |
| 27 | - */ | |
| 26 | + * @return void | |
| 27 | + */ | |
| 28 | 28 | public function info($message) | 
| 29 | 29 |      { | 
| 30 | 30 |          $this->log('INFO', $message); | 
| 31 | 31 | } | 
| 32 | 32 | |
| 33 | 33 | /** | 
| 34 | - * @return void | |
| 35 | - */ | |
| 34 | + * @return void | |
| 35 | + */ | |
| 36 | 36 | public function warning($message) | 
| 37 | 37 |      { | 
| 38 | 38 |          $this->log('WARNING', $message); | 
| 39 | 39 | } | 
| 40 | 40 | |
| 41 | 41 | /** | 
| 42 | - * @return void | |
| 43 | - */ | |
| 42 | + * @return void | |
| 43 | + */ | |
| 44 | 44 | public function error($message) | 
| 45 | 45 |      { | 
| 46 | 46 |          $this->log('ERROR', $message); | 
| 47 | 47 | } | 
| 48 | 48 | |
| 49 | 49 | /** | 
| 50 | - * @return void | |
| 51 | - */ | |
| 50 | + * @return void | |
| 51 | + */ | |
| 52 | 52 | public function debug($message) | 
| 53 | 53 |      { | 
| 54 | 54 |          $this->log('DEBUG', $message); | 
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | /** | 
| 58 | - * @param mixed $level | |
| 59 | - * @return string|int|false | |
| 60 | - */ | |
| 58 | + * @param mixed $level | |
| 59 | + * @return string|int|false | |
| 60 | + */ | |
| 61 | 61 | private function shouldLog(mixed $level) | 
| 62 | 62 |      { | 
| 63 | 63 | return array_search($level, $this->logLevels) >= array_search($this->logLevel, $this->logLevels); | 
| 64 | 64 | } | 
| 65 | 65 | |
| 66 | 66 | /** | 
| 67 | - * @return void | |
| 68 | - */ | |
| 67 | + * @return void | |
| 68 | + */ | |
| 69 | 69 | private function rotateLog() | 
| 70 | 70 |      { | 
| 71 | 71 |          if (file_exists($this->logFile) && filesize($this->logFile) >= $this->maxFileSize) { | 
| @@ -75,10 +75,10 @@ discard block | ||
| 75 | 75 | } | 
| 76 | 76 | |
| 77 | 77 | /** | 
| 78 | - * @param mixed $level | |
| 79 | - * @param string $message | |
| 80 | - * @return void | |
| 81 | - */ | |
| 78 | + * @param mixed $level | |
| 79 | + * @param string $message | |
| 80 | + * @return void | |
| 81 | + */ | |
| 82 | 82 | private function log($level, $message) | 
| 83 | 83 |      { | 
| 84 | 84 |          if (!$this->shouldLog($level)) { | 
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | */ | 
| 20 | 20 | public static function serialize(mixed $data, bool $serialize = true) | 
| 21 | 21 |    { | 
| 22 | -    if($serialize) { | |
| 22 | +    if ($serialize) { | |
| 23 | 23 | return serialize($data); | 
| 24 | 24 | } | 
| 25 | 25 | |
| @@ -13,20 +13,20 @@ discard block | ||
| 13 | 13 | class CacheRedisHelper | 
| 14 | 14 |  { | 
| 15 | 15 | |
| 16 | - /** | |
| 17 | - * @param mixed $data | |
| 18 | - * @param bool $serialize | |
| 19 | - * @return mixed | |
| 20 | - */ | |
| 21 | - public static function serialize(mixed $data, bool $serialize = true) | |
| 22 | -  { | |
| 16 | + /** | |
| 17 | + * @param mixed $data | |
| 18 | + * @param bool $serialize | |
| 19 | + * @return mixed | |
| 20 | + */ | |
| 21 | + public static function serialize(mixed $data, bool $serialize = true) | |
| 22 | +    { | |
| 23 | 23 |      if($serialize) { | 
| 24 | - return serialize($data); | |
| 24 | + return serialize($data); | |
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | 27 | return unserialize($data); | 
| 28 | 28 | |
| 29 | - } | |
| 29 | + } | |
| 30 | 30 | |
| 31 | 31 | /** | 
| 32 | 32 | * @param array $item | 
| @@ -49,15 +49,15 @@ discard block | ||
| 49 | 49 | return CacheerHelper::mergeCacheData($cacheData); | 
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | - /** | |
| 53 | - * @param mixed $currentCacheData | |
| 54 | - * @param mixed $cacheData | |
| 55 | - * @return array | |
| 56 | - */ | |
| 57 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) | |
| 58 | -  { | |
| 59 | - return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); | |
| 60 | - } | |
| 52 | + /** | |
| 53 | + * @param mixed $currentCacheData | |
| 54 | + * @param mixed $cacheData | |
| 55 | + * @return array | |
| 56 | + */ | |
| 57 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) | |
| 58 | +    { | |
| 59 | + return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); | |
| 60 | + } | |
| 61 | 61 | |
| 62 | 62 | } | 
| 63 | 63 | |
| @@ -37,7 +37,7 @@ | ||
| 37 | 37 | */ | 
| 38 | 38 | private static function auth() | 
| 39 | 39 |    { | 
| 40 | -    if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { | |
| 40 | +    if (is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { | |
| 41 | 41 | self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); | 
| 42 | 42 | } | 
| 43 | 43 | } | 
| @@ -14,38 +14,38 @@ | ||
| 14 | 14 | class RedisCacheManager | 
| 15 | 15 |  { | 
| 16 | 16 | |
| 17 | - /** @var Predis\Client */ | |
| 18 | - private static $redis; | |
| 17 | + /** @var Predis\Client */ | |
| 18 | + private static $redis; | |
| 19 | 19 | |
| 20 | - /** @param string $namespace */ | |
| 21 | - private static $namespace; | |
| 20 | + /** @param string $namespace */ | |
| 21 | + private static $namespace; | |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * @return Client | |
| 25 | - */ | |
| 26 | - public static function connect() | |
| 27 | -  { | |
| 23 | + /** | |
| 24 | + * @return Client | |
| 25 | + */ | |
| 26 | + public static function connect() | |
| 27 | +    { | |
| 28 | 28 | Autoloader::register(); | 
| 29 | 29 | self::$redis = new Client([ | 
| 30 | - 'scheme' => 'tcp', | |
| 31 | - 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'], | |
| 32 | - 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'], | |
| 33 | - 'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'], | |
| 34 | - 'database' => 0 | |
| 30 | + 'scheme' => 'tcp', | |
| 31 | + 'host' => REDIS_CONNECTION_CONFIG['REDIS_HOST'], | |
| 32 | + 'port' => REDIS_CONNECTION_CONFIG['REDIS_PORT'], | |
| 33 | + 'password' => REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'], | |
| 34 | + 'database' => 0 | |
| 35 | 35 | ]); | 
| 36 | 36 | self::auth(); | 
| 37 | 37 | self::$namespace = REDIS_CONNECTION_CONFIG['REDIS_NAMESPACE'] ?? 'Cache'; | 
| 38 | 38 | return self::$redis; | 
| 39 | - } | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | - private static function auth() | |
| 45 | -  { | |
| 41 | + /** | |
| 42 | + * @return void | |
| 43 | + */ | |
| 44 | + private static function auth() | |
| 45 | +    { | |
| 46 | 46 |      if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { | 
| 47 | - self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); | |
| 47 | + self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); | |
| 48 | + } | |
| 48 | 49 | } | 
| 49 | - } | |
| 50 | 50 | |
| 51 | 51 | } | 
| @@ -46,13 +46,13 @@ | ||
| 46 | 46 | private string $lastFlushTimeFile; | 
| 47 | 47 | |
| 48 | 48 | /** | 
| 49 | - * @var CacheLogger | |
| 50 | - */ | |
| 49 | + * @var CacheLogger | |
| 50 | + */ | |
| 51 | 51 | private $logger = null; | 
| 52 | 52 | |
| 53 | 53 | /** | 
| 54 | - * @var FileCacheManager | |
| 55 | - */ | |
| 54 | + * @var FileCacheManager | |
| 55 | + */ | |
| 56 | 56 | private FileCacheManager $fileManager; | 
| 57 | 57 | |
| 58 | 58 | public function __construct(array $options = []) | 
| @@ -158,7 +158,7 @@ discard block | ||
| 158 | 158 | * @param string|int $ttl | 
| 159 | 159 | * @return string | 
| 160 | 160 | */ | 
| 161 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) | |
| 161 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) | |
| 162 | 162 |      { | 
| 163 | 163 | |
| 164 | 164 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); | 
| @@ -181,7 +181,7 @@ discard block | ||
| 181 | 181 | * @param string|int $ttl | 
| 182 | 182 | * @return array | 
| 183 | 183 | */ | 
| 184 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) | |
| 184 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) | |
| 185 | 185 |      { | 
| 186 | 186 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); | 
| 187 | 187 | $results = []; | 
| @@ -223,7 +223,7 @@ discard block | ||
| 223 | 223 | * @param string|int $ttl | 
| 224 | 224 | * @return void | 
| 225 | 225 | */ | 
| 226 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) | |
| 226 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) | |
| 227 | 227 |      { | 
| 228 | 228 | $cacheFile = $this->buildCacheFilePath($cacheKey, $namespace); | 
| 229 | 229 | $data = $this->fileManager->serialize($cacheData); | 
| @@ -256,7 +256,7 @@ discard block | ||
| 256 | 256 | * @param string $namespace | 
| 257 | 257 | * @return void | 
| 258 | 258 | */ | 
| 259 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') | |
| 259 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') | |
| 260 | 260 |      { | 
| 261 | 261 | $cacheData = $this->getCache($cacheKey, $namespace); | 
| 262 | 262 |          if ($cacheData) { | 
| @@ -346,12 +346,12 @@ discard block | ||
| 346 | 346 |      { | 
| 347 | 347 | $flushAfterSeconds = CacheFileHelper::convertExpirationToSeconds($flushAfter); | 
| 348 | 348 | |
| 349 | -        if(!$this->fileManager->fileExists($this->lastFlushTimeFile)) { | |
| 349 | +        if (!$this->fileManager->fileExists($this->lastFlushTimeFile)) { | |
| 350 | 350 | $this->fileManager->writeFile($this->lastFlushTimeFile, time()); | 
| 351 | 351 | return; | 
| 352 | 352 | } | 
| 353 | 353 | |
| 354 | - $lastFlushTime = (int) $this->fileManager->readFile($this->lastFlushTimeFile); | |
| 354 | + $lastFlushTime = (int)$this->fileManager->readFile($this->lastFlushTimeFile); | |
| 355 | 355 | |
| 356 | 356 |          if ((time() - $lastFlushTime) >= $flushAfterSeconds) { | 
| 357 | 357 | $this->flushCache(); | 
| @@ -48,10 +48,10 @@ discard block | ||
| 48 | 48 | } | 
| 49 | 49 | |
| 50 | 50 | /** | 
| 51 | - * @param string $cacheKey | |
| 52 | - * @param string $namespace | |
| 53 | - * @return mixed | |
| 54 | - */ | |
| 51 | + * @param string $cacheKey | |
| 52 | + * @param string $namespace | |
| 53 | + * @return mixed | |
| 54 | + */ | |
| 55 | 55 | public function retrieve(string $cacheKey, string $namespace = '') | 
| 56 | 56 |      { | 
| 57 | 57 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); | 
| @@ -105,11 +105,11 @@ discard block | ||
| 105 | 105 | } | 
| 106 | 106 | |
| 107 | 107 | /** | 
| 108 | - * @param string $cacheKey | |
| 109 | - * @param string|int $ttl | |
| 110 | - * @param string $namespace | |
| 111 | - * @return bool | |
| 112 | - */ | |
| 108 | + * @param string $cacheKey | |
| 109 | + * @param string|int $ttl | |
| 110 | + * @param string $namespace | |
| 111 | + * @return bool | |
| 112 | + */ | |
| 113 | 113 | public function renew(string $cacheKey, string|int $ttl, string $namespace = '') | 
| 114 | 114 |      { | 
| 115 | 115 |          $currentTime = date('Y-m-d H:i:s'); | 
| @@ -163,9 +163,9 @@ discard block | ||
| 163 | 163 | } | 
| 164 | 164 | |
| 165 | 165 | /** | 
| 166 | - * @param string $driver | |
| 167 | - * @return string | |
| 168 | - */ | |
| 166 | + * @param string $driver | |
| 167 | + * @return string | |
| 168 | + */ | |
| 169 | 169 | private function getCurrentDateTime(string $driver) | 
| 170 | 170 |      { | 
| 171 | 171 |          return ($driver === 'sqlite') ? "DATETIME('now', 'localtime')" : "NOW()"; | 
| @@ -29,7 +29,7 @@ discard block | ||
| 29 | 29 | * @param string|int $ttl | 
| 30 | 30 | * @return bool | 
| 31 | 31 | */ | 
| 32 | - public function store(string $cacheKey, mixed $cacheData, string $namespace, string|int $ttl = 3600) | |
| 32 | + public function store(string $cacheKey, mixed $cacheData, string $namespace, string | int $ttl = 3600) | |
| 33 | 33 |      { | 
| 34 | 34 |          if (!empty($this->retrieve($cacheKey, $namespace))) { | 
| 35 | 35 | return $this->update($cacheKey, $cacheData, $namespace); | 
| @@ -174,7 +174,7 @@ discard block | ||
| 174 | 174 | * @param string $namespace | 
| 175 | 175 | * @return bool | 
| 176 | 176 | */ | 
| 177 | - public function renew(string $cacheKey, string|int $ttl, string $namespace = '') | |
| 177 | + public function renew(string $cacheKey, string | int $ttl, string $namespace = '') | |
| 178 | 178 |      { | 
| 179 | 179 |          $currentTime = date('Y-m-d H:i:s'); | 
| 180 | 180 |          if (!$this->hasValidCache($cacheKey, $namespace, $currentTime)) { | 
| @@ -183,7 +183,7 @@ discard block | ||
| 183 | 183 | |
| 184 | 184 | $query = $this->getRenewExpirationQueryWithDriver(); | 
| 185 | 185 | $stmt = $this->connection->prepare($query); | 
| 186 | -        $stmt->bindValue(':ttl', (int) $ttl, PDO::PARAM_INT); | |
| 186 | +        $stmt->bindValue(':ttl', (int)$ttl, PDO::PARAM_INT); | |
| 187 | 187 |          $stmt->bindValue(':cacheKey', $cacheKey); | 
| 188 | 188 |          $stmt->bindValue(':namespace', $namespace); | 
| 189 | 189 |          $stmt->bindValue(':currentTime', $currentTime); | 
| @@ -23,15 +23,15 @@ | ||
| 23 | 23 | echo "Cache Found: "; | 
| 24 | 24 | print_r($Cacheer->getCache($cacheKey)); | 
| 25 | 25 |  } else { | 
| 26 | - echo $Cacheer->getMessage(); | |
| 26 | + echo $Cacheer->getMessage(); | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | // Renovando os dados do cache | 
| 30 | 30 | $Cacheer->renewCache($cacheKey, 3600); | 
| 31 | 31 | |
| 32 | 32 |  if($Cacheer->isSuccess()){ | 
| 33 | - echo $Cacheer->getMessage() . PHP_EOL; | |
| 33 | + echo $Cacheer->getMessage() . PHP_EOL; | |
| 34 | 34 |  } else { | 
| 35 | - echo $Cacheer->getMessage() . PHP_EOL; | |
| 35 | + echo $Cacheer->getMessage() . PHP_EOL; | |
| 36 | 36 | |
| 37 | 37 | } | 
| 38 | 38 | \ No newline at end of file | 
| @@ -19,7 +19,7 @@ discard block | ||
| 19 | 19 | $Cacheer->putCache($cacheKey, $userProfile, ttl: 300); | 
| 20 | 20 | |
| 21 | 21 | // Recuperando dados do cache | 
| 22 | -if($Cacheer->isSuccess()){ | |
| 22 | +if ($Cacheer->isSuccess()) { | |
| 23 | 23 | echo "Cache Found: "; | 
| 24 | 24 | print_r($Cacheer->getCache($cacheKey)); | 
| 25 | 25 |  } else { | 
| @@ -29,7 +29,7 @@ discard block | ||
| 29 | 29 | // Renovando os dados do cache | 
| 30 | 30 | $Cacheer->renewCache($cacheKey, 3600); | 
| 31 | 31 | |
| 32 | -if($Cacheer->isSuccess()){ | |
| 32 | +if ($Cacheer->isSuccess()) { | |
| 33 | 33 | echo $Cacheer->getMessage() . PHP_EOL; | 
| 34 | 34 |  } else { | 
| 35 | 35 | echo $Cacheer->getMessage() . PHP_EOL; |