@@ -87,8 +87,9 @@ discard block |
||
| 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)) { |
@@ -239,8 +240,9 @@ discard block |
||
| 239 | 240 | $this->type = $type; |
| 240 | 241 | $this->archiveSize = filesize($fileName); |
| 241 | 242 | |
| 242 | - if (!isset(static::$formatHandlers[$type])) |
|
| 243 | - throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 243 | + if (!isset(static::$formatHandlers[$type])) { |
|
| 244 | + throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 245 | + } |
|
| 244 | 246 | |
| 245 | 247 | $handler_class = static::$formatHandlers[$type]; |
| 246 | 248 | |
@@ -277,8 +279,9 @@ discard block |
||
| 277 | 279 | */ |
| 278 | 280 | public function getPclZipInterface() |
| 279 | 281 | { |
| 280 | - if ($this->type !== self::ZIP) |
|
| 281 | - throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface'); |
|
| 282 | + if ($this->type !== self::ZIP) { |
|
| 283 | + throw new UnsupportedOperationException('Format '.$this->type.' does not support PclZip-interface'); |
|
| 284 | + } |
|
| 282 | 285 | |
| 283 | 286 | return $this->archive->getPclZip(); |
| 284 | 287 | } |
@@ -362,8 +365,9 @@ discard block |
||
| 362 | 365 | */ |
| 363 | 366 | public function getFileData($fileName) |
| 364 | 367 | { |
| 365 | - if (!in_array($fileName, $this->files, true)) |
|
| 366 | - return false; |
|
| 368 | + if (!in_array($fileName, $this->files, true)) { |
|
| 369 | + return false; |
|
| 370 | + } |
|
| 367 | 371 | |
| 368 | 372 | return $this->archive->getFileData($fileName); |
| 369 | 373 | } |
@@ -377,8 +381,9 @@ discard block |
||
| 377 | 381 | */ |
| 378 | 382 | public function getFileContent($fileName) |
| 379 | 383 | { |
| 380 | - if (!in_array($fileName, $this->files, true)) |
|
| 381 | - return false; |
|
| 384 | + if (!in_array($fileName, $this->files, true)) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 382 | 387 | |
| 383 | 388 | return $this->archive->getFileContent($fileName); |
| 384 | 389 | } |
@@ -391,8 +396,9 @@ discard block |
||
| 391 | 396 | */ |
| 392 | 397 | public function getFileResource($fileName) |
| 393 | 398 | { |
| 394 | - if (!in_array($fileName, $this->files, true)) |
|
| 395 | - return false; |
|
| 399 | + if (!in_array($fileName, $this->files, true)) { |
|
| 400 | + return false; |
|
| 401 | + } |
|
| 396 | 402 | |
| 397 | 403 | return $this->archive->getFileResource($fileName); |
| 398 | 404 | } |
@@ -409,10 +415,13 @@ discard block |
||
| 409 | 415 | public function extractFiles($outputFolder, $files = null, $expandFilesList = false) |
| 410 | 416 | { |
| 411 | 417 | if ($files !== null) { |
| 412 | - if (is_string($files)) $files = [$files]; |
|
| 418 | + if (is_string($files)) { |
|
| 419 | + $files = [$files]; |
|
| 420 | + } |
|
| 413 | 421 | |
| 414 | - if ($expandFilesList) |
|
| 415 | - $files = self::expandFileList($this->files, $files); |
|
| 422 | + if ($expandFilesList) { |
|
| 423 | + $files = self::expandFileList($this->files, $files); |
|
| 424 | + } |
|
| 416 | 425 | |
| 417 | 426 | return $this->archive->extractFiles($outputFolder, $files); |
| 418 | 427 | } else { |
@@ -434,8 +443,9 @@ discard block |
||
| 434 | 443 | { |
| 435 | 444 | $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles; |
| 436 | 445 | |
| 437 | - if ($expandFilesList && $fileOrFiles !== null) |
|
| 438 | - $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 446 | + if ($expandFilesList && $fileOrFiles !== null) { |
|
| 447 | + $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 448 | + } |
|
| 439 | 449 | |
| 440 | 450 | $result = $this->archive->deleteFiles($fileOrFiles); |
| 441 | 451 | $this->scanArchive(); |
@@ -452,8 +462,9 @@ discard block |
||
| 452 | 462 | public function addFiles($fileOrFiles) |
| 453 | 463 | { |
| 454 | 464 | $files_list = self::createFilesList($fileOrFiles); |
| 455 | - if (empty($files_list)) |
|
| 456 | - throw new InvalidArgumentException('Files list is empty!'); |
|
| 465 | + if (empty($files_list)) { |
|
| 466 | + throw new InvalidArgumentException('Files list is empty!'); |
|
| 467 | + } |
|
| 457 | 468 | $result = $this->archive->addFiles($files_list); |
| 458 | 469 | $this->scanArchive(); |
| 459 | 470 | return $result; |
@@ -469,8 +480,9 @@ discard block |
||
| 469 | 480 | */ |
| 470 | 481 | public function addFile($file, $inArchiveName = null) |
| 471 | 482 | { |
| 472 | - if (!is_file($file)) |
|
| 473 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 483 | + if (!is_file($file)) { |
|
| 484 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 485 | + } |
|
| 474 | 486 | |
| 475 | 487 | return ($inArchiveName !== null |
| 476 | 488 | ? $this->addFiles([$file => $inArchiveName]) |
@@ -487,8 +499,9 @@ discard block |
||
| 487 | 499 | */ |
| 488 | 500 | public function addDirectory($directory, $inArchivePath = null) |
| 489 | 501 | { |
| 490 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 491 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 502 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 503 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 504 | + } |
|
| 492 | 505 | |
| 493 | 506 | return ($inArchivePath !== null |
| 494 | 507 | ? $this->addFiles([$directory => $inArchivePath]) |
@@ -524,25 +537,30 @@ discard block |
||
| 524 | 537 | */ |
| 525 | 538 | public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false) |
| 526 | 539 | { |
| 527 | - if (file_exists($archiveName)) |
|
| 528 | - throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 540 | + if (file_exists($archiveName)) { |
|
| 541 | + throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 542 | + } |
|
| 529 | 543 | |
| 530 | 544 | self::checkRequirements(); |
| 531 | 545 | |
| 532 | 546 | $archiveType = self::detectArchiveType($archiveName, false); |
| 533 | 547 | // if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true)) |
| 534 | 548 | // return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate); |
| 535 | - if ($archiveType === false) |
|
| 536 | - return false; |
|
| 549 | + if ($archiveType === false) { |
|
| 550 | + return false; |
|
| 551 | + } |
|
| 537 | 552 | |
| 538 | 553 | $files_list = self::createFilesList($fileOrFiles); |
| 539 | - if (empty($files_list)) |
|
| 540 | - throw new InvalidArgumentException('Files list is empty!'); |
|
| 554 | + if (empty($files_list)) { |
|
| 555 | + throw new InvalidArgumentException('Files list is empty!'); |
|
| 556 | + } |
|
| 541 | 557 | |
| 542 | 558 | // fake creation: return archive data |
| 543 | 559 | if ($emulate) { |
| 544 | 560 | $totalSize = 0; |
| 545 | - foreach ($files_list as $fn) $totalSize += filesize($fn); |
|
| 561 | + foreach ($files_list as $fn) { |
|
| 562 | + $totalSize += filesize($fn); |
|
| 563 | + } |
|
| 546 | 564 | |
| 547 | 565 | return array( |
| 548 | 566 | 'totalSize' => $totalSize, |
@@ -552,8 +570,9 @@ discard block |
||
| 552 | 570 | ); |
| 553 | 571 | } |
| 554 | 572 | |
| 555 | - if (!isset(static::$formatHandlers[$archiveType])) |
|
| 556 | - throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 573 | + if (!isset(static::$formatHandlers[$archiveType])) { |
|
| 574 | + throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 575 | + } |
|
| 557 | 576 | |
| 558 | 577 | $handler_class = static::$formatHandlers[$archiveType]; |
| 559 | 578 | |
@@ -570,8 +589,9 @@ discard block |
||
| 570 | 589 | */ |
| 571 | 590 | public static function archiveFile($file, $archiveName) |
| 572 | 591 | { |
| 573 | - if (!is_file($file)) |
|
| 574 | - throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 592 | + if (!is_file($file)) { |
|
| 593 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 594 | + } |
|
| 575 | 595 | |
| 576 | 596 | return static::archiveFiles($file, $archiveName) === 1; |
| 577 | 597 | } |
@@ -586,8 +606,9 @@ discard block |
||
| 586 | 606 | */ |
| 587 | 607 | public static function archiveDirectory($directory, $archiveName) |
| 588 | 608 | { |
| 589 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 590 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 609 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 610 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 611 | + } |
|
| 591 | 612 | |
| 592 | 613 | return static::archiveFiles($directory, $archiveName) > 0; |
| 593 | 614 | } |
@@ -656,8 +677,9 @@ discard block |
||
| 656 | 677 | $newFiles = []; |
| 657 | 678 | foreach ($files as $file) { |
| 658 | 679 | foreach ($archiveFiles as $archiveFile) { |
| 659 | - if (fnmatch($file.'*', $archiveFile)) |
|
| 660 | - $newFiles[] = $archiveFile; |
|
| 680 | + if (fnmatch($file.'*', $archiveFile)) { |
|
| 681 | + $newFiles[] = $archiveFile; |
|
| 682 | + } |
|
| 661 | 683 | } |
| 662 | 684 | } |
| 663 | 685 | return $newFiles; |
@@ -674,26 +696,29 @@ discard block |
||
| 674 | 696 | // passed an extended list |
| 675 | 697 | if (is_array($nodes)) { |
| 676 | 698 | foreach ($nodes as $source => $destination) { |
| 677 | - if (is_numeric($source)) |
|
| 678 | - $source = $destination; |
|
| 699 | + if (is_numeric($source)) { |
|
| 700 | + $source = $destination; |
|
| 701 | + } |
|
| 679 | 702 | |
| 680 | 703 | $destination = rtrim($destination, '/\\*'); |
| 681 | 704 | |
| 682 | 705 | // if is directory |
| 683 | - if (is_dir($source)) |
|
| 684 | - self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 706 | + if (is_dir($source)) { |
|
| 707 | + self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 685 | 708 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 686 | - else if (is_file($source)) |
|
| 687 | - $files[$destination] = $source; |
|
| 709 | + } else if (is_file($source)) { |
|
| 710 | + $files[$destination] = $source; |
|
| 711 | + } |
|
| 688 | 712 | } |
| 689 | 713 | |
| 690 | 714 | } else if (is_string($nodes)) { // passed one file or directory |
| 691 | 715 | // if is directory |
| 692 | - if (is_dir($nodes)) |
|
| 693 | - self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 716 | + if (is_dir($nodes)) { |
|
| 717 | + self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 694 | 718 | $files); |
| 695 | - else if (is_file($nodes)) |
|
| 696 | - $files[basename($nodes)] = $nodes; |
|
| 719 | + } else if (is_file($nodes)) { |
|
| 720 | + $files[basename($nodes)] = $nodes; |
|
| 721 | + } |
|
| 697 | 722 | } |
| 698 | 723 | |
| 699 | 724 | return $files; |
@@ -710,8 +735,9 @@ discard block |
||
| 710 | 735 | // $map[$destination] = rtrim($source, '/*'); |
| 711 | 736 | // do not map root archive folder |
| 712 | 737 | |
| 713 | - if ($destination !== null) |
|
| 714 | - $map[$destination] = null; |
|
| 738 | + if ($destination !== null) { |
|
| 739 | + $map[$destination] = null; |
|
| 740 | + } |
|
| 715 | 741 | |
| 716 | 742 | foreach (glob($source, GLOB_MARK) as $node) { |
| 717 | 743 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -14,8 +14,9 @@ |
||
| 14 | 14 | $binary = static::makeBinary7z(); |
| 15 | 15 | $process = new Process([str_replace('\\', '/', $binary)]); |
| 16 | 16 | $result = $process->mustRun()->getOutput(); |
| 17 | - if (!preg_match('~7-Zip (\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) |
|
| 18 | - return false; |
|
| 17 | + if (!preg_match('~7-Zip (\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) { |
|
| 18 | + return false; |
|
| 19 | + } |
|
| 19 | 20 | |
| 20 | 21 | return $version['version']; |
| 21 | 22 | } |