Completed
Pull Request — final (#469)
by Georges
02:44
created
src/phpFastCache/CacheManager.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -64,101 +64,101 @@  discard block
 block discarded – undo
64 64
         /**
65 65
          * Specify if the item must provide detailed creation/modification dates
66 66
          */
67
-      'itemDetailedDate' => false,
67
+        'itemDetailedDate' => false,
68 68
 
69 69
         /**
70 70
          * Automatically attempt to fallback to temporary directory
71 71
          * if the cache fails to write on the specified directory
72 72
          */
73
-      'autoTmpFallback' => false,
73
+        'autoTmpFallback' => false,
74 74
 
75 75
         /**
76 76
          * Provide a secure file manipulation mechanism,
77 77
          * on intensive usage the performance can be affected.
78 78
          */
79
-      'secureFileManipulation' => false,
79
+        'secureFileManipulation' => false,
80 80
 
81 81
         /**
82 82
          * Ignore Symfony notice for Symfony project which
83 83
          * do not makes use of PhpFastCache's Symfony Bundle
84 84
          */
85
-      'ignoreSymfonyNotice' => false,
85
+        'ignoreSymfonyNotice' => false,
86 86
 
87 87
         /**
88 88
          * Default time-to-live in second
89 89
          */
90
-      'defaultTtl' => 900,
90
+        'defaultTtl' => 900,
91 91
 
92 92
         /**
93 93
          * Default key hash function
94 94
          * (md5 by default)
95 95
          */
96
-      'defaultKeyHashFunction' => '',
96
+        'defaultKeyHashFunction' => '',
97 97
 
98 98
         /**
99 99
          * The securityKey that will be used
100 100
          * to create sub-directory
101 101
          * (Files-based drivers only)
102 102
          */
103
-      'securityKey' => 'Auto',
103
+        'securityKey' => 'Auto',
104 104
 
105 105
         /**
106 106
          * Auto-generate .htaccess if it's missing
107 107
          * (Files-based drivers only)
108 108
          */
109
-      'htaccess' => true,
109
+        'htaccess' => true,
110 110
 
111 111
         /**
112 112
          * Default files chmod
113 113
          * 0777 recommended
114 114
          * (Files-based drivers only)
115 115
          */
116
-      'default_chmod' => 0777,
116
+        'default_chmod' => 0777,
117 117
 
118 118
         /**
119 119
          * The path where we will writecache files
120 120
          * default value if empty: sys_get_temp_dir()
121 121
          * (Files-based drivers only)
122 122
          */
123
-      'path' => '',
123
+        'path' => '',
124 124
 
125 125
         /**
126 126
          * Driver fallback in case of failure.
127 127
          * Caution, in case of failure an E_WARNING
128 128
          * error will always be raised
129 129
          */
130
-      'fallback' => false,
130
+        'fallback' => false,
131 131
 
132 132
         /**
133 133
          * Maximum size (bytes) of object store in memory
134 134
          * (Memcache(d) drivers only)
135 135
          */
136
-      'limited_memory_each_object' => 4096,
136
+        'limited_memory_each_object' => 4096,
137 137
 
138 138
         /**
139 139
          * Compress stored data, if the backend supports it
140 140
          * (Memcache(d) drivers only)
141 141
          */
142
-      'compress_data' => false,
142
+        'compress_data' => false,
143 143
 
144 144
         /**
145 145
          * Prevent cache slams when
146 146
          * making use of heavy cache
147 147
          * items
148 148
          */
149
-      'preventCacheSlams' => false,
149
+        'preventCacheSlams' => false,
150 150
 
151 151
         /**
152 152
          * Cache slams timeout
153 153
          * in seconds
154 154
          */
155
-      'cacheSlamsTimeout' => 15,
155
+        'cacheSlamsTimeout' => 15,
156 156
 
157 157
         /**
158 158
          * Cache slams timeout
159 159
          * in seconds
160 160
          */
161
-      'cacheFileExtension' => 'txt',
161
+        'cacheFileExtension' => 'txt',
162 162
 
163 163
     ];
164 164
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      * @var array
169 169
      */
170 170
     protected static $safeFileExtensions = [
171
-      'txt', 'cache', 'db', 'pfc'
171
+        'txt', 'cache', 'db', 'pfc'
172 172
     ];
173 173
 
174 174
     /**
@@ -373,24 +373,24 @@  discard block
 block discarded – undo
373 373
     public static function getStaticSystemDrivers()
374 374
     {
375 375
         return [
376
-          'Apc',
377
-          'Apcu',
378
-          'Cassandra',
379
-          'Couchbase',
380
-          'Couchdb',
381
-          'Devnull',
382
-          'Files',
383
-          'Leveldb',
384
-          'Memcache',
385
-          'Memcached',
386
-          'Memstatic',
387
-          'Mongodb',
388
-          'Predis',
389
-          'Redis',
390
-          'Ssdb',
391
-          'Sqlite',
392
-          'Wincache',
393
-          'Xcache',
376
+            'Apc',
377
+            'Apcu',
378
+            'Cassandra',
379
+            'Couchbase',
380
+            'Couchdb',
381
+            'Devnull',
382
+            'Files',
383
+            'Leveldb',
384
+            'Memcache',
385
+            'Memcached',
386
+            'Memstatic',
387
+            'Mongodb',
388
+            'Predis',
389
+            'Redis',
390
+            'Ssdb',
391
+            'Sqlite',
392
+            'Wincache',
393
+            'Xcache',
394 394
         ];
395 395
     }
396 396
 
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
     public static function getStaticAllDrivers()
401 401
     {
402 402
         return array_merge(self::getStaticSystemDrivers(), [
403
-          'Devtrue',
404
-          'Devfalse',
405
-          'Cookie',
403
+            'Devtrue',
404
+            'Devfalse',
405
+            'Cookie',
406 406
         ]);
407 407
     }
408 408
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
                     }
505 505
                     if(!in_array($configValue, self::$safeFileExtensions)){
506 506
                         throw new phpFastCacheInvalidConfigurationException(
507
-                          "{$configName} is not a safe extension, currently allowed extension: " . implode(', ', self::$safeFileExtensions)
507
+                            "{$configName} is not a safe extension, currently allowed extension: " . implode(', ', self::$safeFileExtensions)
508 508
                         );
509 509
                     }
510 510
                     break;
Please login to merge, or discard this 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)){
484
+                    if (!is_bool($configValue)) {
485 485
                         throw new phpFastCacheInvalidConfigurationException("{$configName} must be a boolean");
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.
src/phpFastCache/Core/Pool/IO/IOHelperTrait.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
          * Calculate the security key
52 52
          */
53 53
         {
54
-            $securityKey = array_key_exists('securityKey', $this->config) ? $this->config[ 'securityKey' ] : '';
54
+            $securityKey = array_key_exists('securityKey', $this->config) ? $this->config['securityKey'] : '';
55 55
             if (!$securityKey || $securityKey === 'auto') {
56
-                if (isset($_SERVER[ 'HTTP_HOST' ])) {
57
-                    $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER[ 'HTTP_HOST' ])));
56
+                if (isset($_SERVER['HTTP_HOST'])) {
57
+                    $securityKey = preg_replace('/^www./', '', strtolower(str_replace(':', '_', $_SERVER['HTTP_HOST'])));
58 58
                 } else {
59 59
                     $securityKey = ($this->isPHPModule() ? 'web' : 'cli');
60 60
                 }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
          */
74 74
         $tmp_dir = rtrim($tmp_dir, '/') . DIRECTORY_SEPARATOR;
75 75
 
76
-        if (empty($this->config[ 'path' ]) || !is_string($this->config[ 'path' ])) {
76
+        if (empty($this->config['path']) || !is_string($this->config['path'])) {
77 77
             $path = $tmp_dir;
78 78
         } else {
79
-            $path = rtrim($this->config[ 'path' ], '/') . DIRECTORY_SEPARATOR;
79
+            $path = rtrim($this->config['path'], '/') . DIRECTORY_SEPARATOR;
80 80
         }
81 81
 
82 82
         $path_suffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName();
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
          * return the temp dir
92 92
          */
93 93
         if ($readonly === true) {
94
-            if($this->config[ 'autoTmpFallback' ] && (!@file_exists($full_path) || !@is_writable($full_path))){
94
+            if ($this->config['autoTmpFallback'] && (!@file_exists($full_path) || !@is_writable($full_path))) {
95 95
                 return $full_path_tmp;
96 96
             }
97 97
             return $full_path;
98
-        }else{
99
-            if (!isset($this->tmp[ $full_path_hash ]) || (!@file_exists($full_path) || !@is_writable($full_path))) {
98
+        } else {
99
+            if (!isset($this->tmp[$full_path_hash]) || (!@file_exists($full_path) || !@is_writable($full_path))) {
100 100
                 if (!@file_exists($full_path)) {
101 101
                     @mkdir($full_path, $this->getDefaultChmod(), true);
102
-                }else if (!@is_writable($full_path)) {
103
-                    if (!@chmod($full_path, $this->getDefaultChmod()) && $this->config[ 'autoTmpFallback' ])
102
+                } else if (!@is_writable($full_path)) {
103
+                    if (!@chmod($full_path, $this->getDefaultChmod()) && $this->config['autoTmpFallback'])
104 104
                     {
105 105
                         /**
106 106
                          * Switch back to tmp dir
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
                     throw new phpFastCacheIOException('Path "' . $full_path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !');
123 123
                 }
124 124
 
125
-                $this->tmp[ $full_path_hash ] = $full_path;
126
-                $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config[ 'htaccess' ] : false);
125
+                $this->tmp[$full_path_hash] = $full_path;
126
+                $this->htaccessGen($full_path, array_key_exists('htaccess', $this->config) ? $this->config['htaccess'] : false);
127 127
             }
128 128
         }
129 129
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             }
161 161
         }
162 162
 
163
-        return $path . '/' . $filename . '.' . $this->config[ 'cacheFileExtension' ];
163
+        return $path . '/' . $filename . '.' . $this->config['cacheFileExtension'];
164 164
     }
165 165
 
166 166
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
      */
180 180
     protected function getDefaultChmod()
181 181
     {
182
-        if (!isset($this->config[ 'default_chmod' ]) || $this->config[ 'default_chmod' ] == '' || is_null($this->config[ 'default_chmod' ])) {
182
+        if (!isset($this->config['default_chmod']) || $this->config['default_chmod'] == '' || is_null($this->config['default_chmod'])) {
183 183
             return 0777;
184 184
         } else {
185
-            return $this->config[ 'default_chmod' ];
185
+            return $this->config['default_chmod'];
186 186
         }
187 187
     }
188 188
 
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         if ($create === true) {
213 213
             if (!is_writable($path)) {
214 214
                 try {
215
-                    if(!chmod($path, 0777)){
215
+                    if (!chmod($path, 0777)) {
216 216
                         throw new phpFastCacheIOException('Chmod failed on : ' . $path);
217 217
                     }
218 218
                 } catch (phpFastCacheIOException $e) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
          */
288 288
         $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation);
289 289
 
290
-        if($secureFileManipulation){
290
+        if ($secureFileManipulation) {
291 291
             $tmpFilename = Directory::getAbsolutePath(dirname($file) . '/tmp_' . md5(
292 292
                 str_shuffle(uniqid($this->getDriverName(), false))
293 293
                 . str_shuffle(uniqid($this->getDriverName(), false))
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
             flock($f, LOCK_UN);
300 300
             fclose($f);
301 301
 
302
-            if(!rename($tmpFilename, $file)){
302
+            if (!rename($tmpFilename, $file)) {
303 303
                 throw new phpFastCacheIOException(sprintf('Failed to rename %s to %s', $tmpFilename, $file));
304 304
             }
305
-        }else{
305
+        } else {
306 306
             $f = fopen($file, 'w+');
307 307
             $octetWritten = fwrite($f, $data);
308 308
             fclose($f);
Please login to merge, or discard this patch.