Completed
Pull Request — final (#457)
by Georges
02:42
created
src/phpFastCache/CacheManager.php 2 patches
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -188,42 +188,42 @@  discard block
 block discarded – undo
188 188
         }
189 189
 
190 190
         $instance = crc32($driver . serialize($config));
191
-        if (!isset(self::$instances[ $instance ])) {
191
+        if (!isset(self::$instances[$instance])) {
192 192
             $badPracticeOmeter[$driver] = 1;
193
-            if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){
193
+            if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) {
194 194
                 trigger_error('A Symfony Bundle to make the PhpFastCache integration more easier is now available here: https://github.com/PHPSocialNetwork/phpfastcache-bundle', E_USER_NOTICE);
195 195
             }
196 196
             $class = self::getNamespacePath() . $driver . '\Driver';
197
-            try{
198
-                self::$instances[ $instance ] = new $class($config);
199
-                self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
200
-            }catch(phpFastCacheDriverCheckException $e){
201
-                if($config['fallback']){
202
-                    try{
197
+            try {
198
+                self::$instances[$instance] = new $class($config);
199
+                self::$instances[$instance]->setEventManager(EventManager::getInstance());
200
+            } catch (phpFastCacheDriverCheckException $e) {
201
+                if ($config['fallback']) {
202
+                    try {
203 203
                         $fallback = self::standardizeDriverName($config['fallback']);
204
-                        if($fallback !== $driver){
204
+                        if ($fallback !== $driver) {
205 205
                             $class = self::getNamespacePath() . $fallback . '\Driver';
206
-                            self::$instances[ $instance ] = new $class($config);
207
-                            self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
206
+                            self::$instances[$instance] = new $class($config);
207
+                            self::$instances[$instance]->setEventManager(EventManager::getInstance());
208 208
                             trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
209
-                        }else{
209
+                        } else {
210 210
                             throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e);
211 211
                         }
212
-                    }catch (phpFastCacheInvalidArgumentException $e){
212
+                    } catch (phpFastCacheInvalidArgumentException $e) {
213 213
                         throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
214 214
                     }
215
-                }else{
215
+                } else {
216 216
                     throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
217 217
                 }
218 218
             }
219
-        } else if($badPracticeOmeter[$driver] >= 5){
219
+        } else if ($badPracticeOmeter[$driver] >= 5) {
220 220
             trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
221 221
            See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
222 222
         }
223 223
 
224 224
         $badPracticeOmeter[$driver]++;
225 225
 
226
-        return self::$instances[ $instance ];
226
+        return self::$instances[$instance];
227 227
     }
228 228
 
229 229
     /**
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      */
285 285
     public static function __callStatic($name, $arguments)
286 286
     {
287
-        $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []);
287
+        $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []);
288 288
 
289 289
         return self::getInstance($name, $options);
290 290
     }
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
     {
326 326
         if (is_array($name)) {
327 327
             self::$config = array_merge(self::$config, $name);
328
-        } else if (is_string($name)){
329
-            self::$config[ $name ] = $value;
330
-        }else{
328
+        } else if (is_string($name)) {
329
+            self::$config[$name] = $value;
330
+        } else {
331 331
             throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name');
332 332
         }
333 333
     }
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
      */
387 387
     public static function standardizeDriverName($driverName)
388 388
     {
389
-        if(!is_string($driverName)){
389
+        if (!is_string($driverName)) {
390 390
             throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName)));
391 391
         }
392 392
         return ucfirst(strtolower(trim($driverName)));
@@ -401,70 +401,70 @@  discard block
 block discarded – undo
401 401
     protected static function validateConfig(array $config)
402 402
     {
403 403
         foreach ($config as $configName => $configValue) {
404
-            switch($configName)
404
+            switch ($configName)
405 405
             {
406 406
                 case 'itemDetailedDate':
407
-                    if(!is_bool($configValue)){
407
+                    if (!is_bool($configValue)) {
408 408
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
409 409
                     }
410 410
                     break;
411 411
                 case 'autoTmpFallback':
412
-                    if(!is_bool($configValue)){
412
+                    if (!is_bool($configValue)) {
413 413
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
414 414
                     }
415 415
                     break;
416 416
                 case 'secureFileManipulation':
417
-                    if(!is_bool($configValue)){
417
+                    if (!is_bool($configValue)) {
418 418
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
419 419
                     }
420 420
                     break;
421 421
                 case 'ignoreSymfonyNotice':
422
-                    if(!is_bool($configValue)){
422
+                    if (!is_bool($configValue)) {
423 423
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
424 424
                     }
425 425
                     break;
426 426
                 case 'defaultTtl':
427
-                    if(!is_numeric($configValue)){
427
+                    if (!is_numeric($configValue)) {
428 428
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric");
429 429
                     }
430 430
                     break;
431 431
                 case 'defaultKeyHashFunction':
432
-                    if(!is_string($configValue) && !function_exists($configValue)){
432
+                    if (!is_string($configValue) && !function_exists($configValue)) {
433 433
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string");
434 434
                     }
435 435
                     break;
436 436
                 case 'securityKey':
437
-                    if(!is_string($configValue)){
437
+                    if (!is_string($configValue)) {
438 438
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
439 439
                     }
440 440
                     break;
441 441
                 case 'htaccess':
442
-                    if(!is_bool($configValue)){
442
+                    if (!is_bool($configValue)) {
443 443
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
444 444
                     }
445 445
                     break;
446 446
                 case 'default_chmod':
447
-                    if(!is_int($configValue)){
447
+                    if (!is_int($configValue)) {
448 448
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
449 449
                     }
450 450
                     break;
451 451
                 case 'path':
452
-                    if(!is_string($configValue)){
452
+                    if (!is_string($configValue)) {
453 453
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
454 454
                     }
455 455
                     break;
456 456
                 case 'fallback':
457
-                    if(!is_bool($configValue)){
457
+                    if (!is_bool($configValue)) {
458 458
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
459 459
                     }
460 460
                     break;
461 461
                 case 'limited_memory_each_object':
462
-                    if(!is_int($configValue)){
462
+                    if (!is_int($configValue)) {
463 463
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
464 464
                     }
465 465
                     break;
466 466
                 case 'compress_data':
467
-                    if(!is_bool($configValue)){
467
+                    if (!is_bool($configValue)) {
468 468
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
469 469
                     }
470 470
                     break;
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
             try{
198 198
                 self::$instances[ $instance ] = new $class($config);
199 199
                 self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
200
-            }catch(phpFastCacheDriverCheckException $e){
200
+            } catch(phpFastCacheDriverCheckException $e){
201 201
                 if($config['fallback']){
202 202
                     try{
203 203
                         $fallback = self::standardizeDriverName($config['fallback']);
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
                             self::$instances[ $instance ] = new $class($config);
207 207
                             self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
208 208
                             trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
209
-                        }else{
209
+                        } else{
210 210
                             throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e);
211 211
                         }
212
-                    }catch (phpFastCacheInvalidArgumentException $e){
212
+                    } catch (phpFastCacheInvalidArgumentException $e){
213 213
                         throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
214 214
                     }
215
-                }else{
215
+                } else{
216 216
                     throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
217 217
                 }
218 218
             }
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
             self::$config = array_merge(self::$config, $name);
328 328
         } else if (is_string($name)){
329 329
             self::$config[ $name ] = $value;
330
-        }else{
330
+        } else{
331 331
             throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name');
332 332
         }
333 333
     }
Please login to merge, or discard this patch.