@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | - * @return Cacheer |
|
| 69 | - */ |
|
| 68 | + * @return Cacheer |
|
| 69 | + */ |
|
| 70 | 70 | public function useArrayDriver() |
| 71 | 71 | { |
| 72 | 72 | $this->cacheer->cacheStore = new ArrayCacheStore($this->logPath); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * @return Cacheer |
| 78 | - */ |
|
| 78 | + */ |
|
| 79 | 79 | public function useDefaultDriver() |
| 80 | 80 | { |
| 81 | 81 | if (!isset($this->cacheer->options['cacheDir'])) { |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
| 95 | - * @param mixed $dirName |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 95 | + * @param mixed $dirName |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | 98 | private function isDir(mixed $dirName) |
| 99 | 99 | { |
| 100 | - if (is_dir($dirName)) { |
|
| 101 | - return true; |
|
| 102 | - } |
|
| 103 | - return mkdir($dirName, 0755, true); |
|
| 100 | + if (is_dir($dirName)) { |
|
| 101 | + return true; |
|
| 102 | + } |
|
| 103 | + return mkdir($dirName, 0755, true); |
|
| 104 | 104 | } |
| 105 | 105 | } |
@@ -14,9 +14,9 @@ discard block |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @param string $expiration |
|
| 18 | - * @return int |
|
| 19 | - */ |
|
| 17 | + * @param string $expiration |
|
| 18 | + * @return int |
|
| 19 | + */ |
|
| 20 | 20 | public static function convertExpirationToSeconds(string $expiration) |
| 21 | 21 | { |
| 22 | 22 | $units = [ |
@@ -58,10 +58,10 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | - * @param string|int $ttl |
|
| 62 | - * @param int $defaultTTL |
|
| 63 | - * @return mixed |
|
| 64 | - */ |
|
| 61 | + * @param string|int $ttl |
|
| 62 | + * @param int $defaultTTL |
|
| 63 | + * @return mixed |
|
| 64 | + */ |
|
| 65 | 65 | public static function ttl($ttl = null, ?int $defaultTTL = null) { |
| 66 | 66 | if ($ttl) { |
| 67 | 67 | $ttl = is_string($ttl) ? self::convertExpirationToSeconds($ttl) : $ttl; |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | return $ttl; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @param mixed $currentCacheData |
|
| 76 | - * @param mixed $cacheData |
|
| 77 | - * @return array |
|
| 78 | - */ |
|
| 79 | - public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
| 80 | - { |
|
| 74 | + /** |
|
| 75 | + * @param mixed $currentCacheData |
|
| 76 | + * @param mixed $cacheData |
|
| 77 | + * @return array |
|
| 78 | + */ |
|
| 79 | + public static function arrayIdentifier(mixed $currentCacheData, mixed $cacheData) |
|
| 80 | + { |
|
| 81 | 81 | return CacheerHelper::arrayIdentifier($currentCacheData, $cacheData); |
| 82 | - } |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function toJson(int $options = 0) |
| 60 | 60 | { |
| 61 | - return parent::toJson($options); |
|
| 61 | + return parent::toJson($options); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -7,39 +7,39 @@ discard block |
||
| 7 | 7 | class CacheDatabaseException extends BaseException |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** @param string $before */ |
|
| 11 | - private static string $before = "<Database Cache Store Exception>"; |
|
| 10 | + /** @param string $before */ |
|
| 11 | + private static string $before = "<Database Cache Store Exception>"; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param string $message |
|
| 15 | - * @param int $code |
|
| 16 | - * @param Exception|null $previous |
|
| 17 | - * @param array $details |
|
| 18 | - * @return self |
|
| 19 | - */ |
|
| 20 | - public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
|
| 21 | - { |
|
| 13 | + /** |
|
| 14 | + * @param string $message |
|
| 15 | + * @param int $code |
|
| 16 | + * @param Exception|null $previous |
|
| 17 | + * @param array $details |
|
| 18 | + * @return self |
|
| 19 | + */ |
|
| 20 | + public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
|
| 21 | + { |
|
| 22 | 22 | return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
| 23 | - } |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public static function getBefore(): string |
|
| 30 | - { |
|
| 26 | + /** |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public static function getBefore(): string |
|
| 30 | + { |
|
| 31 | 31 | return self::$before; |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return void |
|
| 36 | - */ |
|
| 37 | - public static function setBefore(string $text): void |
|
| 38 | - { |
|
| 34 | + /** |
|
| 35 | + * @return void |
|
| 36 | + */ |
|
| 37 | + public static function setBefore(string $text): void |
|
| 38 | + { |
|
| 39 | 39 | self::$before = $text; |
| 40 | - } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /* |
|
| 42 | + /* |
|
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | 45 | public function toArray() |
@@ -61,6 +61,6 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | public function toJson(int $options = 0) |
| 63 | 63 | { |
| 64 | - return parent::toJson($options); |
|
| 64 | + return parent::toJson($options); |
|
| 65 | 65 | } |
| 66 | 66 | } |
@@ -19,7 +19,7 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
| 21 | 21 | { |
| 22 | - return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
|
| 22 | + return new self(self::getBefore() . ": " . $message, $code, $previous, $details); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * @param string $dir |
|
| 19 | - * @return void |
|
| 20 | - */ |
|
| 18 | + * @param string $dir |
|
| 19 | + * @return void |
|
| 20 | + */ |
|
| 21 | 21 | public function createDirectory(string $dir) |
| 22 | 22 | { |
| 23 | 23 | if ((!file_exists($dir) || !is_dir($dir)) && !mkdir($dir, 0755, true)) { |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | - * @param string $filename |
|
| 30 | - * @param string $data |
|
| 31 | - * @return void |
|
| 32 | - */ |
|
| 29 | + * @param string $filename |
|
| 30 | + * @param string $data |
|
| 31 | + * @return void |
|
| 32 | + */ |
|
| 33 | 33 | public function writeFile(string $filename, string $data) |
| 34 | 34 | { |
| 35 | 35 | if (!@file_put_contents($filename, $data, LOCK_EX)) { |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * @param string $filename |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 41 | + * @param string $filename |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | 44 | public function readFile(string $filename) |
| 45 | 45 | { |
| 46 | 46 | if (!$this->fileExists($filename)) { |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * @param string $filename |
|
| 54 | - * @return bool |
|
| 55 | - */ |
|
| 53 | + * @param string $filename |
|
| 54 | + * @return bool |
|
| 55 | + */ |
|
| 56 | 56 | public function fileExists(string $filename) |
| 57 | 57 | { |
| 58 | 58 | return file_exists($filename); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * @param string $filename |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 62 | + * @param string $filename |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | 65 | public function removeFile(string $filename) |
| 66 | 66 | { |
| 67 | 67 | if (file_exists($filename)) { |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | - * @param string $dir |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 73 | + * @param string $dir |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | 76 | public function clearDirectory(string $dir) |
| 77 | 77 | { |
| 78 | 78 | $iterator = new RecursiveIteratorIterator( |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | - * @param mixed $data |
|
| 90 | - * @param bool $serialize |
|
| 91 | - */ |
|
| 89 | + * @param mixed $data |
|
| 90 | + * @param bool $serialize |
|
| 91 | + */ |
|
| 92 | 92 | public function serialize(mixed $data, bool $serialize = true) |
| 93 | 93 | { |
| 94 | 94 | if($serialize) { |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | */ |
| 92 | 92 | public function serialize(mixed $data, bool $serialize = true) |
| 93 | 93 | { |
| 94 | - if($serialize) { |
|
| 94 | + if ($serialize) { |
|
| 95 | 95 | return serialize($data); |
| 96 | 96 | } |
| 97 | 97 | return unserialize($data); |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function toJson(int $options = 0) |
| 60 | 60 | { |
| 61 | - return parent::toJson($options); |
|
| 61 | + return parent::toJson($options); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | public function toJson(int $options = 0) |
| 60 | 60 | { |
| 61 | - return parent::toJson($options); |
|
| 61 | + return parent::toJson($options); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -7,26 +7,26 @@ discard block |
||
| 7 | 7 | class OptionBuildTest extends TestCase |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - private $cache; |
|
| 11 | - private $cacheDir; |
|
| 10 | + private $cache; |
|
| 11 | + private $cacheDir; |
|
| 12 | 12 | |
| 13 | - protected function setUp(): void |
|
| 14 | - { |
|
| 13 | + protected function setUp(): void |
|
| 14 | + { |
|
| 15 | 15 | $this->cacheDir = __DIR__ . '/cache'; |
| 16 | 16 | if (!file_exists($this->cacheDir) || !is_dir($this->cacheDir)) { |
| 17 | - mkdir($this->cacheDir, 0755, true); |
|
| 17 | + mkdir($this->cacheDir, 0755, true); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | $this->cache = new Cacheer(); |
| 21 | - } |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - protected function tearDown(): void |
|
| 24 | - { |
|
| 23 | + protected function tearDown(): void |
|
| 24 | + { |
|
| 25 | 25 | $this->cache->flushCache(); |
| 26 | - } |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function test_it_can_set_cache_directory() |
|
| 29 | - { |
|
| 28 | + public function test_it_can_set_cache_directory() |
|
| 29 | + { |
|
| 30 | 30 | $cacheDir = __DIR__ . "/cache"; |
| 31 | 31 | |
| 32 | 32 | $options = OptionBuilder::forFile() |
@@ -35,23 +35,23 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | $this->assertArrayHasKey('cacheDir', $options); |
| 37 | 37 | $this->assertEquals($cacheDir, $options['cacheDir']); |
| 38 | - } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | - public function test_it_can_set_expiration_time() |
|
| 41 | + public function test_it_can_set_expiration_time() |
|
| 42 | 42 | { |
| 43 | 43 | |
| 44 | - $options = OptionBuilder::forFile() |
|
| 45 | - ->expirationTime('2 hours') |
|
| 46 | - ->build(); |
|
| 44 | + $options = OptionBuilder::forFile() |
|
| 45 | + ->expirationTime('2 hours') |
|
| 46 | + ->build(); |
|
| 47 | 47 | |
| 48 | - $this->assertArrayHasKey('expirationTime', $options); |
|
| 49 | - $this->assertEquals('2 hours', $options['expirationTime']); |
|
| 48 | + $this->assertArrayHasKey('expirationTime', $options); |
|
| 49 | + $this->assertEquals('2 hours', $options['expirationTime']); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function test_it_can_set_flush_after() |
| 53 | 53 | { |
| 54 | - $options = OptionBuilder::forFile() |
|
| 54 | + $options = OptionBuilder::forFile() |
|
| 55 | 55 | ->flushAfter('11 seconds') |
| 56 | 56 | ->build(); |
| 57 | 57 | |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | public function test_it_can_set_multiple_options_together() |
| 63 | 63 | { |
| 64 | - $cacheDir = __DIR__ . "/cache"; |
|
| 64 | + $cacheDir = __DIR__ . "/cache"; |
|
| 65 | 65 | |
| 66 | - $options = OptionBuilder::forFile() |
|
| 66 | + $options = OptionBuilder::forFile() |
|
| 67 | 67 | ->dir($cacheDir) |
| 68 | 68 | ->expirationTime('1 day') |
| 69 | 69 | ->flushAfter('30 minutes') |
@@ -76,41 +76,41 @@ discard block |
||
| 76 | 76 | ], $options); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
| 79 | + public function test_it_allows_setting_expiration_time_with_timebuilder() |
|
| 80 | 80 | { |
| 81 | - $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
| 82 | - $this->assertArrayHasKey('expirationTime', $options); |
|
| 83 | - $this->assertEquals('1 weeks', $options['expirationTime']); |
|
| 81 | + $options = OptionBuilder::forFile()->expirationTime()->week(1)->build(); |
|
| 82 | + $this->assertArrayHasKey('expirationTime', $options); |
|
| 83 | + $this->assertEquals('1 weeks', $options['expirationTime']); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - public function test_it_allows_setting_flush_after_with_timebuilder() |
|
| 87 | - { |
|
| 86 | + public function test_it_allows_setting_flush_after_with_timebuilder() |
|
| 87 | + { |
|
| 88 | 88 | $options = OptionBuilder::forFile()->flushAfter()->second(10)->build(); |
| 89 | 89 | $this->assertArrayHasKey('flushAfter', $options); |
| 90 | 90 | $this->assertEquals('10 seconds', $options['flushAfter']); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
| 94 | - { |
|
| 93 | + public function test_it_can_set_multiple_options_together_with_timebuilder() |
|
| 94 | + { |
|
| 95 | 95 | $cacheDir = __DIR__ . "/cache"; |
| 96 | 96 | $options = OptionBuilder::forFile() |
| 97 | - ->dir($cacheDir) |
|
| 98 | - ->expirationTime()->week(1) |
|
| 99 | - ->flushAfter()->minute(10) |
|
| 100 | - ->build(); |
|
| 97 | + ->dir($cacheDir) |
|
| 98 | + ->expirationTime()->week(1) |
|
| 99 | + ->flushAfter()->minute(10) |
|
| 100 | + ->build(); |
|
| 101 | 101 | |
| 102 | 102 | $this->assertEquals([ |
| 103 | 103 | 'cacheDir' => $cacheDir, |
| 104 | 104 | 'expirationTime' => '1 weeks', |
| 105 | 105 | 'flushAfter' => '10 minutes', |
| 106 | 106 | ], $options); |
| 107 | - } |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - public function test_it_returns_empty_array_when_no_options_are_set() |
|
| 110 | - { |
|
| 109 | + public function test_it_returns_empty_array_when_no_options_are_set() |
|
| 110 | + { |
|
| 111 | 111 | $options = OptionBuilder::forFile()->build(); |
| 112 | 112 | $this->assertIsArray($options); |
| 113 | 113 | $this->assertEmpty($options); |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param string|int $ttl |
| 119 | 119 | * @return mixed |
| 120 | 120 | */ |
| 121 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 121 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 122 | 122 | { |
| 123 | 123 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
| 124 | 124 | $cacheData = $this->redis->get($fullCacheKey); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param string|int $ttl |
| 140 | 140 | * @return array |
| 141 | 141 | */ |
| 142 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 142 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 143 | 143 | { |
| 144 | 144 | $results = []; |
| 145 | 145 | foreach ($cacheKeys as $cacheKey) { |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | * @param string|int|null $ttl |
| 228 | 228 | * @return mixed |
| 229 | 229 | */ |
| 230 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
| 230 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null) |
|
| 231 | 231 | { |
| 232 | 232 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
| 233 | 233 | $serializedData = CacheRedisHelper::serialize($cacheData); |
| 234 | 234 | |
| 235 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
| 235 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int)$ttl, $serializedData) |
|
| 236 | 236 | : $this->redis->set($cacheFullKey, $serializedData); |
| 237 | 237 | |
| 238 | 238 | if ($result) { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @param string $namespace |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
| 272 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
| 273 | 273 | { |
| 274 | 274 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
| 275 | 275 | $dump = $this->getDump($cacheFullKey); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param mixed $dump |
| 298 | 298 | * @return bool |
| 299 | 299 | */ |
| 300 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
| 300 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump) |
|
| 301 | 301 | { |
| 302 | 302 | try { |
| 303 | 303 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |