Completed
Pull Request — final (#474)
by Georges
02:42
created
src/phpFastCache/CacheManager.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -203,42 +203,42 @@  discard block
 block discarded – undo
203 203
         }
204 204
 
205 205
         $instance = crc32($driver . serialize($config));
206
-        if (!isset(self::$instances[ $instance ])) {
206
+        if (!isset(self::$instances[$instance])) {
207 207
             $badPracticeOmeter[$driver] = 1;
208
-            if(!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')){
208
+            if (!$config['ignoreSymfonyNotice'] && interface_exists('Symfony\Component\HttpKernel\KernelInterface') && !class_exists('phpFastCache\Bundle\phpFastCacheBundle')) {
209 209
                 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);
210 210
             }
211 211
             $class = self::getNamespacePath() . $driver . '\Driver';
212
-            try{
213
-                self::$instances[ $instance ] = new $class($config);
214
-                self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
215
-            }catch(phpFastCacheDriverCheckException $e){
216
-                if($config['fallback']){
217
-                    try{
212
+            try {
213
+                self::$instances[$instance] = new $class($config);
214
+                self::$instances[$instance]->setEventManager(EventManager::getInstance());
215
+            } catch (phpFastCacheDriverCheckException $e) {
216
+                if ($config['fallback']) {
217
+                    try {
218 218
                         $fallback = self::standardizeDriverName($config['fallback']);
219
-                        if($fallback !== $driver){
219
+                        if ($fallback !== $driver) {
220 220
                             $class = self::getNamespacePath() . $fallback . '\Driver';
221
-                            self::$instances[ $instance ] = new $class($config);
222
-                            self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
221
+                            self::$instances[$instance] = new $class($config);
222
+                            self::$instances[$instance]->setEventManager(EventManager::getInstance());
223 223
                             trigger_error(sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, $fallback), E_USER_WARNING);
224
-                        }else{
224
+                        } else {
225 225
                             throw new phpFastCacheInvalidConfigurationException('The fallback driver cannot be the same than the default driver', 0, $e);
226 226
                         }
227
-                    }catch (phpFastCacheInvalidArgumentException $e){
227
+                    } catch (phpFastCacheInvalidArgumentException $e) {
228 228
                         throw new phpFastCacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e);
229 229
                     }
230
-                }else{
230
+                } else {
231 231
                     throw new phpFastCacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
232 232
                 }
233 233
             }
234
-        } else if($badPracticeOmeter[$driver] >= 5){
234
+        } else if ($badPracticeOmeter[$driver] >= 5) {
235 235
             trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
236 236
            See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
237 237
         }
238 238
 
239 239
         $badPracticeOmeter[$driver]++;
240 240
 
241
-        return self::$instances[ $instance ];
241
+        return self::$instances[$instance];
242 242
     }
243 243
 
244 244
     /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      */
300 300
     public static function __callStatic($name, $arguments)
301 301
     {
302
-        $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[ 0 ] : []);
302
+        $options = (array_key_exists(0, $arguments) && is_array($arguments) ? $arguments[0] : []);
303 303
 
304 304
         return self::getInstance($name, $options);
305 305
     }
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
     {
341 341
         if (is_array($name)) {
342 342
             self::$config = array_merge(self::$config, $name);
343
-        } else if (is_string($name)){
344
-            self::$config[ $name ] = $value;
345
-        }else{
343
+        } else if (is_string($name)) {
344
+            self::$config[$name] = $value;
345
+        } else {
346 346
             throw new phpFastCacheInvalidArgumentException('Invalid variable type: $name');
347 347
         }
348 348
     }
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      */
414 414
     public static function standardizeDriverName($driverName)
415 415
     {
416
-        if(!is_string($driverName)){
416
+        if (!is_string($driverName)) {
417 417
             throw new phpFastCacheInvalidArgumentException(sprintf('Expected $driverName to be a string got "%s" instead', gettype($driverName)));
418 418
         }
419 419
         return ucfirst(strtolower(trim($driverName)));
@@ -428,81 +428,81 @@  discard block
 block discarded – undo
428 428
     protected static function validateConfig(array $config)
429 429
     {
430 430
         foreach ($config as $configName => $configValue) {
431
-            switch($configName)
431
+            switch ($configName)
432 432
             {
433 433
                 case 'itemDetailedDate':
434
-                    if(!is_bool($configValue)){
434
+                    if (!is_bool($configValue)) {
435 435
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
436 436
                     }
437 437
                     break;
438 438
                 case 'autoTmpFallback':
439
-                    if(!is_bool($configValue)){
439
+                    if (!is_bool($configValue)) {
440 440
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
441 441
                     }
442 442
                     break;
443 443
                 case 'secureFileManipulation':
444
-                    if(!is_bool($configValue)){
444
+                    if (!is_bool($configValue)) {
445 445
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
446 446
                     }
447 447
                     break;
448 448
                 case 'ignoreSymfonyNotice':
449
-                    if(!is_bool($configValue)){
449
+                    if (!is_bool($configValue)) {
450 450
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
451 451
                     }
452 452
                     break;
453 453
                 case 'defaultTtl':
454
-                    if(!is_numeric($configValue)){
454
+                    if (!is_numeric($configValue)) {
455 455
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be numeric");
456 456
                     }
457 457
                     break;
458 458
                 case 'defaultKeyHashFunction':
459
-                    if(!is_string($configValue) && !function_exists($configValue)){
459
+                    if (!is_string($configValue) && !function_exists($configValue)) {
460 460
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a valid function name string");
461 461
                     }
462 462
                     break;
463 463
                 case 'securityKey':
464
-                    if(!is_string($configValue)){
464
+                    if (!is_string($configValue)) {
465 465
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
466 466
                     }
467 467
                     break;
468 468
                 case 'htaccess':
469
-                    if(!is_bool($configValue)){
469
+                    if (!is_bool($configValue)) {
470 470
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
471 471
                     }
472 472
                     break;
473 473
                 case 'default_chmod':
474
-                    if(!is_int($configValue)){
474
+                    if (!is_int($configValue)) {
475 475
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
476 476
                     }
477 477
                     break;
478 478
                 case 'path':
479
-                    if(!is_string($configValue)){
479
+                    if (!is_string($configValue)) {
480 480
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a string");
481 481
                     }
482 482
                     break;
483 483
                 case 'fallback':
484
-                    if(!is_bool($configValue) && !is_string($configValue)){
484
+                    if (!is_bool($configValue) && !is_string($configValue)) {
485 485
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean or string");
486 486
                     }
487 487
                     break;
488 488
                 case 'limited_memory_each_object':
489
-                    if(!is_int($configValue)){
489
+                    if (!is_int($configValue)) {
490 490
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be an integer");
491 491
                     }
492 492
                     break;
493 493
                 case 'compress_data':
494
-                    if(!is_bool($configValue)){
494
+                    if (!is_bool($configValue)) {
495 495
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
496 496
                     }
497 497
                     break;
498 498
                 case 'cacheFileExtension':
499
-                    if(!is_string($configValue)){
499
+                    if (!is_string($configValue)) {
500 500
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
501 501
                     }
502
-                    if(strpos($configValue, '.') !== false){
502
+                    if (strpos($configValue, '.') !== false) {
503 503
                         throw new phpFastCacheInvalidConfigurationException("{$configName} cannot contain a dot \".\"");
504 504
                     }
505
-                    if(!in_array($configValue, self::$safeFileExtensions)){
505
+                    if (!in_array($configValue, self::$safeFileExtensions)) {
506 506
                         throw new phpFastCacheInvalidConfigurationException(
507 507
                           "{$configName} is not a safe extension, currently allowed extension: " . implode(', ', self::$safeFileExtensions)
508 508
                         );
Please login to merge, or discard this patch.