Passed
Push — master ( 3078fb...b176c5 )
by Darío
01:52
created
src/FileSystem/Shell.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -94,20 +94,20 @@  discard block
 block discarded – undo
94 94
             {
95 95
                 foreach ($contents as $i)
96 96
                 {
97
-                    if (is_file($directory.'/'.$i))
97
+                    if (is_file($directory . '/' . $i))
98 98
                     {
99
-                        $allContents[] = $directory.'/'.$i;
99
+                        $allContents[] = $directory . '/' . $i;
100 100
 
101
-                        $this->buffer = $directory.'/'.$i;
101
+                        $this->buffer = $directory . '/' . $i;
102 102
                         call_user_func($fileCallback, $this);
103 103
                     }
104
-                    elseif (is_dir($directory.'/'.$i))
104
+                    elseif (is_dir($directory . '/' . $i))
105 105
                     {
106
-                        $allContents[] = $directory.'/'.$i;
106
+                        $allContents[] = $directory . '/' . $i;
107 107
 
108
-                        $this->getContents($directory.'/'.$i, $fileCallback, $dirCallback);
108
+                        $this->getContents($directory . '/' . $i, $fileCallback, $dirCallback);
109 109
 
110
-                        $this->buffer = $directory.'/'.$i;
110
+                        $this->buffer = $directory . '/' . $i;
111 111
                         call_user_func($dirCallback, $this);
112 112
                     }
113 113
                 }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                 if (!empty($path))
203 203
                     if (!strlen(stristr($item, $path)) > 0)
204 204
                         continue;
205
-                if (strstr($item,'~') === false && $item != '.' && $item != '..')
205
+                if (strstr($item, '~') === false && $item != '.' && $item != '..')
206 206
                     $filesToReturn[] = $item;
207 207
             }
208 208
         }
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
                     {
340 340
                         foreach ($files["folders"] as $folder)
341 341
                         {
342
-                            if (!file_exists($dest.'/'.$folder))
342
+                            if (!file_exists($dest . '/' . $folder))
343 343
                                 mkdir("$dest/$folder", 0777, true);
344 344
                         }
345 345
                     }
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
                         foreach ($files["files"] as $item)
350 350
                         {
351 351
                             if (!file_exists("$dest/$files"))
352
-                                copy($item, $dest.'/'.$item);
352
+                                copy($item, $dest . '/' . $item);
353 353
                         }
354 354
                     }
355 355
                 }
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
         if (is_dir($dest))
360 360
         {
361 361
             if (!$recursive)
362
-                copy($file, $dest.'/'.$file);
362
+                copy($file, $dest . '/' . $file);
363 363
             else {
364 364
 
365 365
                 $files = array();
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 
379 379
                     foreach ($files[1] as $item)
380 380
                     {
381
-                        if (!file_exists($dest.'/'.$item))
381
+                        if (!file_exists($dest . '/' . $item))
382 382
                             mkdir("$dest/$item", 0777, true);
383 383
                     }
384 384
 
385 385
                     foreach ($files[0] as $item)
386 386
                     {
387 387
                         if (!file_exists("$dest/$files"))
388
-                            copy($item, $dest.'/'.$item);
388
+                            copy($item, $dest . '/' . $item);
389 389
                     }
390 390
                 });
391 391
             }
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
             throw new \InvalidArgumentException("Missing first parameter");
411 411
 
412 412
         if (is_dir($newfile))
413
-                $newfile .= '/'.basename($oldfile);
413
+                $newfile .= '/' . basename($oldfile);
414 414
 
415 415
         if ($oldfile == $newfile)
416 416
             throw new \Exception("'$oldfile' and '$newfile' are the same file");
417 417
 
418
-        if(!rename($oldfile, $newfile))
418
+        if (!rename($oldfile, $newfile))
419 419
             return false;
420 420
 
421 421
         return true;
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
         else {
446 446
             if (!is_dir($dir))
447 447
             {
448
-                if(!mkdir("$dir", 0777))
448
+                if (!mkdir("$dir", 0777))
449 449
                     return false;
450 450
             }
451 451
         }
Please login to merge, or discard this patch.
Braces   +106 added lines, -82 removed lines patch added patch discarded remove patch
@@ -84,8 +84,9 @@  discard block
 block discarded – undo
84 84
         {
85 85
             foreach ($this->ls($directory) as $item)
86 86
             {
87
-                if ($item != '.' && $item != '..')
88
-                    $contents[] = $item;
87
+                if ($item != '.' && $item != '..') {
88
+                                    $contents[] = $item;
89
+                }
89 90
             }
90 91
 
91 92
             $allContents = $contents;
@@ -100,8 +101,7 @@  discard block
 block discarded – undo
100 101
 
101 102
                         $this->buffer = $directory.'/'.$i;
102 103
                         call_user_func($fileCallback, $this);
103
-                    }
104
-                    elseif (is_dir($directory.'/'.$i))
104
+                    } elseif (is_dir($directory.'/'.$i))
105 105
                     {
106 106
                         $allContents[] = $directory.'/'.$i;
107 107
 
@@ -112,14 +112,15 @@  discard block
 block discarded – undo
112 112
                     }
113 113
                 }
114 114
             }
115
+        } else if (is_file($directory)) {
116
+                    throw new \InvalidArgumentException("'$directory' is actually a file");
117
+        } else {
118
+                    throw new \InvalidArgumentException("The directory '$directory' does not exists");
115 119
         }
116
-        else if (is_file($directory))
117
-            throw new \InvalidArgumentException("'$directory' is actually a file");
118
-        else
119
-            throw new \InvalidArgumentException("The directory '$directory' does not exists");
120 120
 
121
-        if (!is_null($callback))
122
-            call_user_func($callback, $this);
121
+        if (!is_null($callback)) {
122
+                    call_user_func($callback, $this);
123
+        }
123 124
 
124 125
         return $allContents;
125 126
     }
@@ -131,10 +132,11 @@  discard block
 block discarded – undo
131 132
      */
132 133
     public function pwd()
133 134
     {
134
-        if (getcwd())
135
-            $this->buffer = getcwd();
136
-        else
137
-            return false;
135
+        if (getcwd()) {
136
+                    $this->buffer = getcwd();
137
+        } else {
138
+                    return false;
139
+        }
138 140
 
139 141
         return $this->buffer;
140 142
     }
@@ -153,9 +155,9 @@  discard block
 block discarded – undo
153 155
 
154 156
         $path = (is_null($path) || empty($path)) ? '.' : $path;
155 157
 
156
-        if (is_file($path))
157
-            $filesToReturn = array($path);
158
-        else if (is_dir($path))
158
+        if (is_file($path)) {
159
+                    $filesToReturn = array($path);
160
+        } else if (is_dir($path))
159 161
         {
160 162
             $pathIns = dir($path);
161 163
 
@@ -176,34 +178,37 @@  discard block
 block discarded – undo
176 178
                     }
177 179
                 );
178 180
 
179
-                foreach ($dirs as $item)
180
-                    $filesToReturn[] = $item;
181
+                foreach ($dirs as $item) {
182
+                                    $filesToReturn[] = $item;
183
+                }
181 184
 
182
-                foreach ($files as $item)
183
-                    $filesToReturn[] = $item;
184
-            }
185
-            else
185
+                foreach ($files as $item) {
186
+                                    $filesToReturn[] = $item;
187
+                }
188
+            } else
186 189
             {
187 190
                 while (($item = $pathIns->read()) !== false)
188 191
                 {
189
-                    if ($item != '.' && $item != '..')
190
-                        $filesToReturn[] = $item;
192
+                    if ($item != '.' && $item != '..') {
193
+                                            $filesToReturn[] = $item;
194
+                    }
191 195
                 }
192 196
 
193 197
                 $pathIns->close();
194 198
             }
195
-        }
196
-        else {
199
+        } else {
197 200
 
198 201
             $contents = $this->ls();
199 202
 
200 203
             foreach ($contents as $item)
201 204
             {
202
-                if (!empty($path))
203
-                    if (!strlen(stristr($item, $path)) > 0)
205
+                if (!empty($path)) {
206
+                                    if (!strlen(stristr($item, $path)) > 0)
204 207
                         continue;
205
-                if (strstr($item,'~') === false && $item != '.' && $item != '..')
206
-                    $filesToReturn[] = $item;
208
+                }
209
+                if (strstr($item,'~') === false && $item != '.' && $item != '..') {
210
+                                    $filesToReturn[] = $item;
211
+                }
207 212
             }
208 213
         }
209 214
 
@@ -223,8 +228,9 @@  discard block
 block discarded – undo
223 228
 
224 229
         if (is_dir($path))
225 230
         {
226
-            if (chdir($path))
227
-                return true;
231
+            if (chdir($path)) {
232
+                            return true;
233
+            }
228 234
         }
229 235
 
230 236
         return false;
@@ -266,12 +272,13 @@  discard block
 block discarded – undo
266 272
     {
267 273
         $recursive = is_null($recursive) ? false : $recursive;
268 274
 
269
-        if (is_null($file))
270
-            throw new \InvalidArgumentException("Missing first parameter");
275
+        if (is_null($file)) {
276
+                    throw new \InvalidArgumentException("Missing first parameter");
277
+        }
271 278
 
272
-        if (file_exists($file) && !$recursive)
273
-            unlink($file);
274
-        elseif (is_dir($file) && $recursive)
279
+        if (file_exists($file) && !$recursive) {
280
+                    unlink($file);
281
+        } elseif (is_dir($file) && $recursive)
275 282
         {
276 283
             $that = $this;
277 284
 
@@ -300,11 +307,13 @@  discard block
 block discarded – undo
300 307
     {
301 308
         $recursive = (is_null($recursive)) ? false : $recursive;
302 309
 
303
-        if (empty($file) || empty($dest))
304
-            throw new \InvalidArgumentException("Missing parameters");
310
+        if (empty($file) || empty($dest)) {
311
+                    throw new \InvalidArgumentException("Missing parameters");
312
+        }
305 313
 
306
-        if (is_dir($file) && !$recursive)
307
-            throw new \RuntimeException("Ommiting directory <<$foo>>");
314
+        if (is_dir($file) && !$recursive) {
315
+                    throw new \RuntimeException("Ommiting directory <<$foo>>");
316
+        }
308 317
 
309 318
         if (is_dir($file) && (is_dir($dest) || !file_exists($dest)))
310 319
         {
@@ -313,11 +322,13 @@  discard block
 block discarded – undo
313 322
                 "folders" => []
314 323
             ];
315 324
 
316
-            if (is_dir($dest))
317
-                $files["folders"][] = basename($file);
325
+            if (is_dir($dest)) {
326
+                            $files["folders"][] = basename($file);
327
+            }
318 328
 
319
-            if (!file_exists($dest))
320
-                mkdir($dest);
329
+            if (!file_exists($dest)) {
330
+                            mkdir($dest);
331
+            }
321 332
 
322 333
             $that = $this;
323 334
 
@@ -339,8 +350,9 @@  discard block
 block discarded – undo
339 350
                     {
340 351
                         foreach ($files["folders"] as $folder)
341 352
                         {
342
-                            if (!file_exists($dest.'/'.$folder))
343
-                                mkdir("$dest/$folder", 0777, true);
353
+                            if (!file_exists($dest.'/'.$folder)) {
354
+                                                            mkdir("$dest/$folder", 0777, true);
355
+                            }
344 356
                         }
345 357
                     }
346 358
 
@@ -348,8 +360,9 @@  discard block
 block discarded – undo
348 360
                     {
349 361
                         foreach ($files["files"] as $item)
350 362
                         {
351
-                            if (!file_exists("$dest/$files"))
352
-                                copy($item, $dest.'/'.$item);
363
+                            if (!file_exists("$dest/$files")) {
364
+                                                            copy($item, $dest.'/'.$item);
365
+                            }
353 366
                         }
354 367
                     }
355 368
                 }
@@ -358,9 +371,9 @@  discard block
 block discarded – undo
358 371
 
359 372
         if (is_dir($dest))
360 373
         {
361
-            if (!$recursive)
362
-                copy($file, $dest.'/'.$file);
363
-            else {
374
+            if (!$recursive) {
375
+                            copy($file, $dest.'/'.$file);
376
+            } else {
364 377
 
365 378
                 $files = array();
366 379
                 $files[0] = array();
@@ -378,20 +391,22 @@  discard block
 block discarded – undo
378 391
 
379 392
                     foreach ($files[1] as $item)
380 393
                     {
381
-                        if (!file_exists($dest.'/'.$item))
382
-                            mkdir("$dest/$item", 0777, true);
394
+                        if (!file_exists($dest.'/'.$item)) {
395
+                                                    mkdir("$dest/$item", 0777, true);
396
+                        }
383 397
                     }
384 398
 
385 399
                     foreach ($files[0] as $item)
386 400
                     {
387
-                        if (!file_exists("$dest/$files"))
388
-                            copy($item, $dest.'/'.$item);
401
+                        if (!file_exists("$dest/$files")) {
402
+                                                    copy($item, $dest.'/'.$item);
403
+                        }
389 404
                     }
390 405
                 });
391 406
             }
407
+        } else {
408
+                    copy($file, $dest);
392 409
         }
393
-        else
394
-            copy($file, $dest);
395 410
 
396 411
         return true;
397 412
     }
@@ -406,17 +421,21 @@  discard block
 block discarded – undo
406 421
      */
407 422
     public function mv($oldfile, $newfile)
408 423
     {
409
-        if (empty($oldfile))
410
-            throw new \InvalidArgumentException("Missing first parameter");
424
+        if (empty($oldfile)) {
425
+                    throw new \InvalidArgumentException("Missing first parameter");
426
+        }
411 427
 
412
-        if (is_dir($newfile))
413
-                $newfile .= '/'.basename($oldfile);
428
+        if (is_dir($newfile)) {
429
+                        $newfile .= '/'.basename($oldfile);
430
+        }
414 431
 
415
-        if ($oldfile == $newfile)
416
-            throw new \Exception("'$oldfile' and '$newfile' are the same file");
432
+        if ($oldfile == $newfile) {
433
+                    throw new \Exception("'$oldfile' and '$newfile' are the same file");
434
+        }
417 435
 
418
-        if(!rename($oldfile, $newfile))
419
-            return false;
436
+        if(!rename($oldfile, $newfile)) {
437
+                    return false;
438
+        }
420 439
 
421 440
         return true;
422 441
     }
@@ -432,21 +451,24 @@  discard block
 block discarded – undo
432 451
      */
433 452
     public function mkdir($dir, $dest = null, $recursive = null)
434 453
     {
435
-        if (empty($dir))
436
-            throw new \InvalidArgumentException("Missing first parameter");
454
+        if (empty($dir)) {
455
+                    throw new \InvalidArgumentException("Missing first parameter");
456
+        }
437 457
 
438
-        if (empty($dest))
439
-            $dest = '.';
458
+        if (empty($dest)) {
459
+                    $dest = '.';
460
+        }
440 461
 
441 462
         $recursive = (is_null($recursive)) ? false : $recursive;
442 463
 
443
-        if ($recursive)
444
-            mkdir("$dest/$dir", 0777, true);
445
-        else {
464
+        if ($recursive) {
465
+                    mkdir("$dest/$dir", 0777, true);
466
+        } else {
446 467
             if (!is_dir($dir))
447 468
             {
448
-                if(!mkdir("$dir", 0777))
449
-                    return false;
469
+                if(!mkdir("$dir", 0777)) {
470
+                                    return false;
471
+                }
450 472
             }
451 473
         }
452 474
         return true;
@@ -461,12 +483,14 @@  discard block
 block discarded – undo
461 483
      */
462 484
     public function rmdir($dir)
463 485
     {
464
-        if (is_null($dir) || empty($dir))
465
-            throw new \RuntimeException("Missing first parameter");
486
+        if (is_null($dir) || empty($dir)) {
487
+                    throw new \RuntimeException("Missing first parameter");
488
+        }
466 489
 
467
-        if (rmdir($dir))
468
-            return true;
469
-        else
470
-            return false;
490
+        if (rmdir($dir)) {
491
+                    return true;
492
+        } else {
493
+                    return false;
494
+        }
471 495
     }
472 496
 }
473 497
\ No newline at end of file
Please login to merge, or discard this patch.