@@ -80,8 +80,9 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | self::checkRequirements(); |
| 82 | 82 | |
| 83 | - if (!file_exists($fileName) || !is_readable($fileName)) |
|
| 84 | - throw new Exception('Could not open file: '.$fileName); |
|
| 83 | + if (!file_exists($fileName) || !is_readable($fileName)) { |
|
| 84 | + throw new Exception('Could not open file: '.$fileName); |
|
| 85 | + } |
|
| 85 | 86 | |
| 86 | 87 | $type = self::detectArchiveType($fileName); |
| 87 | 88 | if (!self::canOpenType($type)) { |
@@ -224,8 +225,9 @@ discard block |
||
| 224 | 225 | $this->type = $type; |
| 225 | 226 | $this->archiveSize = filesize($fileName); |
| 226 | 227 | |
| 227 | - if (!isset(static::$formatHandlers[$type])) |
|
| 228 | - throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 228 | + if (!isset(static::$formatHandlers[$type])) { |
|
| 229 | + throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 230 | + } |
|
| 229 | 231 | |
| 230 | 232 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$type]; |
| 231 | 233 | |
@@ -342,8 +344,9 @@ discard block |
||
| 342 | 344 | */ |
| 343 | 345 | public function getFileData($fileName) |
| 344 | 346 | { |
| 345 | - if (!in_array($fileName, $this->files, true)) |
|
| 346 | - return false; |
|
| 347 | + if (!in_array($fileName, $this->files, true)) { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 347 | 350 | |
| 348 | 351 | return $this->archive->getFileData($fileName); |
| 349 | 352 | } |
@@ -358,8 +361,9 @@ discard block |
||
| 358 | 361 | */ |
| 359 | 362 | public function getFileContent($fileName) |
| 360 | 363 | { |
| 361 | - if (!in_array($fileName, $this->files, true)) |
|
| 362 | - return false; |
|
| 364 | + if (!in_array($fileName, $this->files, true)) { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 363 | 367 | |
| 364 | 368 | return $this->archive->getFileContent($fileName); |
| 365 | 369 | } |
@@ -371,8 +375,9 @@ discard block |
||
| 371 | 375 | */ |
| 372 | 376 | public function getFileResource($fileName) |
| 373 | 377 | { |
| 374 | - if (!in_array($fileName, $this->files, true)) |
|
| 375 | - return false; |
|
| 378 | + if (!in_array($fileName, $this->files, true)) { |
|
| 379 | + return false; |
|
| 380 | + } |
|
| 376 | 381 | |
| 377 | 382 | return $this->archive->getFileResource($fileName); |
| 378 | 383 | } |
@@ -388,10 +393,13 @@ discard block |
||
| 388 | 393 | public function extractFiles($outputFolder, $files = null, $expandFilesList = false) |
| 389 | 394 | { |
| 390 | 395 | if ($files !== null) { |
| 391 | - if (is_string($files)) $files = [$files]; |
|
| 396 | + if (is_string($files)) { |
|
| 397 | + $files = [$files]; |
|
| 398 | + } |
|
| 392 | 399 | |
| 393 | - if ($expandFilesList) |
|
| 394 | - $files = self::expandFileList($this->files, $files); |
|
| 400 | + if ($expandFilesList) { |
|
| 401 | + $files = self::expandFileList($this->files, $files); |
|
| 402 | + } |
|
| 395 | 403 | |
| 396 | 404 | return $this->archive->extractFiles($outputFolder, $files); |
| 397 | 405 | } else { |
@@ -412,8 +420,9 @@ discard block |
||
| 412 | 420 | { |
| 413 | 421 | $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles; |
| 414 | 422 | |
| 415 | - if ($expandFilesList && $fileOrFiles !== null) |
|
| 416 | - $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 423 | + if ($expandFilesList && $fileOrFiles !== null) { |
|
| 424 | + $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 425 | + } |
|
| 417 | 426 | |
| 418 | 427 | $result = $this->archive->deleteFiles($fileOrFiles); |
| 419 | 428 | $this->scanArchive(); |
@@ -446,23 +455,27 @@ discard block |
||
| 446 | 455 | */ |
| 447 | 456 | public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false) |
| 448 | 457 | { |
| 449 | - if (file_exists($archiveName)) |
|
| 450 | - throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 458 | + if (file_exists($archiveName)) { |
|
| 459 | + throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 460 | + } |
|
| 451 | 461 | |
| 452 | 462 | self::checkRequirements(); |
| 453 | 463 | |
| 454 | 464 | $archiveType = self::detectArchiveType($archiveName, false); |
| 455 | 465 | // if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true)) |
| 456 | 466 | // return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate); |
| 457 | - if ($archiveType === false) |
|
| 458 | - return false; |
|
| 467 | + if ($archiveType === false) { |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 459 | 470 | |
| 460 | 471 | $files_list = self::createFilesList($fileOrFiles); |
| 461 | 472 | |
| 462 | 473 | // fake creation: return archive data |
| 463 | 474 | if ($emulate) { |
| 464 | 475 | $totalSize = 0; |
| 465 | - foreach ($files_list as $fn) $totalSize += filesize($fn); |
|
| 476 | + foreach ($files_list as $fn) { |
|
| 477 | + $totalSize += filesize($fn); |
|
| 478 | + } |
|
| 466 | 479 | |
| 467 | 480 | return array( |
| 468 | 481 | 'totalSize' => $totalSize, |
@@ -472,8 +485,9 @@ discard block |
||
| 472 | 485 | ); |
| 473 | 486 | } |
| 474 | 487 | |
| 475 | - if (!isset(static::$formatHandlers[$archiveType])) |
|
| 476 | - throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 488 | + if (!isset(static::$formatHandlers[$archiveType])) { |
|
| 489 | + throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 490 | + } |
|
| 477 | 491 | |
| 478 | 492 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$archiveType]; |
| 479 | 493 | |
@@ -539,8 +553,9 @@ discard block |
||
| 539 | 553 | $newFiles = []; |
| 540 | 554 | foreach ($files as $file) { |
| 541 | 555 | foreach ($archiveFiles as $archiveFile) { |
| 542 | - if (fnmatch($file.'*', $archiveFile)) |
|
| 543 | - $newFiles[] = $archiveFile; |
|
| 556 | + if (fnmatch($file.'*', $archiveFile)) { |
|
| 557 | + $newFiles[] = $archiveFile; |
|
| 558 | + } |
|
| 544 | 559 | } |
| 545 | 560 | } |
| 546 | 561 | return $newFiles; |
@@ -557,26 +572,29 @@ discard block |
||
| 557 | 572 | // passed an extended list |
| 558 | 573 | if (is_array($nodes)) { |
| 559 | 574 | foreach ($nodes as $source => $destination) { |
| 560 | - if (is_numeric($source)) |
|
| 561 | - $source = $destination; |
|
| 575 | + if (is_numeric($source)) { |
|
| 576 | + $source = $destination; |
|
| 577 | + } |
|
| 562 | 578 | |
| 563 | 579 | $destination = rtrim($destination, '/\\*'); |
| 564 | 580 | |
| 565 | 581 | // if is directory |
| 566 | - if (is_dir($source)) |
|
| 567 | - self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 582 | + if (is_dir($source)) { |
|
| 583 | + self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 568 | 584 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 569 | - else if (is_file($source)) |
|
| 570 | - $files[$destination] = $source; |
|
| 585 | + } else if (is_file($source)) { |
|
| 586 | + $files[$destination] = $source; |
|
| 587 | + } |
|
| 571 | 588 | } |
| 572 | 589 | |
| 573 | 590 | } else if (is_string($nodes)) { // passed one file or directory |
| 574 | 591 | // if is directory |
| 575 | - if (is_dir($nodes)) |
|
| 576 | - self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 592 | + if (is_dir($nodes)) { |
|
| 593 | + self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 577 | 594 | $files); |
| 578 | - else if (is_file($nodes)) |
|
| 579 | - $files[basename($nodes)] = $nodes; |
|
| 595 | + } else if (is_file($nodes)) { |
|
| 596 | + $files[basename($nodes)] = $nodes; |
|
| 597 | + } |
|
| 580 | 598 | } |
| 581 | 599 | |
| 582 | 600 | return $files; |
@@ -593,8 +611,9 @@ discard block |
||
| 593 | 611 | // $map[$destination] = rtrim($source, '/*'); |
| 594 | 612 | // do not map root archive folder |
| 595 | 613 | |
| 596 | - if ($destination !== null) |
|
| 597 | - $map[$destination] = null; |
|
| 614 | + if ($destination !== null) { |
|
| 615 | + $map[$destination] = null; |
|
| 616 | + } |
|
| 598 | 617 | |
| 599 | 618 | foreach (glob($source, GLOB_MARK) as $node) { |
| 600 | 619 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -613,8 +632,9 @@ discard block |
||
| 613 | 632 | */ |
| 614 | 633 | static public function archiveFile($file, $archiveName) |
| 615 | 634 | { |
| 616 | - if (!is_file($file)) |
|
| 617 | - throw new \InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 635 | + if (!is_file($file)) { |
|
| 636 | + throw new \InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 637 | + } |
|
| 618 | 638 | |
| 619 | 639 | return static::archiveFiles($file, $archiveName) === 1; |
| 620 | 640 | } |
@@ -627,8 +647,9 @@ discard block |
||
| 627 | 647 | */ |
| 628 | 648 | static public function archiveDirectory($directory, $archiveName) |
| 629 | 649 | { |
| 630 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 631 | - throw new \InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 650 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 651 | + throw new \InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 652 | + } |
|
| 632 | 653 | |
| 633 | 654 | return static::archiveFiles($directory, $archiveName) > 0; |
| 634 | 655 | } |
@@ -641,8 +662,9 @@ discard block |
||
| 641 | 662 | */ |
| 642 | 663 | public function addFile($file, $inArchiveName = null) |
| 643 | 664 | { |
| 644 | - if (!is_file($file)) |
|
| 645 | - throw new \InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 665 | + if (!is_file($file)) { |
|
| 666 | + throw new \InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 667 | + } |
|
| 646 | 668 | |
| 647 | 669 | return ($inArchiveName !== null |
| 648 | 670 | ? $this->addFiles([$file => $inArchiveName]) |
@@ -657,8 +679,9 @@ discard block |
||
| 657 | 679 | */ |
| 658 | 680 | public function addDirectory($directory, $inArchivePath = null) |
| 659 | 681 | { |
| 660 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 661 | - throw new \InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 682 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 683 | + throw new \InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 684 | + } |
|
| 662 | 685 | |
| 663 | 686 | return ($inArchivePath !== null |
| 664 | 687 | ? $this->addFiles([$directory => $inArchivePath]) |