@@ -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 {} |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -trait CacheOptionsTrait{ |
|
15 | +trait CacheOptionsTrait { |
|
16 | 16 | |
17 | 17 | protected $cacheFilestorage = ''; |
18 | - protected $cacheSessionkey = '_session_cache'; |
|
18 | + protected $cacheSessionkey = '_session_cache'; |
|
19 | 19 | |
20 | 20 | } |
@@ -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 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class MemoryCache extends CacheDriverAbstract{ |
|
15 | +class MemoryCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var array |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | protected $cache = []; |
21 | 21 | |
22 | 22 | /** @inheritdoc */ |
23 | - public function get($key, $default = null){ |
|
23 | + public function get($key, $default = null) { |
|
24 | 24 | $key = $this->checkKey($key); |
25 | 25 | |
26 | - if(isset($this->cache[$key])){ |
|
26 | + if (isset($this->cache[$key])) { |
|
27 | 27 | |
28 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){ |
|
28 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()) { |
|
29 | 29 | return $this->cache[$key]['content']; |
30 | 30 | } |
31 | 31 |
@@ -12,13 +12,13 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class APCUCache extends CacheDriverAbstract{ |
|
15 | +class APCUCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | - public function get($key, $default = null){ |
|
18 | + public function get($key, $default = null) { |
|
19 | 19 | $value = apcu_fetch($this->checkKey($key)); |
20 | 20 | |
21 | - if($value !== false){ |
|
21 | + if ($value !== false) { |
|
22 | 22 | return $value; |
23 | 23 | } |
24 | 24 |
@@ -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 |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
32 | 32 | * @param \Psr\Log\LoggerInterface|null $logger |
33 | 33 | */ |
34 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
34 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
35 | 35 | $this->options = $options ?? new CacheOptions; |
36 | 36 | $this->logger = $logger ?? new NullLogger; |
37 | 37 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function getMultiple($keys, $default = null):array{ |
46 | 46 | $data = []; |
47 | 47 | |
48 | - foreach($this->getData($keys) as $key){ |
|
48 | + foreach ($this->getData($keys) as $key) { |
|
49 | 49 | $data[$key] = $this->get($key, $default); |
50 | 50 | } |
51 | 51 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | public function setMultiple($values, $ttl = null):bool{ |
57 | 57 | $return = []; |
58 | 58 | |
59 | - foreach($this->getData($values) as $key => $value){ |
|
59 | + foreach ($this->getData($values) as $key => $value) { |
|
60 | 60 | $return[] = $this->set($key, $value, $ttl); |
61 | 61 | } |
62 | 62 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | public function deleteMultiple($keys):bool{ |
68 | 68 | $return = []; |
69 | 69 | |
70 | - foreach($this->getData($keys) as $key){ |
|
70 | + foreach ($this->getData($keys) as $key) { |
|
71 | 71 | $return[] = $this->delete($key); |
72 | 72 | } |
73 | 73 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | protected function checkKey($key):string{ |
84 | 84 | |
85 | - if(!is_string($key) || empty($key)){ |
|
85 | + if (!is_string($key) || empty($key)) { |
|
86 | 86 | $msg = 'invalid cache key: "'.$key.'"'; |
87 | 87 | $this->logger->error($msg); |
88 | 88 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | protected function checkKeyArray(array $keys):void{ |
101 | 101 | |
102 | - foreach($keys as $key){ |
|
102 | + foreach ($keys as $key) { |
|
103 | 103 | $this->checkKey($key); |
104 | 104 | } |
105 | 105 | |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function getData($data):array{ |
115 | 115 | |
116 | - if(is_array($data)){ |
|
116 | + if (is_array($data)) { |
|
117 | 117 | return $data; |
118 | 118 | } |
119 | - elseif($data instanceof Traversable){ |
|
119 | + elseif ($data instanceof Traversable) { |
|
120 | 120 | return iterator_to_array($data); // @codeCoverageIgnore |
121 | 121 | } |
122 | 122 | |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * @return int|null |
133 | 133 | * @throws \Psr\SimpleCache\InvalidArgumentException |
134 | 134 | */ |
135 | - protected function getTTL($ttl):?int{ |
|
135 | + protected function getTTL($ttl): ?int{ |
|
136 | 136 | |
137 | - if($ttl instanceof DateInterval){ |
|
137 | + if ($ttl instanceof DateInterval) { |
|
138 | 138 | return (new DateTime)->add($ttl)->getTimeStamp() - time(); |
139 | 139 | } |
140 | - else if((is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
140 | + else if ((is_int($ttl) && $ttl > 0) || $ttl === null) { |
|
141 | 141 | return $ttl; |
142 | 142 | } |
143 | 143 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function checkReturn(array $booleans):bool{ |
156 | 156 | |
157 | - foreach($booleans as $bool){ |
|
157 | + foreach ($booleans as $bool) { |
|
158 | 158 | |
159 | - if(!(bool)$bool){ |
|
159 | + if (!(bool)$bool) { |
|
160 | 160 | return false; // @codeCoverageIgnore |
161 | 161 | } |
162 | 162 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | |
18 | -class SessionCache extends CacheDriverAbstract{ |
|
18 | +class SessionCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @throws \chillerlan\SimpleCache\CacheException |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | parent::__construct($options, $logger); |
35 | 35 | |
36 | 36 | $this->key = $this->options->cacheSessionkey; |
37 | 37 | |
38 | - if(!is_string($this->key) || empty($this->key)){ |
|
38 | + if (!is_string($this->key) || empty($this->key)) { |
|
39 | 39 | $msg = 'invalid session cache key'; |
40 | 40 | |
41 | 41 | $this->logger->error($msg); |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @inheritdoc */ |
50 | - public function get($key, $default = null){ |
|
50 | + public function get($key, $default = null) { |
|
51 | 51 | $key = $this->checkKey($key); |
52 | 52 | |
53 | - if(isset($_SESSION[$this->key][$key])){ |
|
53 | + if (isset($_SESSION[$this->key][$key])) { |
|
54 | 54 | |
55 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){ |
|
55 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) { |
|
56 | 56 | return $_SESSION[$this->key][$key]['content']; |
57 | 57 | } |
58 | 58 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use Memcached; |
17 | 17 | use Psr\Log\LoggerInterface; |
18 | 18 | |
19 | -class MemcachedCache extends CacheDriverAbstract{ |
|
19 | +class MemcachedCache extends CacheDriverAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var \Memcached |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @throws \chillerlan\SimpleCache\CacheException |
34 | 34 | */ |
35 | - public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
35 | + public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
36 | 36 | parent::__construct($options, $logger); |
37 | 37 | |
38 | 38 | $this->memcached = $memcached; |
39 | 39 | |
40 | - if(empty($this->memcached->getServerList())){ |
|
40 | + if (empty($this->memcached->getServerList())) { |
|
41 | 41 | $msg = 'no memcache server available'; |
42 | 42 | |
43 | 43 | $this->logger->error($msg); |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @inheritdoc */ |
50 | - public function get($key, $default = null){ |
|
50 | + public function get($key, $default = null) { |
|
51 | 51 | $value = $this->memcached->get($this->checkKey($key)); |
52 | 52 | |
53 | - if($value !== false){ |
|
53 | + if ($value !== false) { |
|
54 | 54 | return $value; |
55 | 55 | } |
56 | 56 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $values = $this->memcached->getMulti($keys); |
82 | 82 | $return = []; |
83 | 83 | |
84 | - foreach($keys as $key){ |
|
84 | + foreach ($keys as $key) { |
|
85 | 85 | $return[$key] = $values[$key] ?? $default; |
86 | 86 | } |
87 | 87 |