Completed
Pull Request — final (#478)
by Georges
02:25
created
src/phpFastCache/Core/Item/ItemExtendedTrait.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -53,13 +53,13 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function getEncodedKey()
55 55
     {
56
-        if(!$this->encodedKey){
56
+        if (!$this->encodedKey) {
57 57
             $keyHashFunction = $this->driver->getConfigOption('defaultKeyHashFunction');
58 58
 
59
-            if($keyHashFunction){
60
-                $this->encodedKey =  $keyHashFunction($this->getKey());
61
-            }else{
62
-                $this->encodedKey =  md5($this->getKey());
59
+            if ($keyHashFunction) {
60
+                $this->encodedKey = $keyHashFunction($this->getKey());
61
+            } else {
62
+                $this->encodedKey = md5($this->getKey());
63 63
             }
64 64
         }
65 65
 
@@ -105,9 +105,9 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function getCreationDate()
107 107
     {
108
-        if($this->driver->getConfig()['itemDetailedDate']){
108
+        if ($this->driver->getConfig()['itemDetailedDate']) {
109 109
             return $this->creationDate;
110
-        }else{
110
+        } else {
111 111
             throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
112 112
         }
113 113
     }
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
      */
120 120
     public function setCreationDate(\DateTimeInterface $date)
121 121
     {
122
-        if($this->driver->getConfig()['itemDetailedDate']){
122
+        if ($this->driver->getConfig()['itemDetailedDate']) {
123 123
             $this->creationDate = $date;
124 124
             return $this;
125
-        }else{
125
+        } else {
126 126
             throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
127 127
         }
128 128
     }
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function getModificationDate()
135 135
     {
136
-        if($this->driver->getConfig()['itemDetailedDate']){
136
+        if ($this->driver->getConfig()['itemDetailedDate']) {
137 137
             return $this->modificationDate;
138
-        }else{
138
+        } else {
139 139
             throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
140 140
         }
141 141
     }
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public function setModificationDate(\DateTimeInterface $date)
149 149
     {
150
-        if($this->driver->getConfig()['itemDetailedDate']){
150
+        if ($this->driver->getConfig()['itemDetailedDate']) {
151 151
             $this->modificationDate = $date;
152 152
             return $this;
153
-        }else{
153
+        } else {
154 154
             throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
155 155
         }
156 156
     }
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
     public function removeTag($tagName)
319 319
     {
320 320
         if (($key = array_search($tagName, $this->tags)) !== false) {
321
-            unset($this->tags[ $key ]);
321
+            unset($this->tags[$key]);
322 322
             $this->removedTags[] = $tagName;
323 323
         }
324 324
 
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
     final public function __debugInfo()
398 398
     {
399 399
         $info = get_object_vars($this);
400
-        $info[ 'driver' ] = 'object(' . get_class($info[ 'driver' ]) . ')';
400
+        $info['driver'] = 'object(' . get_class($info['driver']) . ')';
401 401
 
402 402
         return (array) $info;
403 403
     }
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
             if($keyHashFunction){
60 60
                 $this->encodedKey =  $keyHashFunction($this->getKey());
61
-            }else{
61
+            } else{
62 62
                 $this->encodedKey =  md5($this->getKey());
63 63
             }
64 64
         }
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     {
108 108
         if($this->driver->getConfig()['itemDetailedDate']){
109 109
             return $this->creationDate;
110
-        }else{
110
+        } else{
111 111
             throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
112 112
         }
113 113
     }
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         if($this->driver->getConfig()['itemDetailedDate']){
123 123
             $this->creationDate = $date;
124 124
             return $this;
125
-        }else{
125
+        } else{
126 126
             throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
127 127
         }
128 128
     }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
     {
136 136
         if($this->driver->getConfig()['itemDetailedDate']){
137 137
             return $this->modificationDate;
138
-        }else{
138
+        } else{
139 139
             throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
140 140
         }
141 141
     }
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
         if($this->driver->getConfig()['itemDetailedDate']){
151 151
             $this->modificationDate = $date;
152 152
             return $this;
153
-        }else{
153
+        } else{
154 154
             throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
155 155
         }
156 156
     }
Please login to merge, or discard this patch.
src/phpFastCache/Core/Pool/CacheItemPoolTrait.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
              * loop dispatching operations
70 70
              */
71 71
             if (!isset($this->itemInstances[$key])) {
72
-                if (preg_match('~([' . preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)){
72
+                if (preg_match('~([' . preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) {
73 73
                     throw new phpFastCacheInvalidArgumentException('Unsupported key character detected: "' . $matches[1] . '". Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers');
74 74
                 }
75 75
 
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
                     $driverArray = $this->driverRead($item);
88 88
 
89 89
                     if ($driverArray) {
90
-                        if(!is_array($driverArray)){
90
+                        if (!is_array($driverArray)) {
91 91
                             throw new phpFastCacheCoreException(sprintf('The driverRead method returned an unexpected variable type: %s', gettype($driverArray)));
92 92
                         }
93 93
                         $driverData = $this->driverUnwrapData($driverArray);
94 94
 
95
-                        if($this->getConfig()[ 'preventCacheSlams' ]){
96
-                            while($driverData instanceof ItemBatch) {
97
-                                if($driverData->getItemDate()->getTimestamp() + $this->getConfig()[ 'cacheSlamsTimeout' ] < time()){
95
+                        if ($this->getConfig()['preventCacheSlams']) {
96
+                            while ($driverData instanceof ItemBatch) {
97
+                                if ($driverData->getItemDate()->getTimestamp() + $this->getConfig()['cacheSlamsTimeout'] < time()) {
98 98
                                     /**
99 99
                                      * The timeout has been reached
100 100
                                      * Consider that the batch has
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                         $item->set($driverData);
127 127
                         $item->expiresAt($this->driverUnwrapEdate($driverArray));
128 128
 
129
-                        if($this->config['itemDetailedDate']){
129
+                        if ($this->config['itemDetailedDate']) {
130 130
 
131 131
                             /**
132 132
                              * If the itemDetailedDate has been
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
                              * Reset the Item
155 155
                              */
156 156
                             $item->set(null)
157
-                              ->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ]))
157
+                              ->expiresAfter(abs((int) $this->getConfig()['defaultTtl']))
158 158
                               ->setHit(false)
159 159
                               ->setTags([]);
160
-                            if($this->config['itemDetailedDate']){
160
+                            if ($this->config['itemDetailedDate']) {
161 161
 
162 162
                                 /**
163 163
                                  * If the itemDetailedDate has been
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
                         } else {
171 171
                             $item->setHit(true);
172 172
                         }
173
-                    }else{
174
-                        $item->expiresAfter(abs((int) $this->getConfig()[ 'defaultTtl' ]));
173
+                    } else {
174
+                        $item->expiresAfter(abs((int) $this->getConfig()['defaultTtl']));
175 175
                     }
176 176
                 }
177 177
             }
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
          * @param $this ExtendedCacheItemPoolInterface
185 185
          * @param $this ExtendedCacheItemInterface
186 186
          */
187
-        $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[ $key ]);
187
+        $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[$key]);
188 188
 
189
-        return $this->itemInstances[ $key ];
189
+        return $this->itemInstances[$key];
190 190
     }
191 191
 
192 192
     /**
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     public function setItem(CacheItemInterface $item)
198 198
     {
199 199
         if ($this->getClassNamespace() . '\\Item' === get_class($item)) {
200
-            $this->itemInstances[ $item->getKey() ] = $item;
200
+            $this->itemInstances[$item->getKey()] = $item;
201 201
 
202 202
             return $this;
203 203
         } else {
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
     {
215 215
         $collection = [];
216 216
         foreach ($keys as $key) {
217
-            $collection[ $key ] = $this->getItem($key);
217
+            $collection[$key] = $this->getItem($key);
218 218
         }
219 219
 
220 220
         return $collection;
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
          * loop dispatching operations
316 316
          */
317 317
         if (!isset($this->itemInstances[$item->getKey()])) {
318
-            $this->itemInstances[ $item->getKey() ] = $item;
319
-        } else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){
318
+            $this->itemInstances[$item->getKey()] = $item;
319
+        } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) {
320 320
             throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
321 321
         }
322 322
 
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         $this->eventManager->dispatch('CacheSaveItem', $this, $item);
329 329
 
330 330
 
331
-        if($this->getConfig()[ 'preventCacheSlams' ]){
331
+        if ($this->getConfig()['preventCacheSlams']) {
332 332
             /**
333 333
              * @var $itemBatch ExtendedCacheItemInterface
334 334
              */
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
             $itemBatch = $class->newInstanceArgs([$this, $item->getKey()]);
337 337
             $itemBatch->setEventManager($this->eventManager)
338 338
                         ->set(new ItemBatch($item->getKey(), new \DateTime()))
339
-                        ->expiresAfter($this->getConfig()[ 'cacheSlamsTimeout' ]);
339
+                        ->expiresAfter($this->getConfig()['cacheSlamsTimeout']);
340 340
 
341 341
             /**
342 342
              * To avoid SPL mismatches
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
     public function saveDeferred(CacheItemInterface $item)
369 369
     {
370 370
         if (!array_key_exists($item->getKey(), $this->itemInstances)) {
371
-            $this->itemInstances[ $item->getKey() ] = $item;
372
-        }else if(spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])){
371
+            $this->itemInstances[$item->getKey()] = $item;
372
+        } else if (spl_object_hash($item) !== spl_object_hash($this->itemInstances[$item->getKey()])) {
373 373
             throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
374 374
         }
375 375
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
          */
381 381
         $this->eventManager->dispatch('CacheSaveDeferredItem', $this, $item);
382 382
 
383
-        return $this->deferredList[ $item->getKey() ] = $item;
383
+        return $this->deferredList[$item->getKey()] = $item;
384 384
     }
385 385
 
386 386
     /**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
         foreach ($this->deferredList as $key => $item) {
401 401
             $result = $this->save($item);
402 402
             if ($return !== false) {
403
-                unset($this->deferredList[ $key ]);
403
+                unset($this->deferredList[$key]);
404 404
                 $return = $result;
405 405
             }
406 406
         }
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.
src/phpFastCache/EventManager.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -74,8 +74,8 @@  discard block
 block discarded – undo
74 74
          * due to performance issue on huge
75 75
          * loop dispatching operations
76 76
          */
77
-        if(isset($this->events[$eventName])){
78
-            foreach ($this->events[ $eventName ] as $event) {
77
+        if (isset($this->events[$eventName])) {
78
+            foreach ($this->events[$eventName] as $event) {
79 79
                 call_user_func_array($event, $args);
80 80
             }
81 81
         }
@@ -89,18 +89,18 @@  discard block
 block discarded – undo
89 89
      */
90 90
     public function __call($name, $arguments)
91 91
     {
92
-        if(strpos($name, 'on') === 0){
92
+        if (strpos($name, 'on') === 0) {
93 93
             $name = substr($name, 2);
94
-            if(is_callable($arguments[0])){
95
-                if(isset($arguments[1]) && is_string($arguments[0])){
94
+            if (is_callable($arguments[0])) {
95
+                if (isset($arguments[1]) && is_string($arguments[0])) {
96 96
                     $this->events[$name][$arguments[1]] = $arguments[0];
97
-                }else {
97
+                } else {
98 98
                     $this->events[$name][] = $arguments[0];
99 99
                 }
100
-            }else{
100
+            } else {
101 101
                 throw new phpFastCacheInvalidArgumentException(sprintf('Expected Callable, got "%s"', gettype($arguments[0])));
102 102
             }
103
-        }else{
103
+        } else {
104 104
             throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"');
105 105
         }
106 106
     }
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      */
113 113
     public function unbindEventCallback($eventName, $callbackName)
114 114
     {
115
-        if(isset($this->events[$eventName][$callbackName])){
115
+        if (isset($this->events[$eventName][$callbackName])) {
116 116
             unset($this->events[$eventName][$callbackName]);
117 117
             return true;
118 118
         }
Please login to merge, or discard this patch.
src/phpFastCache/Util/ClassNamespaceResolverTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
     protected function getClassNamespace()
32 32
     {
33 33
         if (!$this->namespace) {
34
-            $this->namespace = substr(static::class, 0, strrpos( static::class, '\\'));
34
+            $this->namespace = substr(static::class, 0, strrpos(static::class, '\\'));
35 35
         }
36 36
 
37 37
         return $this->namespace;
Please login to merge, or discard this patch.