@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | public function get($key, $default = null) |
30 | 30 | { |
31 | 31 | $this->validateKey($key); |
32 | - if (\array_key_exists($key, $this->cache) && !$this->isExpired($key)) { |
|
32 | + if (\array_key_exists($key, $this->cache) && !$this->isExpired($key)){ |
|
33 | 33 | /** @psalm-var mixed $value */ |
34 | 34 | $value = $this->cache[$key][0]; |
35 | - if (\is_object($value)) { |
|
35 | + if (\is_object($value)){ |
|
36 | 36 | $value = clone $value; |
37 | 37 | } |
38 | 38 | |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | { |
47 | 47 | $this->validateKey($key); |
48 | 48 | $expiration = $this->ttlToExpiration($ttl); |
49 | - if ($expiration < 0) { |
|
49 | + if ($expiration < 0){ |
|
50 | 50 | return $this->delete($key); |
51 | 51 | } |
52 | - if (\is_object($value)) { |
|
52 | + if (\is_object($value)){ |
|
53 | 53 | $value = clone $value; |
54 | 54 | } |
55 | 55 | $this->cache[$key] = [$value, $expiration]; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->validateKeys($keys); |
82 | 82 | /** @psalm-var string[] $keys */ |
83 | 83 | $result = []; |
84 | - foreach ($keys as $key) { |
|
84 | + foreach ($keys as $key){ |
|
85 | 85 | /** @psalm-var mixed */ |
86 | 86 | $result[$key] = $this->get($key, $default); |
87 | 87 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @psalm-var mixed $value |
101 | 101 | */ |
102 | - foreach ($values as $key => $value) { |
|
102 | + foreach ($values as $key => $value){ |
|
103 | 103 | $this->set((string)$key, $value, $ttl); |
104 | 104 | } |
105 | 105 | return $this->returnOnSet; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $keys = $this->iterableToArray($keys); |
111 | 111 | $this->validateKeys($keys); |
112 | 112 | /** @var string[] $keys */ |
113 | - foreach ($keys as $key) { |
|
113 | + foreach ($keys as $key){ |
|
114 | 114 | $this->delete($key); |
115 | 115 | } |
116 | 116 | return $this->returnOnDelete; |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function getValues(): array |
132 | 132 | { |
133 | 133 | $result = []; |
134 | - foreach ($this->cache as $key => $value) { |
|
134 | + foreach ($this->cache as $key => $value){ |
|
135 | 135 | /** @psalm-var mixed */ |
136 | 136 | $result[$key] = $value[0]; |
137 | 137 | } |
@@ -157,11 +157,11 @@ discard block |
||
157 | 157 | { |
158 | 158 | $ttl = $this->normalizeTtl($ttl); |
159 | 159 | |
160 | - if ($ttl === null) { |
|
160 | + if ($ttl === null){ |
|
161 | 161 | $expiration = self::EXPIRATION_INFINITY; |
162 | - } elseif ($ttl <= 0) { |
|
162 | + } elseif ($ttl <= 0){ |
|
163 | 163 | $expiration = self::EXPIRATION_EXPIRED; |
164 | - } else { |
|
164 | + }else{ |
|
165 | 165 | $expiration = $ttl + time(); |
166 | 166 | } |
167 | 167 | |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | */ |
178 | 178 | private function normalizeTtl($ttl): ?int |
179 | 179 | { |
180 | - if ($ttl instanceof DateInterval) { |
|
180 | + if ($ttl instanceof DateInterval){ |
|
181 | 181 | return (new DateTime('@0'))->add($ttl)->getTimestamp(); |
182 | 182 | } |
183 | 183 | |
184 | - if (\is_string($ttl)) { |
|
184 | + if (\is_string($ttl)){ |
|
185 | 185 | return (int)$ttl; |
186 | 186 | } |
187 | 187 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | private function iterableToArray($iterable): array |
197 | 197 | { |
198 | - if (!is_iterable($iterable)) { |
|
198 | + if (!is_iterable($iterable)){ |
|
199 | 199 | throw new \InvalidArgumentException(\sprintf('Iterable is expected, got %s.', \gettype($iterable))); |
200 | 200 | } |
201 | 201 | return $iterable instanceof Traversable ? \iterator_to_array($iterable) : $iterable; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | private function validateKey($key): void |
208 | 208 | { |
209 | - if (!\is_string($key) || $key === '' || \strpbrk($key, '{}()/\@:')) { |
|
209 | + if (!\is_string($key) || $key === '' || \strpbrk($key, '{}()/\@:')){ |
|
210 | 210 | throw new \InvalidArgumentException('Invalid key value.'); |
211 | 211 | } |
212 | 212 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | private function validateKeys(array $keys): void |
218 | 218 | { |
219 | 219 | /** @psalm-var mixed $key */ |
220 | - foreach ($keys as $key) { |
|
220 | + foreach ($keys as $key){ |
|
221 | 221 | $this->validateKey($key); |
222 | 222 | } |
223 | 223 | } |
@@ -29,10 +29,12 @@ discard block |
||
29 | 29 | public function get($key, $default = null) |
30 | 30 | { |
31 | 31 | $this->validateKey($key); |
32 | - if (\array_key_exists($key, $this->cache) && !$this->isExpired($key)) { |
|
32 | + if (\array_key_exists($key, $this->cache) && !$this->isExpired($key)) |
|
33 | + { |
|
33 | 34 | /** @psalm-var mixed $value */ |
34 | 35 | $value = $this->cache[$key][0]; |
35 | - if (\is_object($value)) { |
|
36 | + if (\is_object($value)) |
|
37 | + { |
|
36 | 38 | $value = clone $value; |
37 | 39 | } |
38 | 40 | |
@@ -46,10 +48,12 @@ discard block |
||
46 | 48 | { |
47 | 49 | $this->validateKey($key); |
48 | 50 | $expiration = $this->ttlToExpiration($ttl); |
49 | - if ($expiration < 0) { |
|
51 | + if ($expiration < 0) |
|
52 | + { |
|
50 | 53 | return $this->delete($key); |
51 | 54 | } |
52 | - if (\is_object($value)) { |
|
55 | + if (\is_object($value)) |
|
56 | + { |
|
53 | 57 | $value = clone $value; |
54 | 58 | } |
55 | 59 | $this->cache[$key] = [$value, $expiration]; |
@@ -81,7 +85,8 @@ discard block |
||
81 | 85 | $this->validateKeys($keys); |
82 | 86 | /** @psalm-var string[] $keys */ |
83 | 87 | $result = []; |
84 | - foreach ($keys as $key) { |
|
88 | + foreach ($keys as $key) |
|
89 | + { |
|
85 | 90 | /** @psalm-var mixed */ |
86 | 91 | $result[$key] = $this->get($key, $default); |
87 | 92 | } |
@@ -99,7 +104,8 @@ discard block |
||
99 | 104 | /** |
100 | 105 | * @psalm-var mixed $value |
101 | 106 | */ |
102 | - foreach ($values as $key => $value) { |
|
107 | + foreach ($values as $key => $value) |
|
108 | + { |
|
103 | 109 | $this->set((string)$key, $value, $ttl); |
104 | 110 | } |
105 | 111 | return $this->returnOnSet; |
@@ -110,7 +116,8 @@ discard block |
||
110 | 116 | $keys = $this->iterableToArray($keys); |
111 | 117 | $this->validateKeys($keys); |
112 | 118 | /** @var string[] $keys */ |
113 | - foreach ($keys as $key) { |
|
119 | + foreach ($keys as $key) |
|
120 | + { |
|
114 | 121 | $this->delete($key); |
115 | 122 | } |
116 | 123 | return $this->returnOnDelete; |
@@ -131,7 +138,8 @@ discard block |
||
131 | 138 | public function getValues(): array |
132 | 139 | { |
133 | 140 | $result = []; |
134 | - foreach ($this->cache as $key => $value) { |
|
141 | + foreach ($this->cache as $key => $value) |
|
142 | + { |
|
135 | 143 | /** @psalm-var mixed */ |
136 | 144 | $result[$key] = $value[0]; |
137 | 145 | } |
@@ -157,11 +165,16 @@ discard block |
||
157 | 165 | { |
158 | 166 | $ttl = $this->normalizeTtl($ttl); |
159 | 167 | |
160 | - if ($ttl === null) { |
|
168 | + if ($ttl === null) |
|
169 | + { |
|
161 | 170 | $expiration = self::EXPIRATION_INFINITY; |
162 | - } elseif ($ttl <= 0) { |
|
171 | + } |
|
172 | + elseif ($ttl <= 0) |
|
173 | + { |
|
163 | 174 | $expiration = self::EXPIRATION_EXPIRED; |
164 | - } else { |
|
175 | + } |
|
176 | + else |
|
177 | + { |
|
165 | 178 | $expiration = $ttl + time(); |
166 | 179 | } |
167 | 180 | |
@@ -177,11 +190,13 @@ discard block |
||
177 | 190 | */ |
178 | 191 | private function normalizeTtl($ttl): ?int |
179 | 192 | { |
180 | - if ($ttl instanceof DateInterval) { |
|
193 | + if ($ttl instanceof DateInterval) |
|
194 | + { |
|
181 | 195 | return (new DateTime('@0'))->add($ttl)->getTimestamp(); |
182 | 196 | } |
183 | 197 | |
184 | - if (\is_string($ttl)) { |
|
198 | + if (\is_string($ttl)) |
|
199 | + { |
|
185 | 200 | return (int)$ttl; |
186 | 201 | } |
187 | 202 | |
@@ -195,7 +210,8 @@ discard block |
||
195 | 210 | */ |
196 | 211 | private function iterableToArray($iterable): array |
197 | 212 | { |
198 | - if (!is_iterable($iterable)) { |
|
213 | + if (!is_iterable($iterable)) |
|
214 | + { |
|
199 | 215 | throw new \InvalidArgumentException(\sprintf('Iterable is expected, got %s.', \gettype($iterable))); |
200 | 216 | } |
201 | 217 | return $iterable instanceof Traversable ? \iterator_to_array($iterable) : $iterable; |
@@ -206,7 +222,8 @@ discard block |
||
206 | 222 | */ |
207 | 223 | private function validateKey($key): void |
208 | 224 | { |
209 | - if (!\is_string($key) || $key === '' || \strpbrk($key, '{}()/\@:')) { |
|
225 | + if (!\is_string($key) || $key === '' || \strpbrk($key, '{}()/\@:')) |
|
226 | + { |
|
210 | 227 | throw new \InvalidArgumentException('Invalid key value.'); |
211 | 228 | } |
212 | 229 | } |
@@ -217,7 +234,8 @@ discard block |
||
217 | 234 | private function validateKeys(array $keys): void |
218 | 235 | { |
219 | 236 | /** @psalm-var mixed $key */ |
220 | - foreach ($keys as $key) { |
|
237 | + foreach ($keys as $key) |
|
238 | + { |
|
221 | 239 | $this->validateKey($key); |
222 | 240 | } |
223 | 241 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | 'test' => $this->defaultCache, |
77 | 77 | 'array' => new ArrayCache(), |
78 | 78 | ][$name] ?? null; |
79 | - if ($result === null) { |
|
79 | + if ($result === null){ |
|
80 | 80 | throw new NotFoundException(); |
81 | 81 | } |
82 | 82 | return $result; |
@@ -76,7 +76,8 @@ |
||
76 | 76 | 'test' => $this->defaultCache, |
77 | 77 | 'array' => new ArrayCache(), |
78 | 78 | ][$name] ?? null; |
79 | - if ($result === null) { |
|
79 | + if ($result === null) |
|
80 | + { |
|
80 | 81 | throw new NotFoundException(); |
81 | 82 | } |
82 | 83 | return $result; |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $manager = new CacheManager($config, $container); |
57 | 57 | |
58 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
58 | + foreach ($config->getAliases() as $alias => $storageName){ |
|
59 | 59 | $container->bind($alias, static function (CacheManager $manager) use ($storageName) { |
60 | 60 | return $manager->storage($storageName); |
61 | 61 | }); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | ], |
78 | 78 | 'file' => [ |
79 | 79 | 'type' => 'file', |
80 | - 'path' => $dirs->get('runtime') . 'cache', |
|
80 | + 'path' => $dirs->get('runtime').'cache', |
|
81 | 81 | ], |
82 | 82 | ], |
83 | 83 | 'typeAliases' => [ |
@@ -55,8 +55,10 @@ |
||
55 | 55 | { |
56 | 56 | $manager = new CacheManager($config, $container); |
57 | 57 | |
58 | - foreach ($config->getAliases() as $alias => $storageName) { |
|
59 | - $container->bind($alias, static function (CacheManager $manager) use ($storageName) { |
|
58 | + foreach ($config->getAliases() as $alias => $storageName) |
|
59 | + { |
|
60 | + $container->bind($alias, static function (CacheManager $manager) use ($storageName) |
|
61 | + { |
|
60 | 62 | return $manager->storage($storageName); |
61 | 63 | }); |
62 | 64 | } |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | |
26 | 26 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
27 | 27 | { |
28 | - try { |
|
29 | - if ($context === null) { |
|
28 | + try{ |
|
29 | + if ($context === null){ |
|
30 | 30 | $connection = $this->provider->storage(); |
31 | - } else { |
|
31 | + }else{ |
|
32 | 32 | // Get Cache by context |
33 | - try { |
|
33 | + try{ |
|
34 | 34 | $connection = $this->provider->storage($context); |
35 | - } catch (InvalidArgumentException $e) { |
|
35 | + }catch (InvalidArgumentException $e){ |
|
36 | 36 | // Case when context doesn't match to configured connections |
37 | 37 | return $this->provider->storage(); |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | 41 | $this->matchType($class, $context, $connection); |
42 | - } catch (\Throwable $e) { |
|
42 | + }catch (\Throwable $e){ |
|
43 | 43 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
44 | 44 | } |
45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
55 | 55 | { |
56 | 56 | $className = $class->getName(); |
57 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
57 | + if ($className !== CacheInterface::class && !$connection instanceof $className){ |
|
58 | 58 | throw new \RuntimeException( |
59 | 59 | \sprintf( |
60 | 60 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -25,21 +25,30 @@ discard block |
||
25 | 25 | |
26 | 26 | public function createInjection(ReflectionClass $class, string $context = null): CacheInterface |
27 | 27 | { |
28 | - try { |
|
29 | - if ($context === null) { |
|
28 | + try |
|
29 | + { |
|
30 | + if ($context === null) |
|
31 | + { |
|
30 | 32 | $connection = $this->provider->storage(); |
31 | - } else { |
|
33 | + } |
|
34 | + else |
|
35 | + { |
|
32 | 36 | // Get Cache by context |
33 | - try { |
|
37 | + try |
|
38 | + { |
|
34 | 39 | $connection = $this->provider->storage($context); |
35 | - } catch (InvalidArgumentException $e) { |
|
40 | + } |
|
41 | + catch (InvalidArgumentException $e) |
|
42 | + { |
|
36 | 43 | // Case when context doesn't match to configured connections |
37 | 44 | return $this->provider->storage(); |
38 | 45 | } |
39 | 46 | } |
40 | 47 | |
41 | 48 | $this->matchType($class, $context, $connection); |
42 | - } catch (\Throwable $e) { |
|
49 | + } |
|
50 | + catch (\Throwable $e) |
|
51 | + { |
|
43 | 52 | throw new ContainerException(sprintf("Can't inject the required cache. %s", $e->getMessage()), 0, $e); |
44 | 53 | } |
45 | 54 | |
@@ -54,7 +63,8 @@ discard block |
||
54 | 63 | private function matchType(ReflectionClass $class, ?string $context, CacheInterface $connection): void |
55 | 64 | { |
56 | 65 | $className = $class->getName(); |
57 | - if ($className !== CacheInterface::class && !$connection instanceof $className) { |
|
66 | + if ($className !== CacheInterface::class && !$connection instanceof $className) |
|
67 | + { |
|
58 | 68 | throw new \RuntimeException( |
59 | 69 | \sprintf( |
60 | 70 | "The cache obtained by the context `%s` doesn't match the type `%s`.", |
@@ -25,21 +25,21 @@ discard block |
||
25 | 25 | |
26 | 26 | public function createInjection(ReflectionClass $class, string $context = null): QueueInterface |
27 | 27 | { |
28 | - try { |
|
29 | - if ($context === null) { |
|
28 | + try{ |
|
29 | + if ($context === null){ |
|
30 | 30 | $connection = $this->queueManager->getConnection(); |
31 | - } else { |
|
31 | + }else{ |
|
32 | 32 | // Get Queue by context |
33 | - try { |
|
33 | + try{ |
|
34 | 34 | $connection = $this->queueManager->getConnection($context); |
35 | - } catch (InvalidArgumentException $e) { |
|
35 | + }catch (InvalidArgumentException $e){ |
|
36 | 36 | // Case when context doesn't match to configured connections |
37 | 37 | return $this->queueManager->getConnection(); |
38 | 38 | } |
39 | 39 | } |
40 | 40 | |
41 | 41 | $this->matchType($class, $context, $connection); |
42 | - } catch (\Throwable $e) { |
|
42 | + }catch (\Throwable $e){ |
|
43 | 43 | throw new ContainerException(sprintf("Can't inject the required queue. %s", $e->getMessage()), 0, $e); |
44 | 44 | } |
45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | private function matchType(ReflectionClass $class, ?string $context, QueueInterface $connection): void |
55 | 55 | { |
56 | 56 | $className = $class->getName(); |
57 | - if ($className !== QueueInterface::class && !$connection instanceof $className) { |
|
57 | + if ($className !== QueueInterface::class && !$connection instanceof $className){ |
|
58 | 58 | throw new \RuntimeException( |
59 | 59 | \sprintf( |
60 | 60 | "The queue obtained by the context `%s` doesn't match the type `%s`.", |
@@ -25,21 +25,30 @@ discard block |
||
25 | 25 | |
26 | 26 | public function createInjection(ReflectionClass $class, string $context = null): QueueInterface |
27 | 27 | { |
28 | - try { |
|
29 | - if ($context === null) { |
|
28 | + try |
|
29 | + { |
|
30 | + if ($context === null) |
|
31 | + { |
|
30 | 32 | $connection = $this->queueManager->getConnection(); |
31 | - } else { |
|
33 | + } |
|
34 | + else |
|
35 | + { |
|
32 | 36 | // Get Queue by context |
33 | - try { |
|
37 | + try |
|
38 | + { |
|
34 | 39 | $connection = $this->queueManager->getConnection($context); |
35 | - } catch (InvalidArgumentException $e) { |
|
40 | + } |
|
41 | + catch (InvalidArgumentException $e) |
|
42 | + { |
|
36 | 43 | // Case when context doesn't match to configured connections |
37 | 44 | return $this->queueManager->getConnection(); |
38 | 45 | } |
39 | 46 | } |
40 | 47 | |
41 | 48 | $this->matchType($class, $context, $connection); |
42 | - } catch (\Throwable $e) { |
|
49 | + } |
|
50 | + catch (\Throwable $e) |
|
51 | + { |
|
43 | 52 | throw new ContainerException(sprintf("Can't inject the required queue. %s", $e->getMessage()), 0, $e); |
44 | 53 | } |
45 | 54 | |
@@ -54,7 +63,8 @@ discard block |
||
54 | 63 | private function matchType(ReflectionClass $class, ?string $context, QueueInterface $connection): void |
55 | 64 | { |
56 | 65 | $className = $class->getName(); |
57 | - if ($className !== QueueInterface::class && !$connection instanceof $className) { |
|
66 | + if ($className !== QueueInterface::class && !$connection instanceof $className) |
|
67 | + { |
|
58 | 68 | throw new \RuntimeException( |
59 | 69 | \sprintf( |
60 | 70 | "The queue obtained by the context `%s` doesn't match the type `%s`.", |