@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class CacheException extends \Exception implements \Psr\SimpleCache\CacheException{} |
|
15 | +class CacheException extends \Exception implements \Psr\SimpleCache\CacheException {} |
@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException{} |
|
15 | +class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException {} |
@@ -18,6 +18,6 @@ |
||
18 | 18 | * @property string $cacheFilestorage |
19 | 19 | * @property string $cacheSessionkey |
20 | 20 | */ |
21 | -class CacheOptions extends SettingsContainerAbstract{ |
|
21 | +class CacheOptions extends SettingsContainerAbstract { |
|
22 | 22 | use CacheOptionsTrait; |
23 | 23 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use Memcached; |
19 | 19 | use Psr\Log\LoggerInterface; |
20 | 20 | |
21 | -class MemcachedCache extends CacheDriverAbstract{ |
|
21 | +class MemcachedCache extends CacheDriverAbstract { |
|
22 | 22 | |
23 | 23 | protected Memcached $memcached; |
24 | 24 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @throws \chillerlan\SimpleCache\CacheException |
33 | 33 | */ |
34 | - public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
34 | + public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
35 | 35 | parent::__construct($options, $logger); |
36 | 36 | |
37 | 37 | $this->memcached = $memcached; |
38 | 38 | |
39 | - if(empty($this->memcached->getServerList())){ |
|
39 | + if (empty($this->memcached->getServerList())) { |
|
40 | 40 | $msg = 'no memcache server available'; |
41 | 41 | |
42 | 42 | $this->logger->error($msg); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** @inheritdoc */ |
49 | - public function get($key, $default = null){ |
|
49 | + public function get($key, $default = null) { |
|
50 | 50 | $value = $this->memcached->get($this->checkKey($key)); |
51 | 51 | |
52 | - if($value !== false){ |
|
52 | + if ($value !== false) { |
|
53 | 53 | return $value; |
54 | 54 | } |
55 | 55 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $values = $this->memcached->getMulti($keys); |
81 | 81 | $return = []; |
82 | 82 | |
83 | - foreach($keys as $key){ |
|
83 | + foreach ($keys as $key) { |
|
84 | 84 | $return[$key] = $values[$key] ?? $default; |
85 | 85 | } |
86 | 86 |
@@ -14,13 +14,13 @@ |
||
14 | 14 | |
15 | 15 | namespace chillerlan\SimpleCache; |
16 | 16 | |
17 | -class APCUCache extends CacheDriverAbstract{ |
|
17 | +class APCUCache extends CacheDriverAbstract { |
|
18 | 18 | |
19 | 19 | /** @inheritdoc */ |
20 | - public function get($key, $default = null){ |
|
20 | + public function get($key, $default = null) { |
|
21 | 21 | $value = \apcu_fetch($this->checkKey($key)); |
22 | 22 | |
23 | - if($value !== false){ |
|
23 | + if ($value !== false) { |
|
24 | 24 | return $value; |
25 | 25 | } |
26 | 26 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * CacheDriverAbstract constructor. |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | $this->options = $options ?? new CacheOptions; |
35 | 35 | $this->logger = $logger ?? new NullLogger; |
36 | 36 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function getMultiple($keys, $default = null):array{ |
45 | 45 | $data = []; |
46 | 46 | |
47 | - foreach($this->getData($keys) as $key){ |
|
47 | + foreach ($this->getData($keys) as $key) { |
|
48 | 48 | $data[$key] = $this->get($key, $default); |
49 | 49 | } |
50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function setMultiple($values, $ttl = null):bool{ |
56 | 56 | $return = []; |
57 | 57 | |
58 | - foreach($this->getData($values) as $key => $value){ |
|
58 | + foreach ($this->getData($values) as $key => $value) { |
|
59 | 59 | $return[] = $this->set($key, $value, $ttl); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function deleteMultiple($keys):bool{ |
67 | 67 | $return = []; |
68 | 68 | |
69 | - foreach($this->getData($keys) as $key){ |
|
69 | + foreach ($this->getData($keys) as $key) { |
|
70 | 70 | $return[] = $this->delete($key); |
71 | 71 | } |
72 | 72 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function checkKey($key):string{ |
83 | 83 | |
84 | - if(!\is_string($key) || empty($key)){ |
|
84 | + if (!\is_string($key) || empty($key)) { |
|
85 | 85 | $msg = 'invalid cache key: "'.$key.'"'; |
86 | 86 | $this->logger->error($msg); |
87 | 87 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function checkKeyArray(array $keys):void{ |
100 | 100 | |
101 | - foreach($keys as $key){ |
|
101 | + foreach ($keys as $key) { |
|
102 | 102 | $this->checkKey($key); |
103 | 103 | } |
104 | 104 | |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function getData($data):array{ |
114 | 114 | |
115 | - if(\is_array($data)){ |
|
115 | + if (\is_array($data)) { |
|
116 | 116 | return $data; |
117 | 117 | } |
118 | - elseif($data instanceof Traversable){ |
|
118 | + elseif ($data instanceof Traversable) { |
|
119 | 119 | return \iterator_to_array($data); // @codeCoverageIgnore |
120 | 120 | } |
121 | 121 | |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | * @return int|null |
132 | 132 | * @throws \Psr\SimpleCache\InvalidArgumentException |
133 | 133 | */ |
134 | - protected function getTTL($ttl):?int{ |
|
134 | + protected function getTTL($ttl): ?int{ |
|
135 | 135 | |
136 | - if($ttl instanceof DateInterval){ |
|
136 | + if ($ttl instanceof DateInterval) { |
|
137 | 137 | return (new DateTime)->add($ttl)->getTimeStamp() - \time(); |
138 | 138 | } |
139 | - else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
139 | + else if ((\is_int($ttl) && $ttl > 0) || $ttl === null) { |
|
140 | 140 | return $ttl; |
141 | 141 | } |
142 | 142 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function checkReturn(array $booleans):bool{ |
155 | 155 | |
156 | - foreach($booleans as $bool){ |
|
156 | + foreach ($booleans as $bool) { |
|
157 | 157 | |
158 | - if(!(bool)$bool){ |
|
158 | + if (!(bool)$bool) { |
|
159 | 159 | return false; // @codeCoverageIgnore |
160 | 160 | } |
161 | 161 |
@@ -114,8 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | if(\is_array($data)){ |
116 | 116 | return $data; |
117 | - } |
|
118 | - elseif($data instanceof Traversable){ |
|
117 | + } elseif($data instanceof Traversable){ |
|
119 | 118 | return \iterator_to_array($data); // @codeCoverageIgnore |
120 | 119 | } |
121 | 120 | |
@@ -135,8 +134,7 @@ discard block |
||
135 | 134 | |
136 | 135 | if($ttl instanceof DateInterval){ |
137 | 136 | return (new DateTime)->add($ttl)->getTimeStamp() - \time(); |
138 | - } |
|
139 | - else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
137 | + } else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
140 | 138 | return $ttl; |
141 | 139 | } |
142 | 140 |
@@ -12,17 +12,17 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class MemoryCache extends CacheDriverAbstract{ |
|
15 | +class MemoryCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | protected array $cache = []; |
18 | 18 | |
19 | 19 | /** @inheritdoc */ |
20 | - public function get($key, $default = null){ |
|
20 | + public function get($key, $default = null) { |
|
21 | 21 | $key = $this->checkKey($key); |
22 | 22 | |
23 | - if(isset($this->cache[$key])){ |
|
23 | + if (isset($this->cache[$key])) { |
|
24 | 24 | |
25 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > \time()){ |
|
25 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > \time()) { |
|
26 | 26 | return $this->cache[$key]['content']; |
27 | 27 | } |
28 | 28 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -trait CacheOptionsTrait{ |
|
15 | +trait CacheOptionsTrait { |
|
16 | 16 | |
17 | 17 | protected string $cacheFilestorage = ''; |
18 | 18 | protected string $cacheSessionkey = '_session_cache'; |
@@ -18,24 +18,24 @@ discard block |
||
18 | 18 | use Psr\Log\LoggerInterface; |
19 | 19 | use Redis; |
20 | 20 | |
21 | -class RedisCache extends CacheDriverAbstract{ |
|
21 | +class RedisCache extends CacheDriverAbstract { |
|
22 | 22 | |
23 | 23 | protected Redis $redis; |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * RedisCache constructor. |
27 | 27 | */ |
28 | - public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
28 | + public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
29 | 29 | parent::__construct($options, $logger); |
30 | 30 | |
31 | 31 | $this->redis = $redis; |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** @inheritdoc */ |
35 | - public function get($key, $default = null){ |
|
35 | + public function get($key, $default = null) { |
|
36 | 36 | $value = $this->redis->get($this->checkKey($key)); |
37 | 37 | |
38 | - if($value !== false){ |
|
38 | + if ($value !== false) { |
|
39 | 39 | return $value; |
40 | 40 | } |
41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $key = $this->checkKey($key); |
48 | 48 | $ttl = $this->getTTL($ttl); |
49 | 49 | |
50 | - if($ttl === null){ |
|
50 | + if ($ttl === null) { |
|
51 | 51 | return $this->redis->set($key, $value); |
52 | 52 | } |
53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $values = \array_combine($keys, $this->redis->mget($keys)); |
75 | 75 | $return = []; |
76 | 76 | |
77 | - foreach($keys as $key){ |
|
77 | + foreach ($keys as $key) { |
|
78 | 78 | /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */ |
79 | 79 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
80 | 80 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $values = $this->getData($values); |
88 | 88 | $ttl = $this->getTTL($ttl); |
89 | 89 | |
90 | - if($ttl === null){ |
|
90 | + if ($ttl === null) { |
|
91 | 91 | $this->checkKeyArray(\array_keys($values)); |
92 | 92 | |
93 | 93 | return $this->redis->msetnx($values); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | $return = []; |
97 | 97 | |
98 | - foreach($values as $key => $value){ |
|
98 | + foreach ($values as $key => $value) { |
|
99 | 99 | $return[] = $this->set($key, $value, $ttl); |
100 | 100 | } |
101 | 101 |