Passed
Push — 0.1.x ( 9bc492...223229 )
by f
02:59
created
src/UnifiedArchive.php 1 patch
Braces   +76 added lines, -50 removed lines patch added patch discarded remove patch
@@ -87,8 +87,9 @@  discard block
 block discarded – undo
87 87
     {
88 88
         self::checkRequirements();
89 89
 
90
-        if (!file_exists($fileName) || !is_readable($fileName))
91
-            throw new Exception('Could not open file: '.$fileName);
90
+        if (!file_exists($fileName) || !is_readable($fileName)) {
91
+                    throw new Exception('Could not open file: '.$fileName);
92
+        }
92 93
 
93 94
         $type = self::detectArchiveType($fileName);
94 95
         if (!self::canOpenType($type)) {
@@ -227,8 +228,9 @@  discard block
 block discarded – undo
227 228
         $this->type = $type;
228 229
         $this->archiveSize = filesize($fileName);
229 230
 
230
-        if (!isset(static::$formatHandlers[$type]))
231
-            throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName);
231
+        if (!isset(static::$formatHandlers[$type])) {
232
+                    throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName);
233
+        }
232 234
 
233 235
         $handler_class = static::$formatHandlers[$type];
234 236
 
@@ -265,8 +267,9 @@  discard block
 block discarded – undo
265 267
      */
266 268
     public function getPclZipInterface()
267 269
     {
268
-        if ($this->type !== self::ZIP)
269
-            throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface');
270
+        if ($this->type !== self::ZIP) {
271
+                    throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface');
272
+        }
270 273
 
271 274
         return new $this->archive->getPclZip();
272 275
     }
@@ -350,8 +353,9 @@  discard block
 block discarded – undo
350 353
      */
351 354
     public function getFileData($fileName)
352 355
     {
353
-        if (!in_array($fileName, $this->files, true))
354
-            return false;
356
+        if (!in_array($fileName, $this->files, true)) {
357
+                    return false;
358
+        }
355 359
 
356 360
         return $this->archive->getFileData($fileName);
357 361
     }
@@ -365,8 +369,9 @@  discard block
 block discarded – undo
365 369
      */
366 370
     public function getFileContent($fileName)
367 371
     {
368
-        if (!in_array($fileName, $this->files, true))
369
-            return false;
372
+        if (!in_array($fileName, $this->files, true)) {
373
+                    return false;
374
+        }
370 375
 
371 376
         return $this->archive->getFileContent($fileName);
372 377
     }
@@ -379,8 +384,9 @@  discard block
 block discarded – undo
379 384
      */
380 385
     public function getFileResource($fileName)
381 386
     {
382
-        if (!in_array($fileName, $this->files, true))
383
-            return false;
387
+        if (!in_array($fileName, $this->files, true)) {
388
+                    return false;
389
+        }
384 390
 
385 391
         return $this->archive->getFileResource($fileName);
386 392
     }
@@ -397,10 +403,13 @@  discard block
 block discarded – undo
397 403
     public function extractFiles($outputFolder, $files = null, $expandFilesList = false)
398 404
     {
399 405
         if ($files !== null) {
400
-            if (is_string($files)) $files = [$files];
406
+            if (is_string($files)) {
407
+             $files = [$files];
408
+            }
401 409
 
402
-            if ($expandFilesList)
403
-                $files = self::expandFileList($this->files, $files);
410
+            if ($expandFilesList) {
411
+                            $files = self::expandFileList($this->files, $files);
412
+            }
404 413
 
405 414
             return $this->archive->extractFiles($outputFolder, $files);
406 415
         } else {
@@ -422,8 +431,9 @@  discard block
 block discarded – undo
422 431
     {
423 432
         $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles;
424 433
 
425
-        if ($expandFilesList && $fileOrFiles !== null)
426
-            $fileOrFiles = self::expandFileList($this->files, $fileOrFiles);
434
+        if ($expandFilesList && $fileOrFiles !== null) {
435
+                    $fileOrFiles = self::expandFileList($this->files, $fileOrFiles);
436
+        }
427 437
 
428 438
         $result = $this->archive->deleteFiles($fileOrFiles);
429 439
         $this->scanArchive();
@@ -440,8 +450,9 @@  discard block
 block discarded – undo
440 450
     public function addFiles($fileOrFiles)
441 451
     {
442 452
         $files_list = self::createFilesList($fileOrFiles);
443
-        if (empty($files_list))
444
-            throw new InvalidArgumentException('Files list is empty!');
453
+        if (empty($files_list)) {
454
+                    throw new InvalidArgumentException('Files list is empty!');
455
+        }
445 456
         $result = $this->archive->addFiles($files_list);
446 457
         $this->scanArchive();
447 458
         return $result;
@@ -457,8 +468,9 @@  discard block
 block discarded – undo
457 468
      */
458 469
     public function addFile($file, $inArchiveName = null)
459 470
     {
460
-        if (!is_file($file))
461
-            throw new InvalidArgumentException($file.' is not a valid file to add in archive');
471
+        if (!is_file($file)) {
472
+                    throw new InvalidArgumentException($file.' is not a valid file to add in archive');
473
+        }
462 474
 
463 475
         return ($inArchiveName !== null
464 476
                 ? $this->addFiles([$file => $inArchiveName])
@@ -475,8 +487,9 @@  discard block
 block discarded – undo
475 487
      */
476 488
     public function addDirectory($directory, $inArchivePath = null)
477 489
     {
478
-        if (!is_dir($directory) || !is_readable($directory))
479
-            throw new InvalidArgumentException($directory.' is not a valid directory to add in archive');
490
+        if (!is_dir($directory) || !is_readable($directory)) {
491
+                    throw new InvalidArgumentException($directory.' is not a valid directory to add in archive');
492
+        }
480 493
 
481 494
         return ($inArchivePath !== null
482 495
                 ? $this->addFiles([$directory => $inArchivePath])
@@ -512,25 +525,30 @@  discard block
 block discarded – undo
512 525
      */
513 526
     public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false)
514 527
     {
515
-        if (file_exists($archiveName))
516
-            throw new Exception('Archive '.$archiveName.' already exists!');
528
+        if (file_exists($archiveName)) {
529
+                    throw new Exception('Archive '.$archiveName.' already exists!');
530
+        }
517 531
 
518 532
         self::checkRequirements();
519 533
 
520 534
         $archiveType = self::detectArchiveType($archiveName, false);
521 535
         //        if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true))
522 536
         //            return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate);
523
-        if ($archiveType === false)
524
-            return false;
537
+        if ($archiveType === false) {
538
+                    return false;
539
+        }
525 540
 
526 541
         $files_list = self::createFilesList($fileOrFiles);
527
-        if (empty($files_list))
528
-            throw new InvalidArgumentException('Files list is empty!');
542
+        if (empty($files_list)) {
543
+                    throw new InvalidArgumentException('Files list is empty!');
544
+        }
529 545
 
530 546
         // fake creation: return archive data
531 547
         if ($emulate) {
532 548
             $totalSize = 0;
533
-            foreach ($files_list as $fn) $totalSize += filesize($fn);
549
+            foreach ($files_list as $fn) {
550
+             $totalSize += filesize($fn);
551
+            }
534 552
 
535 553
             return array(
536 554
                 'totalSize' => $totalSize,
@@ -540,8 +558,9 @@  discard block
 block discarded – undo
540 558
             );
541 559
         }
542 560
 
543
-        if (!isset(static::$formatHandlers[$archiveType]))
544
-            throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName);
561
+        if (!isset(static::$formatHandlers[$archiveType])) {
562
+                    throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName);
563
+        }
545 564
 
546 565
         $handler_class = static::$formatHandlers[$archiveType];
547 566
 
@@ -558,8 +577,9 @@  discard block
 block discarded – undo
558 577
      */
559 578
     public static function archiveFile($file, $archiveName)
560 579
     {
561
-        if (!is_file($file))
562
-            throw new InvalidArgumentException($file.' is not a valid file to archive');
580
+        if (!is_file($file)) {
581
+                    throw new InvalidArgumentException($file.' is not a valid file to archive');
582
+        }
563 583
 
564 584
         return static::archiveFiles($file, $archiveName) === 1;
565 585
     }
@@ -574,8 +594,9 @@  discard block
 block discarded – undo
574 594
      */
575 595
     public static function archiveDirectory($directory, $archiveName)
576 596
     {
577
-        if (!is_dir($directory) || !is_readable($directory))
578
-            throw new InvalidArgumentException($directory.' is not a valid directory to archive');
597
+        if (!is_dir($directory) || !is_readable($directory)) {
598
+                    throw new InvalidArgumentException($directory.' is not a valid directory to archive');
599
+        }
579 600
 
580 601
         return static::archiveFiles($directory, $archiveName) > 0;
581 602
     }
@@ -644,8 +665,9 @@  discard block
 block discarded – undo
644 665
         $newFiles = [];
645 666
         foreach ($files as $file) {
646 667
             foreach ($archiveFiles as $archiveFile) {
647
-                if (fnmatch($file.'*', $archiveFile))
648
-                    $newFiles[] = $archiveFile;
668
+                if (fnmatch($file.'*', $archiveFile)) {
669
+                                    $newFiles[] = $archiveFile;
670
+                }
649 671
             }
650 672
         }
651 673
         return $newFiles;
@@ -662,26 +684,29 @@  discard block
 block discarded – undo
662 684
         // passed an extended list
663 685
         if (is_array($nodes)) {
664 686
             foreach ($nodes as $source => $destination) {
665
-                if (is_numeric($source))
666
-                    $source = $destination;
687
+                if (is_numeric($source)) {
688
+                                    $source = $destination;
689
+                }
667 690
 
668 691
                 $destination = rtrim($destination, '/\\*');
669 692
 
670 693
                 // if is directory
671
-                if (is_dir($source))
672
-                    self::importFilesFromDir(rtrim($source, '/\\*').'/*',
694
+                if (is_dir($source)) {
695
+                                    self::importFilesFromDir(rtrim($source, '/\\*').'/*',
673 696
                         !empty($destination) ? $destination.'/' : null, true, $files);
674
-                else if (is_file($source))
675
-                    $files[$destination] = $source;
697
+                } else if (is_file($source)) {
698
+                                    $files[$destination] = $source;
699
+                }
676 700
             }
677 701
 
678 702
         } else if (is_string($nodes)) { // passed one file or directory
679 703
             // if is directory
680
-            if (is_dir($nodes))
681
-                self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true,
704
+            if (is_dir($nodes)) {
705
+                            self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true,
682 706
                     $files);
683
-            else if (is_file($nodes))
684
-                $files[basename($nodes)] = $nodes;
707
+            } else if (is_file($nodes)) {
708
+                            $files[basename($nodes)] = $nodes;
709
+            }
685 710
         }
686 711
 
687 712
         return $files;
@@ -698,8 +723,9 @@  discard block
 block discarded – undo
698 723
         // $map[$destination] = rtrim($source, '/*');
699 724
         // do not map root archive folder
700 725
 
701
-        if ($destination !== null)
702
-            $map[$destination] = null;
726
+        if ($destination !== null) {
727
+                    $map[$destination] = null;
728
+        }
703 729
 
704 730
         foreach (glob($source, GLOB_MARK) as $node) {
705 731
             if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) {
Please login to merge, or discard this patch.