@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public static function open($fileName, $password = null) |
| 56 | 56 | { |
| 57 | 57 | if (!file_exists($fileName) || !is_readable($fileName)) { |
| 58 | - throw new InvalidArgumentException('Could not open file: ' . $fileName); |
|
| 58 | + throw new InvalidArgumentException('Could not open file: '.$fileName); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $format = Formats::detectArchiveFormat($fileName); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | public function getFileData($fileName) |
| 215 | 215 | { |
| 216 | 216 | if (!in_array($fileName, $this->files, true)) { |
| 217 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 217 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | return $this->archive->getFileData($fileName); |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | public function getFileContent($fileName) |
| 231 | 231 | { |
| 232 | 232 | if (!in_array($fileName, $this->files, true)) { |
| 233 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 233 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return $this->archive->getFileContent($fileName); |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | public function getFileStream($fileName) |
| 247 | 247 | { |
| 248 | 248 | if (!in_array($fileName, $this->files, true)) { |
| 249 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 249 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | return $this->archive->getFileStream($fileName); |
@@ -503,7 +503,7 @@ discard block |
||
| 503 | 503 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 504 | 504 | { |
| 505 | 505 | if (!is_file($file)) { |
| 506 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
| 506 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | return static::archiveFiles($file, $archiveName, $compressionLevel, $password) === 1; |
@@ -326,8 +326,9 @@ discard block |
||
| 326 | 326 | { |
| 327 | 327 | $files_list = static::createFilesList($fileOrFiles); |
| 328 | 328 | |
| 329 | - if (empty($files_list)) |
|
| 330 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 329 | + if (empty($files_list)) { |
|
| 330 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 331 | + } |
|
| 331 | 332 | |
| 332 | 333 | $result = $this->archive->addFiles($files_list); |
| 333 | 334 | $this->scanArchive(); |
@@ -346,8 +347,9 @@ discard block |
||
| 346 | 347 | */ |
| 347 | 348 | public function addFile($file, $inArchiveName = null) |
| 348 | 349 | { |
| 349 | - if (!is_file($file)) |
|
| 350 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 350 | + if (!is_file($file)) { |
|
| 351 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 352 | + } |
|
| 351 | 353 | |
| 352 | 354 | return ($inArchiveName !== null |
| 353 | 355 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -380,8 +382,9 @@ discard block |
||
| 380 | 382 | */ |
| 381 | 383 | public function addDirectory($directory, $inArchivePath = null) |
| 382 | 384 | { |
| 383 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 384 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 385 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 386 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 387 | + } |
|
| 385 | 388 | |
| 386 | 389 | return ($inArchivePath !== null |
| 387 | 390 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -421,13 +424,15 @@ discard block |
||
| 421 | 424 | { |
| 422 | 425 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 423 | 426 | |
| 424 | - if ($archiveType === false) |
|
| 425 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 427 | + if ($archiveType === false) { |
|
| 428 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 429 | + } |
|
| 426 | 430 | |
| 427 | 431 | $files_list = static::createFilesList($fileOrFiles); |
| 428 | 432 | |
| 429 | - if (empty($files_list)) |
|
| 430 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 433 | + if (empty($files_list)) { |
|
| 434 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 435 | + } |
|
| 431 | 436 | |
| 432 | 437 | $totalSize = 0; |
| 433 | 438 | foreach ($files_list as $fn) { |
@@ -472,16 +477,19 @@ discard block |
||
| 472 | 477 | */ |
| 473 | 478 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 474 | 479 | { |
| 475 | - if (file_exists($archiveName)) |
|
| 476 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 480 | + if (file_exists($archiveName)) { |
|
| 481 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 482 | + } |
|
| 477 | 483 | |
| 478 | 484 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 479 | 485 | |
| 480 | - if (!Formats::canCreate($info['type'])) |
|
| 481 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 486 | + if (!Formats::canCreate($info['type'])) { |
|
| 487 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 488 | + } |
|
| 482 | 489 | |
| 483 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
| 484 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 490 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
| 491 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 492 | + } |
|
| 485 | 493 | |
| 486 | 494 | /** @var BasicDriver $handler_class */ |
| 487 | 495 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -522,8 +530,9 @@ discard block |
||
| 522 | 530 | */ |
| 523 | 531 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 524 | 532 | { |
| 525 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 526 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 533 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 534 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 535 | + } |
|
| 527 | 536 | |
| 528 | 537 | return static::archiveFiles($directory, $archiveName, $compressionLevel, $password) > 0; |
| 529 | 538 | } |
@@ -558,26 +567,29 @@ discard block |
||
| 558 | 567 | // passed an extended list |
| 559 | 568 | if (is_array($nodes)) { |
| 560 | 569 | foreach ($nodes as $destination => $source) { |
| 561 | - if (is_numeric($destination)) |
|
| 562 | - $destination = $source; |
|
| 570 | + if (is_numeric($destination)) { |
|
| 571 | + $destination = $source; |
|
| 572 | + } |
|
| 563 | 573 | |
| 564 | 574 | $destination = rtrim($destination, '/\\*'); |
| 565 | 575 | |
| 566 | 576 | // if is directory |
| 567 | - if (is_dir($source)) |
|
| 568 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 577 | + if (is_dir($source)) { |
|
| 578 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 569 | 579 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 570 | - else if (is_file($source)) |
|
| 571 | - $files[$destination] = $source; |
|
| 580 | + } else if (is_file($source)) { |
|
| 581 | + $files[$destination] = $source; |
|
| 582 | + } |
|
| 572 | 583 | } |
| 573 | 584 | |
| 574 | 585 | } else if (is_string($nodes)) { // passed one file or directory |
| 575 | 586 | // if is directory |
| 576 | - if (is_dir($nodes)) |
|
| 577 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 587 | + if (is_dir($nodes)) { |
|
| 588 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 578 | 589 | $files); |
| 579 | - else if (is_file($nodes)) |
|
| 580 | - $files[basename($nodes)] = $nodes; |
|
| 590 | + } else if (is_file($nodes)) { |
|
| 591 | + $files[basename($nodes)] = $nodes; |
|
| 592 | + } |
|
| 581 | 593 | } |
| 582 | 594 | |
| 583 | 595 | return $files; |
@@ -594,8 +606,9 @@ discard block |
||
| 594 | 606 | // $map[$destination] = rtrim($source, '/*'); |
| 595 | 607 | // do not map root archive folder |
| 596 | 608 | |
| 597 | - if ($destination !== null) |
|
| 598 | - $map[$destination] = null; |
|
| 609 | + if ($destination !== null) { |
|
| 610 | + $map[$destination] = null; |
|
| 611 | + } |
|
| 599 | 612 | |
| 600 | 613 | foreach (glob($source, GLOB_MARK) as $node) { |
| 601 | 614 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |