Passed
Push — v7 ( c2ec86...629ebb )
by Georges
01:43
created
lib/Phpfastcache/CacheManager.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  * @author Georges.L (Geolim4)  <[email protected]>
12 12
  *
13 13
  */
14
-declare(strict_types=1);
14
+declare(strict_types = 1);
15 15
 
16 16
 namespace Phpfastcache;
17 17
 
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
               'The CacheManager will drops the support of primitive configuration arrays, use a "\Phpfastcache\Config\ConfigurationOption" object instead',
119 119
               E_USER_DEPRECATED
120 120
             );
121
-        }elseif ($config === null){
121
+        }elseif ($config === null) {
122 122
             $config = self::getDefaultConfig();
123
-        }else if(!($config instanceof ConfigurationOption)){
123
+        } else if (!($config instanceof ConfigurationOption)) {
124 124
             throw new PhpfastcacheInvalidArgumentException(\sprintf('Unsupported config type: %s', gettype($config)));
125 125
         }
126 126
 
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
 
133 133
         $instance = $instanceId ?: md5($driver . \serialize($config->toArray()));
134 134
 
135
-        if (!isset(self::$instances[ $instance ])) {
136
-            self::$badPracticeOmeter[ $driver ] = 1;
135
+        if (!isset(self::$instances[$instance])) {
136
+            self::$badPracticeOmeter[$driver] = 1;
137 137
             $driverClass = self::getDriverClass($driver);
138 138
 
139
-            if(!is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)){
139
+            if (!is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
140 140
                 throw new PhpfastcacheDriverException(sprintf(
141 141
                   'Class "%s" does not implement "%s"',
142 142
                   $driverClass,
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
             try {
147 147
                 if (\class_exists($driverClass)) {
148 148
                     $configClass = $driverClass::getConfigClass();
149
-                    self::$instances[ $instance ] = new $driverClass(new $configClass($config->toArray()), $instance);
150
-                    self::$instances[ $instance ]->setEventManager(EventManager::getInstance());
149
+                    self::$instances[$instance] = new $driverClass(new $configClass($config->toArray()), $instance);
150
+                    self::$instances[$instance]->setEventManager(EventManager::getInstance());
151 151
                 } else {
152 152
                     throw new PhpfastcacheDriverNotFoundException(\sprintf('The driver "%s" does not exists', $driver));
153 153
                 }
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
                     throw new PhpfastcacheDriverCheckException($e->getMessage(), $e->getCode(), $e);
166 166
                 }
167 167
             }
168
-        } else if (self::$badPracticeOmeter[ $driver ] >= 2) {
168
+        } else if (self::$badPracticeOmeter[$driver] >= 2) {
169 169
             trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
170 170
            See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F');
171 171
         }
172 172
 
173
-        self::$badPracticeOmeter[ $driver ]++;
173
+        self::$badPracticeOmeter[$driver]++;
174 174
 
175
-        return self::$instances[ $instance ];
175
+        return self::$instances[$instance];
176 176
     }
177 177
 
178 178
     /**
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
             throw new PhpfastcacheInvalidArgumentException('The Instance ID must be a string');
190 190
         }
191 191
 
192
-        if (isset(self::$instances[ $instanceId ])) {
193
-            return self::$instances[ $instanceId ];
192
+        if (isset(self::$instances[$instanceId])) {
193
+            return self::$instances[$instanceId];
194 194
         }
195 195
 
196 196
         throw new PhpfastcacheInstanceNotFoundException(\sprintf('Instance ID %s not found', $instanceId));
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         if ($autoDriver === null) {
239 239
             foreach (self::getDriverList() as $driver) {
240 240
                 /** @var ExtendedCacheItemPoolInterface $driver */
241
-                if((self::CORE_DRIVER_NAMESPACE . $driver . '\Driver')::isUsableInAutoContext()){
241
+                if ((self::CORE_DRIVER_NAMESPACE . $driver . '\Driver')::isUsableInAutoContext()) {
242 242
                     try {
243 243
                         self::getInstance($driver, $config);
244 244
                         $autoDriver = $driver;
@@ -250,11 +250,11 @@  discard block
 block discarded – undo
250 250
             }
251 251
         }
252 252
 
253
-        if(!$autoDriver || !\is_string($autoDriver)){
253
+        if (!$autoDriver || !\is_string($autoDriver)) {
254 254
             throw new PhpfastcacheLogicException('Unable to find out a valid driver automatically');
255 255
         }
256 256
 
257
-        self::$badPracticeOmeter[ $autoDriver ]--;
257
+        self::$badPracticeOmeter[$autoDriver]--;
258 258
 
259 259
         return $autoDriver;
260 260
     }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
      */
267 267
     public static function __callStatic(string $name, array $arguments): ExtendedCacheItemPoolInterface
268 268
     {
269
-        $options = (\array_key_exists(0, $arguments) && \is_array($arguments) ? $arguments[ 0 ] : []);
269
+        $options = (\array_key_exists(0, $arguments) && \is_array($arguments) ? $arguments[0] : []);
270 270
 
271 271
         return self::getInstance($name, $options);
272 272
     }
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
     {
379 379
         static $driverList;
380 380
 
381
-        if(self::getDefaultNamespacePath() === self::getNamespacePath()){
382
-            if($driverList === null){
381
+        if (self::getDefaultNamespacePath() === self::getNamespacePath()) {
382
+            if ($driverList === null) {
383 383
                 $prefix = self::CORE_DRIVER_NAMESPACE;
384 384
                 $classMap = self::createClassMap(__DIR__ . '/Drivers');
385 385
                 $driverList = [];
386 386
 
387 387
                 foreach ($classMap as $class => $file) {
388
-                    $driverList[] = str_replace($prefix, '', substr($class, 0, strrpos($class, '\\') ));
388
+                    $driverList[] = str_replace($prefix, '', substr($class, 0, strrpos($class, '\\')));
389 389
                 }
390 390
 
391 391
                 $driverList = array_values(array_unique($driverList));
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
      */
417 417
     public static function getDriverClass(string $driverName): string
418 418
     {
419
-        if(!empty(self::$driverCustoms[$driverName])){
419
+        if (!empty(self::$driverCustoms[$driverName])) {
420 420
             $driverClass = self::$driverCustoms[$driverName];
421
-        }else if(!empty(self::$driverOverrides[$driverName])){
421
+        } else if (!empty(self::$driverOverrides[$driverName])) {
422 422
             $driverClass = self::$driverOverrides[$driverName];
423
-        } else{
423
+        } else {
424 424
             $driverClass = self::getNamespacePath() . $driverName . '\Driver';
425 425
         }
426 426
 
@@ -435,24 +435,24 @@  discard block
 block discarded – undo
435 435
      * @throws \Phpfastcache\Exceptions\PhpfastcacheUnsupportedOperationException
436 436
      * @return void
437 437
      */
438
-    public static function addCustomDriver(string $driverName, string $className){
438
+    public static function addCustomDriver(string $driverName, string $className) {
439 439
         $driverName = self::standardizeDriverName($driverName);
440 440
 
441
-        if(empty($driverName)){
441
+        if (empty($driverName)) {
442 442
             throw new PhpfastcacheInvalidArgumentException("Can't add a custom driver because its name is empty");
443 443
         }
444 444
 
445
-        if(!\class_exists($className)){
445
+        if (!\class_exists($className)) {
446 446
             throw new PhpfastcacheInvalidArgumentException(
447 447
               sprintf("Can't add '%s' because the class '%s' does not exists", $driverName, $className)
448 448
             );
449 449
         }
450 450
 
451
-        if(!empty(self::$driverCustoms[$driverName])){
451
+        if (!empty(self::$driverCustoms[$driverName])) {
452 452
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' has been already added", $driverName));
453 453
         }
454 454
 
455
-        if(\in_array($driverName, self::getDriverList(), true)){
455
+        if (\in_array($driverName, self::getDriverList(), true)) {
456 456
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' is already a part of the PhpFastCache core", $driverName));
457 457
         }
458 458
 
@@ -469,11 +469,11 @@  discard block
 block discarded – undo
469 469
     {
470 470
         $driverName = self::standardizeDriverName($driverName);
471 471
 
472
-        if(empty($driverName)){
472
+        if (empty($driverName)) {
473 473
             throw new PhpfastcacheInvalidArgumentException("Can't remove a custom driver because its name is empty");
474 474
         }
475 475
 
476
-        if(!isset(self::$driverCustoms[$driverName])){
476
+        if (!isset(self::$driverCustoms[$driverName])) {
477 477
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' does not exists", $driverName));
478 478
         }
479 479
 
@@ -488,28 +488,28 @@  discard block
 block discarded – undo
488 488
      * @throws \Phpfastcache\Exceptions\PhpfastcacheUnsupportedOperationException
489 489
      * @return void
490 490
      */
491
-    public static function addCoreDriverOverride(string $driverName, string $className){
491
+    public static function addCoreDriverOverride(string $driverName, string $className) {
492 492
         $driverName = self::standardizeDriverName($driverName);
493 493
 
494
-        if(empty($driverName)){
494
+        if (empty($driverName)) {
495 495
             throw new PhpfastcacheInvalidArgumentException("Can't add a core driver override because its name is empty");
496 496
         }
497 497
 
498
-        if(!\class_exists($className)){
498
+        if (!\class_exists($className)) {
499 499
             throw new PhpfastcacheInvalidArgumentException(
500 500
               sprintf("Can't override '%s' because the class '%s' does not exists", $driverName, $className)
501 501
             );
502 502
         }
503 503
 
504
-        if(!empty(self::$driverOverrides[$driverName])){
504
+        if (!empty(self::$driverOverrides[$driverName])) {
505 505
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' has been already overridden", $driverName));
506 506
         }
507 507
 
508
-        if(!\in_array($driverName, self::getDriverList(), true)){
508
+        if (!\in_array($driverName, self::getDriverList(), true)) {
509 509
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' can't be overridden since its not a part of the PhpFastCache core", $driverName));
510 510
         }
511 511
 
512
-        if(!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)){
512
+        if (!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)) {
513 513
             throw new PhpfastcacheLogicException(
514 514
               sprintf("Can't override '%s' because the class '%s' MUST extend '%s'", $driverName, $className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver')
515 515
             );
@@ -528,11 +528,11 @@  discard block
 block discarded – undo
528 528
     {
529 529
         $driverName = self::standardizeDriverName($driverName);
530 530
 
531
-        if(empty($driverName)){
531
+        if (empty($driverName)) {
532 532
             throw new PhpfastcacheInvalidArgumentException("Can't remove a core driver override because its name is empty");
533 533
         }
534 534
 
535
-        if(!isset(self::$driverOverrides[$driverName])){
535
+        if (!isset(self::$driverOverrides[$driverName])) {
536 536
             throw new PhpfastcacheLogicException(sprintf("Driver '%s' were not overridden", $driverName));
537 537
         }
538 538
 
Please login to merge, or discard this patch.