@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | * @param int $size |
74 | 74 | * @return $this |
75 | 75 | */ |
76 | - public function setSize(int $size) |
|
77 | - { |
|
76 | + public function setSize(int $size) { |
|
78 | 77 | $this->size = $size; |
79 | 78 | |
80 | 79 | return $this; |
@@ -83,8 +82,7 @@ discard block |
||
83 | 82 | /** |
84 | 83 | * @return mixed |
85 | 84 | */ |
86 | - public function getData() |
|
87 | - { |
|
85 | + public function getData() { |
|
88 | 86 | return $this->data; |
89 | 87 | } |
90 | 88 | |
@@ -102,8 +100,7 @@ discard block |
||
102 | 100 | /** |
103 | 101 | * @return mixed |
104 | 102 | */ |
105 | - public function getRawData() |
|
106 | - { |
|
103 | + public function getRawData() { |
|
107 | 104 | return $this->rawData; |
108 | 105 | } |
109 | 106 |
@@ -39,8 +39,7 @@ |
||
39 | 39 | * @param string $itemKey |
40 | 40 | * @param DateTimeInterface $itemDate |
41 | 41 | */ |
42 | - public function __construct(string $itemKey, DateTimeInterface $itemDate) |
|
43 | - { |
|
42 | + public function __construct(string $itemKey, DateTimeInterface $itemDate) { |
|
44 | 43 | $this->itemKey = $itemKey; |
45 | 44 | $this->itemDate = $itemDate; |
46 | 45 | } |
@@ -64,8 +64,7 @@ discard block |
||
64 | 64 | /** |
65 | 65 | * EventManager constructor. |
66 | 66 | */ |
67 | - final protected function __construct() |
|
68 | - { |
|
67 | + final protected function __construct() { |
|
69 | 68 | // The constructor should not be instantiated externally |
70 | 69 | } |
71 | 70 | |
@@ -111,13 +110,16 @@ discard block |
||
111 | 110 | if (\is_callable($arguments[0])) { |
112 | 111 | if (isset($arguments[1]) && \is_string($arguments[0])) { |
113 | 112 | $this->events[$name][$arguments[1]] = $arguments[0]; |
114 | - } else { |
|
113 | + } |
|
114 | + else { |
|
115 | 115 | $this->events[$name][] = $arguments[0]; |
116 | 116 | } |
117 | - } else { |
|
117 | + } |
|
118 | + else { |
|
118 | 119 | throw new PhpfastcacheInvalidArgumentException(\sprintf('Expected Callable, got "%s"', \gettype($arguments[0]))); |
119 | 120 | } |
120 | - } else { |
|
121 | + } |
|
122 | + else { |
|
121 | 123 | throw new BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); |
122 | 124 | } |
123 | 125 | } |
@@ -95,8 +95,7 @@ discard block |
||
95 | 95 | /** |
96 | 96 | * CacheManager constructor. |
97 | 97 | */ |
98 | - final protected function __construct() |
|
99 | - { |
|
98 | + final protected function __construct() { |
|
100 | 99 | // The cache manager is not meant to be instantiated |
101 | 100 | } |
102 | 101 | |
@@ -188,10 +187,12 @@ discard block |
||
188 | 187 | $configClass = $driverClass::getConfigClass(); |
189 | 188 | self::$instances[$instanceId] = new $driverClass(new $configClass($config->toArray()), $instanceId); |
190 | 189 | self::$instances[$instanceId]->setEventManager(EventManager::getInstance()); |
191 | - } else { |
|
190 | + } |
|
191 | + else { |
|
192 | 192 | throw new PhpfastcacheDriverNotFoundException(sprintf('The driver "%s" does not exists', $driver)); |
193 | 193 | } |
194 | - } else { |
|
194 | + } |
|
195 | + else { |
|
195 | 196 | if (self::$badPracticeOmeter[$driver] >= 2) { |
196 | 197 | \trigger_error( |
197 | 198 | '[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. |
@@ -216,7 +217,8 @@ discard block |
||
216 | 217 | { |
217 | 218 | if ($config === null) { |
218 | 219 | $config = self::getDefaultConfig(); |
219 | - } else { |
|
220 | + } |
|
221 | + else { |
|
220 | 222 | if (!($config instanceof ConfigurationOption)) { |
221 | 223 | throw new PhpfastcacheInvalidArgumentException(\sprintf('Unsupported config type: %s', \gettype($config))); |
222 | 224 | } |
@@ -271,10 +273,12 @@ discard block |
||
271 | 273 | { |
272 | 274 | if (!empty(self::$driverCustoms[$driverName])) { |
273 | 275 | $driverClass = self::$driverCustoms[$driverName]; |
274 | - } else { |
|
276 | + } |
|
277 | + else { |
|
275 | 278 | if (!empty(self::$driverOverrides[$driverName])) { |
276 | 279 | $driverClass = self::$driverOverrides[$driverName]; |
277 | - } else { |
|
280 | + } |
|
281 | + else { |
|
278 | 282 | $driverClass = self::getNamespacePath() . $driverName . '\Driver'; |
279 | 283 | } |
280 | 284 | } |
@@ -34,8 +34,7 @@ discard block |
||
34 | 34 | * CachePromise constructor. |
35 | 35 | * @param CacheItemPoolInterface $cacheInstance |
36 | 36 | */ |
37 | - public function __construct(CacheItemPoolInterface $cacheInstance) |
|
38 | - { |
|
37 | + public function __construct(CacheItemPoolInterface $cacheInstance) { |
|
39 | 38 | $this->cacheInstance = $cacheInstance; |
40 | 39 | } |
41 | 40 | |
@@ -45,8 +44,7 @@ discard block |
||
45 | 44 | * @param int|DateInterval $expiresAfter |
46 | 45 | * @return mixed |
47 | 46 | */ |
48 | - public function get(string $cacheKey, callable $callback, $expiresAfter = null) |
|
49 | - { |
|
47 | + public function get(string $cacheKey, callable $callback, $expiresAfter = null) { |
|
50 | 48 | $cacheItem = $this->cacheInstance->getItem($cacheKey); |
51 | 49 | |
52 | 50 | if (!$cacheItem->isHit()) { |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException |
54 | 54 | * @throws \ReflectionException |
55 | 55 | */ |
56 | - public function __construct($driver, ConfigurationOptionInterface $config = null) |
|
57 | - { |
|
56 | + public function __construct($driver, ConfigurationOptionInterface $config = null) { |
|
58 | 57 | if ($driver instanceof ExtendedCacheItemPoolInterface) { |
59 | 58 | if ($config !== null) { |
60 | 59 | throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); |
61 | 60 | } |
62 | 61 | $this->internalCacheInstance = $driver; |
63 | - } else { |
|
62 | + } |
|
63 | + else { |
|
64 | 64 | $this->internalCacheInstance = CacheManager::getInstance($driver, $config); |
65 | 65 | } |
66 | 66 | } |
@@ -72,8 +72,7 @@ discard block |
||
72 | 72 | * @throws PhpfastcacheSimpleCacheException |
73 | 73 | * @throws \Psr\Cache\InvalidArgumentException |
74 | 74 | */ |
75 | - public function get($key, $default = null) |
|
76 | - { |
|
75 | + public function get($key, $default = null) { |
|
77 | 76 | try { |
78 | 77 | $cacheItem = $this->internalCacheInstance->getItem($key); |
79 | 78 | if (!$cacheItem->isExpired() && $cacheItem->get() !== null) { |
@@ -81,7 +80,8 @@ discard block |
||
81 | 80 | } |
82 | 81 | |
83 | 82 | return $default; |
84 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
83 | + } |
|
84 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
85 | 85 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
86 | 86 | } |
87 | 87 | } |
@@ -102,11 +102,13 @@ discard block |
||
102 | 102 | ->set($value); |
103 | 103 | if (\is_int($ttl) && $ttl <= 0) { |
104 | 104 | $cacheItem->expiresAt((new DateTime('@0'))); |
105 | - } elseif ($ttl !== null) { |
|
105 | + } |
|
106 | + elseif ($ttl !== null) { |
|
106 | 107 | $cacheItem->expiresAfter($ttl); |
107 | 108 | } |
108 | 109 | return $this->internalCacheInstance->save($cacheItem); |
109 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
110 | + } |
|
111 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
110 | 112 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
111 | 113 | } |
112 | 114 | } |
@@ -120,7 +122,8 @@ discard block |
||
120 | 122 | { |
121 | 123 | try { |
122 | 124 | return $this->internalCacheInstance->deleteItem($key); |
123 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
125 | + } |
|
126 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
124 | 127 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
125 | 128 | } |
126 | 129 | } |
@@ -133,7 +136,8 @@ discard block |
||
133 | 136 | { |
134 | 137 | try { |
135 | 138 | return $this->internalCacheInstance->clear(); |
136 | - } catch (PhpfastcacheRootException $e) { |
|
139 | + } |
|
140 | + catch (PhpfastcacheRootException $e) { |
|
137 | 141 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
138 | 142 | } |
139 | 143 | } |
@@ -145,8 +149,7 @@ discard block |
||
145 | 149 | * @throws PhpfastcacheSimpleCacheException |
146 | 150 | * @throws \Psr\Cache\InvalidArgumentException |
147 | 151 | */ |
148 | - public function getMultiple($keys, $default = null) |
|
149 | - { |
|
152 | + public function getMultiple($keys, $default = null) { |
|
150 | 153 | if ($keys instanceof Traversable) { |
151 | 154 | $keys = \iterator_to_array($keys); |
152 | 155 | } |
@@ -157,7 +160,8 @@ discard block |
||
157 | 160 | }, |
158 | 161 | $this->internalCacheInstance->getItems($keys) |
159 | 162 | ); |
160 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
163 | + } |
|
164 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
161 | 165 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
162 | 166 | } |
163 | 167 | } |
@@ -177,14 +181,16 @@ discard block |
||
177 | 181 | |
178 | 182 | if (\is_int($ttl) && $ttl <= 0) { |
179 | 183 | $cacheItem->expiresAt((new DateTime('@0'))); |
180 | - } elseif ($ttl !== null) { |
|
184 | + } |
|
185 | + elseif ($ttl !== null) { |
|
181 | 186 | $cacheItem->expiresAfter($ttl); |
182 | 187 | } |
183 | 188 | $this->internalCacheInstance->saveDeferred($cacheItem); |
184 | 189 | unset($cacheItem); |
185 | 190 | } |
186 | 191 | return $this->internalCacheInstance->commit(); |
187 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
192 | + } |
|
193 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
188 | 194 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
189 | 195 | } |
190 | 196 | } |
@@ -200,12 +206,15 @@ discard block |
||
200 | 206 | try { |
201 | 207 | if ($keys instanceof Traversable) { |
202 | 208 | return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys)); |
203 | - } elseif (\is_array($keys)) { |
|
209 | + } |
|
210 | + elseif (\is_array($keys)) { |
|
204 | 211 | return $this->internalCacheInstance->deleteItems($keys); |
205 | - } else { |
|
212 | + } |
|
213 | + else { |
|
206 | 214 | throw new phpFastCacheInvalidArgumentException('$keys must be an array/Traversable instance.'); |
207 | 215 | } |
208 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
216 | + } |
|
217 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
209 | 218 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
210 | 219 | } |
211 | 220 | } |
@@ -220,7 +229,8 @@ discard block |
||
220 | 229 | try { |
221 | 230 | $cacheItem = $this->internalCacheInstance->getItem($key); |
222 | 231 | return $cacheItem->isHit() && !$cacheItem->isExpired(); |
223 | - } catch (PhpfastcacheInvalidArgumentException $e) { |
|
232 | + } |
|
233 | + catch (PhpfastcacheInvalidArgumentException $e) { |
|
224 | 234 | throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e); |
225 | 235 | } |
226 | 236 | } |
@@ -45,7 +45,8 @@ discard block |
||
45 | 45 | |
46 | 46 | if (\is_readable($path)) { |
47 | 47 | require_once $path; |
48 | - } else { |
|
48 | + } |
|
49 | + else { |
|
49 | 50 | \trigger_error('Cannot locate the Psr/Cache files', E_USER_ERROR); |
50 | 51 | } |
51 | 52 | return; |
@@ -56,7 +57,8 @@ discard block |
||
56 | 57 | |
57 | 58 | if (\is_readable($path)) { |
58 | 59 | require_once $path; |
59 | - } else { |
|
60 | + } |
|
61 | + else { |
|
60 | 62 | \trigger_error('Cannot locate the Psr/SimpleCache files', E_USER_ERROR); |
61 | 63 | } |
62 | 64 | return; |
@@ -66,7 +68,8 @@ discard block |
||
66 | 68 | |
67 | 69 | if(\strpos($entity, PFC_TESTS_NS) === 0){ |
68 | 70 | $path = PFC_TESTS_DIR . \str_replace(str_replace('\\', '/', PFC_TESTS_NS), '', $entityPath) . '.' . PFC_PHP_EXT; |
69 | - }else{ |
|
71 | + } |
|
72 | + else{ |
|
70 | 73 | $path = PFC_LIB_DIR . $entityPath . '.' . PFC_PHP_EXT; |
71 | 74 | } |
72 | 75 |
@@ -30,8 +30,7 @@ |
||
30 | 30 | /** |
31 | 31 | * Api constructor. |
32 | 32 | */ |
33 | - final protected function __construct() |
|
34 | - { |
|
33 | + final protected function __construct() { |
|
35 | 34 | // The Api is not meant to be instantiated |
36 | 35 | } |
37 | 36 |
@@ -41,7 +41,8 @@ |
||
41 | 41 | define($CONSTANT_NAME, $driverName); |
42 | 42 | |
43 | 43 | return true; |
44 | - } else { |
|
44 | + } |
|
45 | + else { |
|
45 | 46 | if (constant($CONSTANT_NAME) !== $driverName) { |
46 | 47 | trigger_error( |
47 | 48 | 'Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours', |