Passed
Push — 0.1.x ( e0e8bc...9bc492 )
by f
02:39
created
src/UnifiedArchive.php 1 patch
Braces   +76 added lines, -50 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@  discard block
 block discarded – undo
78 78
     {
79 79
         self::checkRequirements();
80 80
 
81
-        if (!file_exists($fileName) || !is_readable($fileName))
82
-            throw new Exception('Could not open file: '.$fileName);
81
+        if (!file_exists($fileName) || !is_readable($fileName)) {
82
+                    throw new Exception('Could not open file: '.$fileName);
83
+        }
83 84
 
84 85
         $type = self::detectArchiveType($fileName);
85 86
         if (!self::canOpenType($type)) {
@@ -218,8 +219,9 @@  discard block
 block discarded – undo
218 219
         $this->type = $type;
219 220
         $this->archiveSize = filesize($fileName);
220 221
 
221
-        if (!isset(static::$formatHandlers[$type]))
222
-            throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName);
222
+        if (!isset(static::$formatHandlers[$type])) {
223
+                    throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName);
224
+        }
223 225
 
224 226
         $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$type];
225 227
 
@@ -256,8 +258,9 @@  discard block
 block discarded – undo
256 258
      */
257 259
     public function getPclZipInterface()
258 260
     {
259
-        if ($this->type !== self::ZIP)
260
-            throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface');
261
+        if ($this->type !== self::ZIP) {
262
+                    throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface');
263
+        }
261 264
 
262 265
         return new $this->archive->getPclZip();
263 266
     }
@@ -341,8 +344,9 @@  discard block
 block discarded – undo
341 344
      */
342 345
     public function getFileData($fileName)
343 346
     {
344
-        if (!in_array($fileName, $this->files, true))
345
-            return false;
347
+        if (!in_array($fileName, $this->files, true)) {
348
+                    return false;
349
+        }
346 350
 
347 351
         return $this->archive->getFileData($fileName);
348 352
     }
@@ -356,8 +360,9 @@  discard block
 block discarded – undo
356 360
      */
357 361
     public function getFileContent($fileName)
358 362
     {
359
-        if (!in_array($fileName, $this->files, true))
360
-            return false;
363
+        if (!in_array($fileName, $this->files, true)) {
364
+                    return false;
365
+        }
361 366
 
362 367
         return $this->archive->getFileContent($fileName);
363 368
     }
@@ -370,8 +375,9 @@  discard block
 block discarded – undo
370 375
      */
371 376
     public function getFileResource($fileName)
372 377
     {
373
-        if (!in_array($fileName, $this->files, true))
374
-            return false;
378
+        if (!in_array($fileName, $this->files, true)) {
379
+                    return false;
380
+        }
375 381
 
376 382
         return $this->archive->getFileResource($fileName);
377 383
     }
@@ -388,10 +394,13 @@  discard block
 block discarded – undo
388 394
     public function extractFiles($outputFolder, $files = null, $expandFilesList = false)
389 395
     {
390 396
         if ($files !== null) {
391
-            if (is_string($files)) $files = [$files];
397
+            if (is_string($files)) {
398
+             $files = [$files];
399
+            }
392 400
 
393
-            if ($expandFilesList)
394
-                $files = self::expandFileList($this->files, $files);
401
+            if ($expandFilesList) {
402
+                            $files = self::expandFileList($this->files, $files);
403
+            }
395 404
 
396 405
             return $this->archive->extractFiles($outputFolder, $files);
397 406
         } else {
@@ -413,8 +422,9 @@  discard block
 block discarded – undo
413 422
     {
414 423
         $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles;
415 424
 
416
-        if ($expandFilesList && $fileOrFiles !== null)
417
-            $fileOrFiles = self::expandFileList($this->files, $fileOrFiles);
425
+        if ($expandFilesList && $fileOrFiles !== null) {
426
+                    $fileOrFiles = self::expandFileList($this->files, $fileOrFiles);
427
+        }
418 428
 
419 429
         $result = $this->archive->deleteFiles($fileOrFiles);
420 430
         $this->scanArchive();
@@ -431,8 +441,9 @@  discard block
 block discarded – undo
431 441
     public function addFiles($fileOrFiles)
432 442
     {
433 443
         $files_list = self::createFilesList($fileOrFiles);
434
-        if (empty($files_list))
435
-            throw new InvalidArgumentException('Files list is empty!');
444
+        if (empty($files_list)) {
445
+                    throw new InvalidArgumentException('Files list is empty!');
446
+        }
436 447
         $result = $this->archive->addFiles($files_list);
437 448
         $this->scanArchive();
438 449
         return $result;
@@ -448,8 +459,9 @@  discard block
 block discarded – undo
448 459
      */
449 460
     public function addFile($file, $inArchiveName = null)
450 461
     {
451
-        if (!is_file($file))
452
-            throw new InvalidArgumentException($file.' is not a valid file to add in archive');
462
+        if (!is_file($file)) {
463
+                    throw new InvalidArgumentException($file.' is not a valid file to add in archive');
464
+        }
453 465
 
454 466
         return ($inArchiveName !== null
455 467
                 ? $this->addFiles([$file => $inArchiveName])
@@ -466,8 +478,9 @@  discard block
 block discarded – undo
466 478
      */
467 479
     public function addDirectory($directory, $inArchivePath = null)
468 480
     {
469
-        if (!is_dir($directory) || !is_readable($directory))
470
-            throw new InvalidArgumentException($directory.' is not a valid directory to add in archive');
481
+        if (!is_dir($directory) || !is_readable($directory)) {
482
+                    throw new InvalidArgumentException($directory.' is not a valid directory to add in archive');
483
+        }
471 484
 
472 485
         return ($inArchivePath !== null
473 486
                 ? $this->addFiles([$directory => $inArchivePath])
@@ -503,25 +516,30 @@  discard block
 block discarded – undo
503 516
      */
504 517
     public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false)
505 518
     {
506
-        if (file_exists($archiveName))
507
-            throw new Exception('Archive '.$archiveName.' already exists!');
519
+        if (file_exists($archiveName)) {
520
+                    throw new Exception('Archive '.$archiveName.' already exists!');
521
+        }
508 522
 
509 523
         self::checkRequirements();
510 524
 
511 525
         $archiveType = self::detectArchiveType($archiveName, false);
512 526
         //        if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true))
513 527
         //            return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate);
514
-        if ($archiveType === false)
515
-            return false;
528
+        if ($archiveType === false) {
529
+                    return false;
530
+        }
516 531
 
517 532
         $files_list = self::createFilesList($fileOrFiles);
518
-        if (empty($files_list))
519
-            throw new InvalidArgumentException('Files list is empty!');
533
+        if (empty($files_list)) {
534
+                    throw new InvalidArgumentException('Files list is empty!');
535
+        }
520 536
 
521 537
         // fake creation: return archive data
522 538
         if ($emulate) {
523 539
             $totalSize = 0;
524
-            foreach ($files_list as $fn) $totalSize += filesize($fn);
540
+            foreach ($files_list as $fn) {
541
+             $totalSize += filesize($fn);
542
+            }
525 543
 
526 544
             return array(
527 545
                 'totalSize' => $totalSize,
@@ -531,8 +549,9 @@  discard block
 block discarded – undo
531 549
             );
532 550
         }
533 551
 
534
-        if (!isset(static::$formatHandlers[$archiveType]))
535
-            throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName);
552
+        if (!isset(static::$formatHandlers[$archiveType])) {
553
+                    throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName);
554
+        }
536 555
 
537 556
         $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$archiveType];
538 557
 
@@ -549,8 +568,9 @@  discard block
 block discarded – undo
549 568
      */
550 569
     public static function archiveFile($file, $archiveName)
551 570
     {
552
-        if (!is_file($file))
553
-            throw new InvalidArgumentException($file.' is not a valid file to archive');
571
+        if (!is_file($file)) {
572
+                    throw new InvalidArgumentException($file.' is not a valid file to archive');
573
+        }
554 574
 
555 575
         return static::archiveFiles($file, $archiveName) === 1;
556 576
     }
@@ -565,8 +585,9 @@  discard block
 block discarded – undo
565 585
      */
566 586
     public static function archiveDirectory($directory, $archiveName)
567 587
     {
568
-        if (!is_dir($directory) || !is_readable($directory))
569
-            throw new InvalidArgumentException($directory.' is not a valid directory to archive');
588
+        if (!is_dir($directory) || !is_readable($directory)) {
589
+                    throw new InvalidArgumentException($directory.' is not a valid directory to archive');
590
+        }
570 591
 
571 592
         return static::archiveFiles($directory, $archiveName) > 0;
572 593
     }
@@ -635,8 +656,9 @@  discard block
 block discarded – undo
635 656
         $newFiles = [];
636 657
         foreach ($files as $file) {
637 658
             foreach ($archiveFiles as $archiveFile) {
638
-                if (fnmatch($file.'*', $archiveFile))
639
-                    $newFiles[] = $archiveFile;
659
+                if (fnmatch($file.'*', $archiveFile)) {
660
+                                    $newFiles[] = $archiveFile;
661
+                }
640 662
             }
641 663
         }
642 664
         return $newFiles;
@@ -653,26 +675,29 @@  discard block
 block discarded – undo
653 675
         // passed an extended list
654 676
         if (is_array($nodes)) {
655 677
             foreach ($nodes as $source => $destination) {
656
-                if (is_numeric($source))
657
-                    $source = $destination;
678
+                if (is_numeric($source)) {
679
+                                    $source = $destination;
680
+                }
658 681
 
659 682
                 $destination = rtrim($destination, '/\\*');
660 683
 
661 684
                 // if is directory
662
-                if (is_dir($source))
663
-                    self::importFilesFromDir(rtrim($source, '/\\*').'/*',
685
+                if (is_dir($source)) {
686
+                                    self::importFilesFromDir(rtrim($source, '/\\*').'/*',
664 687
                         !empty($destination) ? $destination.'/' : null, true, $files);
665
-                else if (is_file($source))
666
-                    $files[$destination] = $source;
688
+                } else if (is_file($source)) {
689
+                                    $files[$destination] = $source;
690
+                }
667 691
             }
668 692
 
669 693
         } else if (is_string($nodes)) { // passed one file or directory
670 694
             // if is directory
671
-            if (is_dir($nodes))
672
-                self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true,
695
+            if (is_dir($nodes)) {
696
+                            self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true,
673 697
                     $files);
674
-            else if (is_file($nodes))
675
-                $files[basename($nodes)] = $nodes;
698
+            } else if (is_file($nodes)) {
699
+                            $files[basename($nodes)] = $nodes;
700
+            }
676 701
         }
677 702
 
678 703
         return $files;
@@ -689,8 +714,9 @@  discard block
 block discarded – undo
689 714
         // $map[$destination] = rtrim($source, '/*');
690 715
         // do not map root archive folder
691 716
 
692
-        if ($destination !== null)
693
-            $map[$destination] = null;
717
+        if ($destination !== null) {
718
+                    $map[$destination] = null;
719
+        }
694 720
 
695 721
         foreach (glob($source, GLOB_MARK) as $node) {
696 722
             if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) {
Please login to merge, or discard this patch.