@@ -5,7 +5,7 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Bzip extends OneFileDriver |
| 7 | 7 | { |
| 8 | - const FORMAT_SUFFIX = 'bz2'; |
|
| 8 | + const FORMAT_SUFFIX = 'bz2'; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @return array |
@@ -25,10 +25,12 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($archiveFileName, $format, $password = null) |
| 27 | 27 | { |
| 28 | - if (static::FORMAT_SUFFIX === null) |
|
| 29 | - throw new \Exception('Format should be initialized'); |
|
| 30 | - if ($password !== null) |
|
| 31 | - throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 28 | + if (static::FORMAT_SUFFIX === null) { |
|
| 29 | + throw new \Exception('Format should be initialized'); |
|
| 30 | + } |
|
| 31 | + if ($password !== null) { |
|
| 32 | + throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $this->fileName = $archiveFileName; |
| 34 | 36 | $this->inArchiveFileName = basename($archiveFileName, '.'.self::FORMAT_SUFFIX); |
@@ -96,8 +98,9 @@ discard block |
||
| 96 | 98 | public function extractArchive($outputFolder) |
| 97 | 99 | { |
| 98 | 100 | $data = $this->getFileContent($this->inArchiveFileName); |
| 99 | - if ($data === false) |
|
| 100 | - throw new ArchiveExtractionException('Could not extract archive'); |
|
| 101 | + if ($data === false) { |
|
| 102 | + throw new ArchiveExtractionException('Could not extract archive'); |
|
| 103 | + } |
|
| 101 | 104 | |
| 102 | 105 | $size = strlen($data); |
| 103 | 106 | $written = file_put_contents($outputFolder.$this->inArchiveFileName, $data); |
@@ -40,8 +40,9 @@ |
||
| 40 | 40 | $this->compressedSize = $compressedSize; |
| 41 | 41 | $this->uncompressedSize = $uncompressedSize; |
| 42 | 42 | $this->modificationTime = $modificationTime; |
| 43 | - if ($isCompressed === null) |
|
| 44 | - $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 43 | + if ($isCompressed === null) { |
|
| 44 | + $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 45 | + } |
|
| 45 | 46 | $this->isCompressed = $isCompressed; |
| 46 | 47 | } |
| 47 | 48 | } |
| 48 | 49 | \ No newline at end of file |
@@ -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 getFileResource($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->getFileResource($fileName); |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE) |
| 493 | 493 | { |
| 494 | 494 | if (!is_file($file)) { |
| 495 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
| 495 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | return static::archiveFiles($file, $archiveName, $compressionLevel) === 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([$file => $inArchiveName]) |
@@ -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([$directory => $inArchivePath]) |
@@ -415,13 +418,15 @@ discard block |
||
| 415 | 418 | { |
| 416 | 419 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 417 | 420 | |
| 418 | - if ($archiveType === false) |
|
| 419 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 421 | + if ($archiveType === false) { |
|
| 422 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 423 | + } |
|
| 420 | 424 | |
| 421 | 425 | $files_list = static::createFilesList($fileOrFiles); |
| 422 | 426 | |
| 423 | - if (empty($files_list)) |
|
| 424 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 427 | + if (empty($files_list)) { |
|
| 428 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 429 | + } |
|
| 425 | 430 | |
| 426 | 431 | $totalSize = 0; |
| 427 | 432 | foreach ($files_list as $fn) { |
@@ -465,13 +470,15 @@ discard block |
||
| 465 | 470 | */ |
| 466 | 471 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE) |
| 467 | 472 | { |
| 468 | - if (file_exists($archiveName)) |
|
| 469 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 473 | + if (file_exists($archiveName)) { |
|
| 474 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 475 | + } |
|
| 470 | 476 | |
| 471 | 477 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 472 | 478 | |
| 473 | - if (!Formats::canCreate($info['type'])) |
|
| 474 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 479 | + if (!Formats::canCreate($info['type'])) { |
|
| 480 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 481 | + } |
|
| 475 | 482 | |
| 476 | 483 | /** @var BasicDriver $handler_class */ |
| 477 | 484 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -510,8 +517,9 @@ discard block |
||
| 510 | 517 | */ |
| 511 | 518 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE) |
| 512 | 519 | { |
| 513 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 514 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 520 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 521 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 522 | + } |
|
| 515 | 523 | |
| 516 | 524 | return static::archiveFiles($directory, $archiveName) > 0; |
| 517 | 525 | } |
@@ -546,26 +554,29 @@ discard block |
||
| 546 | 554 | // passed an extended list |
| 547 | 555 | if (is_array($nodes)) { |
| 548 | 556 | foreach ($nodes as $source => $destination) { |
| 549 | - if (is_numeric($source)) |
|
| 550 | - $source = $destination; |
|
| 557 | + if (is_numeric($source)) { |
|
| 558 | + $source = $destination; |
|
| 559 | + } |
|
| 551 | 560 | |
| 552 | 561 | $destination = rtrim($destination, '/\\*'); |
| 553 | 562 | |
| 554 | 563 | // if is directory |
| 555 | - if (is_dir($source)) |
|
| 556 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 564 | + if (is_dir($source)) { |
|
| 565 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 557 | 566 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 558 | - else if (is_file($source)) |
|
| 559 | - $files[$destination] = $source; |
|
| 567 | + } else if (is_file($source)) { |
|
| 568 | + $files[$destination] = $source; |
|
| 569 | + } |
|
| 560 | 570 | } |
| 561 | 571 | |
| 562 | 572 | } else if (is_string($nodes)) { // passed one file or directory |
| 563 | 573 | // if is directory |
| 564 | - if (is_dir($nodes)) |
|
| 565 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 574 | + if (is_dir($nodes)) { |
|
| 575 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 566 | 576 | $files); |
| 567 | - else if (is_file($nodes)) |
|
| 568 | - $files[basename($nodes)] = $nodes; |
|
| 577 | + } else if (is_file($nodes)) { |
|
| 578 | + $files[basename($nodes)] = $nodes; |
|
| 579 | + } |
|
| 569 | 580 | } |
| 570 | 581 | |
| 571 | 582 | return $files; |
@@ -582,8 +593,9 @@ discard block |
||
| 582 | 593 | // $map[$destination] = rtrim($source, '/*'); |
| 583 | 594 | // do not map root archive folder |
| 584 | 595 | |
| 585 | - if ($destination !== null) |
|
| 586 | - $map[$destination] = null; |
|
| 596 | + if ($destination !== null) { |
|
| 597 | + $map[$destination] = null; |
|
| 598 | + } |
|
| 587 | 599 | |
| 588 | 600 | foreach (glob($source, GLOB_MARK) as $node) { |
| 589 | 601 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -10,13 +10,13 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | public static function getBinaryVersion() |
| 12 | 12 | { |
| 13 | - if (method_exists(__CLASS__, 'makeBinary7z')) |
|
| 14 | - try { |
|
| 13 | + if (method_exists(__CLASS__, 'makeBinary7z')) { |
|
| 14 | + try { |
|
| 15 | 15 | $binary = static::makeBinary7z(); |
| 16 | + } |
|
| 16 | 17 | } catch (\Exception $e) { |
| 17 | 18 | return false; |
| 18 | - } |
|
| 19 | - else { |
|
| 19 | + } else { |
|
| 20 | 20 | // some hack for gemorroj/archive7z 4.x version |
| 21 | 21 | try { |
| 22 | 22 | $seven_zip = new self(null); |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | $process = new Process([str_replace('\\', '/', $binary)]); |
| 31 | 31 | $result = $process->mustRun()->getOutput(); |
| 32 | - if (!preg_match('~7-Zip (\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) |
|
| 33 | - return false; |
|
| 32 | + if (!preg_match('~7-Zip (\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) { |
|
| 33 | + return false; |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | 36 | return $version['version']; |
| 36 | 37 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function checkFormats() |
| 32 | 32 | { |
| 33 | 33 | echo "format\topen\tcreate\tappend\tupdate\tencrypt\tdrivers".PHP_EOL; |
| 34 | - foreach(Formats::getFormatsReport() as $format => $config) { |
|
| 34 | + foreach (Formats::getFormatsReport() as $format => $config) { |
|
| 35 | 35 | echo $format."\t" |
| 36 | 36 | .($config['open'] ? '+' : '-')."\t" |
| 37 | 37 | .($config['create'] ? '+' : '-')."\t" |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | $description = $driverClass::getDescription(); |
| 88 | 88 | $install = $driverClass::getInstallationInstruction(); |
| 89 | 89 | $formats = $driverClass::getSupportedFormats(); |
| 90 | - echo ($i+1).'. '.$driverClass . " - ".$description.PHP_EOL |
|
| 91 | - .'- '.$install.PHP_EOL . PHP_EOL; |
|
| 90 | + echo ($i + 1).'. '.$driverClass." - ".$description.PHP_EOL |
|
| 91 | + .'- '.$install.PHP_EOL.PHP_EOL; |
|
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | else { |
| 322 | 322 | $size = $this->formatSize($len); |
| 323 | 323 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 324 | - $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
|
| 324 | + $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']).PHP_EOL; |
|
| 325 | 325 | } |
| 326 | 326 | } |
| 327 | 327 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | if ($archived_files === false) |
| 343 | 343 | echo 'Error'.PHP_EOL; |
| 344 | 344 | else |
| 345 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 345 | + echo 'Created archive '.$args['ARCHIVE'].' with '.$archived_files.' file(s) of total size '.implode('', $this->formatSize(filesize($args['ARCHIVE']))).PHP_EOL; |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | } |
@@ -15,12 +15,14 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | protected function open($file, $password = null) |
| 17 | 17 | { |
| 18 | - if (!UnifiedArchive::canOpen($file)) |
|
| 19 | - throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 18 | + if (!UnifiedArchive::canOpen($file)) { |
|
| 19 | + throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $archive = UnifiedArchive::open($file, $password); |
| 22 | - if ($archive === null) |
|
| 23 | - throw new Exception('Could not open archive '.$file); |
|
| 23 | + if ($archive === null) { |
|
| 24 | + throw new Exception('Could not open archive '.$file); |
|
| 25 | + } |
|
| 24 | 26 | |
| 25 | 27 | return $archive; |
| 26 | 28 | } |
@@ -164,17 +166,18 @@ discard block |
||
| 164 | 166 | */ |
| 165 | 167 | public function formatDate($unixtime) |
| 166 | 168 | { |
| 167 | - if (strtotime('today') < $unixtime) |
|
| 168 | - return 'Today, '.date('G:m', $unixtime); |
|
| 169 | - else if (strtotime('yesterday') < $unixtime) |
|
| 170 | - return 'Yesterday, '.date('G:m', $unixtime); |
|
| 171 | - else { |
|
| 169 | + if (strtotime('today') < $unixtime) { |
|
| 170 | + return 'Today, '.date('G:m', $unixtime); |
|
| 171 | + } else if (strtotime('yesterday') < $unixtime) { |
|
| 172 | + return 'Yesterday, '.date('G:m', $unixtime); |
|
| 173 | + } else { |
|
| 172 | 174 | $datetime = new \DateTime(); |
| 173 | 175 | $datetime->setTimestamp($unixtime); |
| 174 | - if ($datetime->format('Y') == date('Y')) |
|
| 175 | - return $datetime->format('d M, G:m'); |
|
| 176 | - else |
|
| 177 | - return $datetime->format('d M Y, G:m'); |
|
| 176 | + if ($datetime->format('Y') == date('Y')) { |
|
| 177 | + return $datetime->format('d M, G:m'); |
|
| 178 | + } else { |
|
| 179 | + return $datetime->format('d M Y, G:m'); |
|
| 180 | + } |
|
| 178 | 181 | } |
| 179 | 182 | } |
| 180 | 183 | |
@@ -204,25 +207,36 @@ discard block |
||
| 204 | 207 | $archive = $this->open($args['ARCHIVE'], isset($args['--password']) ? $args['--password'] : null); |
| 205 | 208 | $output = getcwd(); |
| 206 | 209 | if (isset($args['--output'])) { |
| 207 | - if (!is_dir($args['--output'])) |
|
| 208 | - mkdir($args['--output']); |
|
| 210 | + if (!is_dir($args['--output'])) { |
|
| 211 | + mkdir($args['--output']); |
|
| 212 | + } |
|
| 209 | 213 | $output = realpath($args['--output']); |
| 210 | 214 | } |
| 211 | 215 | |
| 212 | 216 | if (empty($args['FILES_IN_ARCHIVE']) || $args['FILES_IN_ARCHIVE'] == array('/') || $args['FILES_IN_ARCHIVE'] == array('*')) { |
| 213 | 217 | $result = $archive->extractFiles($output); |
| 214 | - if ($result === false) echo 'Error occured'.PHP_EOL; |
|
| 215 | - else echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 218 | + if ($result === false) { |
|
| 219 | + echo 'Error occured'.PHP_EOL; |
|
| 220 | + } else { |
|
| 221 | + echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 222 | + } |
|
| 216 | 223 | } else { |
| 217 | 224 | $extracted = 0; |
| 218 | 225 | $errored = []; |
| 219 | 226 | foreach ($args['FILES_IN_ARCHIVE'] as $file) { |
| 220 | 227 | $result = $archive->extractFiles($output, $file); |
| 221 | - if ($result === false) $errored[] = $file; |
|
| 222 | - else $extracted += $result; |
|
| 228 | + if ($result === false) { |
|
| 229 | + $errored[] = $file; |
|
| 230 | + } else { |
|
| 231 | + $extracted += $result; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + if (!empty($errored)) { |
|
| 235 | + echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 236 | + } |
|
| 237 | + if ($extracted > 0) { |
|
| 238 | + echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 223 | 239 | } |
| 224 | - if (!empty($errored)) echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 225 | - if ($extracted > 0) echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 226 | 240 | } |
| 227 | 241 | } |
| 228 | 242 | |
@@ -281,8 +295,9 @@ discard block |
||
| 281 | 295 | echo 'File '.$file.' is NOT in archive'.PHP_EOL; |
| 282 | 296 | continue; |
| 283 | 297 | } |
| 284 | - if ($archive->deleteFiles($file) === false) |
|
| 285 | - echo 'Error file '.$file.PHP_EOL; |
|
| 298 | + if ($archive->deleteFiles($file) === false) { |
|
| 299 | + echo 'Error file '.$file.PHP_EOL; |
|
| 300 | + } |
|
| 286 | 301 | } |
| 287 | 302 | } |
| 288 | 303 | |
@@ -295,10 +310,11 @@ discard block |
||
| 295 | 310 | { |
| 296 | 311 | $archive = $this->open($args['ARCHIVE']); |
| 297 | 312 | $added_files = $archive->addFiles($args['FILES_ON_DISK']); |
| 298 | - if ($added_files === false) |
|
| 299 | - echo 'Error'.PHP_EOL; |
|
| 300 | - else |
|
| 301 | - echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 313 | + if ($added_files === false) { |
|
| 314 | + echo 'Error'.PHP_EOL; |
|
| 315 | + } else { |
|
| 316 | + echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 317 | + } |
|
| 302 | 318 | } |
| 303 | 319 | |
| 304 | 320 | /** |
@@ -316,9 +332,9 @@ discard block |
||
| 316 | 332 | $len = strlen($content); |
| 317 | 333 | |
| 318 | 334 | $added_files = $archive->addFileFromString($args['FILE_IN_ARCHIVE'], $content); |
| 319 | - if ($added_files === false) |
|
| 320 | - echo 'Error'.PHP_EOL; |
|
| 321 | - else { |
|
| 335 | + if ($added_files === false) { |
|
| 336 | + echo 'Error'.PHP_EOL; |
|
| 337 | + } else { |
|
| 322 | 338 | $size = $this->formatSize($len); |
| 323 | 339 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 324 | 340 | $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
@@ -332,17 +348,18 @@ discard block |
||
| 332 | 348 | public function create($args) |
| 333 | 349 | { |
| 334 | 350 | if (file_exists($args['ARCHIVE'])) { |
| 335 | - if (is_dir($args['ARCHIVE'])) |
|
| 336 | - echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 337 | - else { |
|
| 351 | + if (is_dir($args['ARCHIVE'])) { |
|
| 352 | + echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 353 | + } else { |
|
| 338 | 354 | echo 'File '.$args['ARCHIVE'].' already exists!'.PHP_EOL; |
| 339 | 355 | } |
| 340 | 356 | } else { |
| 341 | 357 | $archived_files = UnifiedArchive::archiveFiles($args['FILES_ON_DISK'], $args['ARCHIVE']); |
| 342 | - if ($archived_files === false) |
|
| 343 | - echo 'Error'.PHP_EOL; |
|
| 344 | - else |
|
| 345 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 358 | + if ($archived_files === false) { |
|
| 359 | + echo 'Error'.PHP_EOL; |
|
| 360 | + } else { |
|
| 361 | + echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 362 | + } |
|
| 346 | 363 | } |
| 347 | 364 | } |
| 348 | 365 | } |
@@ -90,7 +90,9 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | $information = new ArchiveInformation(); |
| 92 | 92 | foreach ($this->rar->getEntries() as $i => $entry) { |
| 93 | - if ($entry->isDirectory()) continue; |
|
| 93 | + if ($entry->isDirectory()) { |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 94 | 96 | $information->files[] = $entry->getName(); |
| 95 | 97 | $information->compressedFilesSize += $entry->getPackedSize(); |
| 96 | 98 | $information->uncompressedFilesSize += $entry->getUnpackedSize(); |
@@ -105,7 +107,9 @@ discard block |
||
| 105 | 107 | { |
| 106 | 108 | $files = []; |
| 107 | 109 | foreach ($this->rar->getEntries() as $i => $entry) { |
| 108 | - if ($entry->isDirectory()) continue; |
|
| 110 | + if ($entry->isDirectory()) { |
|
| 111 | + continue; |
|
| 112 | + } |
|
| 109 | 113 | $files[] = $entry->getName(); |
| 110 | 114 | } |
| 111 | 115 | return $files; |
@@ -141,7 +145,9 @@ discard block |
||
| 141 | 145 | public function getFileContent($fileName) |
| 142 | 146 | { |
| 143 | 147 | $entry = $this->rar->getEntry($fileName); |
| 144 | - if ($entry->isDirectory()) return false; |
|
| 148 | + if ($entry->isDirectory()) { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 145 | 151 | return stream_get_contents($entry->getStream()); |
| 146 | 152 | } |
| 147 | 153 | |
@@ -153,7 +159,9 @@ discard block |
||
| 153 | 159 | public function getFileResource($fileName) |
| 154 | 160 | { |
| 155 | 161 | $entry = $this->rar->getEntry($fileName); |
| 156 | - if ($entry->isDirectory()) return false; |
|
| 162 | + if ($entry->isDirectory()) { |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 157 | 165 | return $entry->getStream(); |
| 158 | 166 | } |
| 159 | 167 | |
@@ -61,8 +61,9 @@ discard block |
||
| 61 | 61 | public function __construct($archiveFileName, $format, $password = null) |
| 62 | 62 | { |
| 63 | 63 | $this->open($archiveFileName); |
| 64 | - if ($password !== null) |
|
| 65 | - $this->zip->setPassword($password); |
|
| 64 | + if ($password !== null) { |
|
| 65 | + $this->zip->setPassword($password); |
|
| 66 | + } |
|
| 66 | 67 | } |
| 67 | 68 | |
| 68 | 69 | /** |
@@ -95,8 +96,9 @@ discard block |
||
| 95 | 96 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 96 | 97 | $file = $this->zip->statIndex($i); |
| 97 | 98 | // skip directories |
| 98 | - if (in_array(substr($file['name'], -1), ['/', '\\'], true)) |
|
| 99 | - continue; |
|
| 99 | + if (in_array(substr($file['name'], -1), ['/', '\\'], true)) { |
|
| 100 | + continue; |
|
| 101 | + } |
|
| 100 | 102 | $information->files[$i] = $file['name']; |
| 101 | 103 | $information->compressedFilesSize += $file['comp_size']; |
| 102 | 104 | $information->uncompressedFilesSize += $file['size']; |
@@ -113,8 +115,9 @@ discard block |
||
| 113 | 115 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 114 | 116 | $file_name = $this->zip->getNameIndex($i); |
| 115 | 117 | // skip directories |
| 116 | - if (in_array(substr($file_name, -1), ['/', '\\'], true)) |
|
| 117 | - continue; |
|
| 118 | + if (in_array(substr($file_name, -1), ['/', '\\'], true)) { |
|
| 119 | + continue; |
|
| 120 | + } |
|
| 118 | 121 | $files[] = $file_name; |
| 119 | 122 | } |
| 120 | 123 | return $files; |
@@ -151,8 +154,9 @@ discard block |
||
| 151 | 154 | public function getFileContent($fileName) |
| 152 | 155 | { |
| 153 | 156 | $result = $this->zip->getFromName($fileName); |
| 154 | - if ($result === false) |
|
| 155 | - throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 157 | + if ($result === false) { |
|
| 158 | + throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 159 | + } |
|
| 156 | 160 | return $result; |
| 157 | 161 | } |
| 158 | 162 | |
@@ -174,8 +178,9 @@ discard block |
||
| 174 | 178 | */ |
| 175 | 179 | public function extractFiles($outputFolder, array $files) |
| 176 | 180 | { |
| 177 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
| 178 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 181 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
| 182 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 183 | + } |
|
| 179 | 184 | |
| 180 | 185 | return count($files); |
| 181 | 186 | } |
@@ -187,8 +192,9 @@ discard block |
||
| 187 | 192 | */ |
| 188 | 193 | public function extractArchive($outputFolder) |
| 189 | 194 | { |
| 190 | - if ($this->zip->extractTo($outputFolder) === false) |
|
| 191 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 195 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
| 196 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 197 | + } |
|
| 192 | 198 | |
| 193 | 199 | return $this->zip->numFiles; |
| 194 | 200 | } |
@@ -203,8 +209,9 @@ discard block |
||
| 203 | 209 | { |
| 204 | 210 | $count = 0; |
| 205 | 211 | foreach ($files as $file) { |
| 206 | - if ($this->zip->deleteName($file) === false) |
|
| 207 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 212 | + if ($this->zip->deleteName($file) === false) { |
|
| 213 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 214 | + } |
|
| 208 | 215 | $count++; |
| 209 | 216 | } |
| 210 | 217 | |
@@ -227,11 +234,13 @@ discard block |
||
| 227 | 234 | $added_files = 0; |
| 228 | 235 | foreach ($files as $localName => $fileName) { |
| 229 | 236 | if (is_null($fileName)) { |
| 230 | - if ($this->zip->addEmptyDir($localName) === false) |
|
| 231 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 237 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
| 238 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 239 | + } |
|
| 232 | 240 | } else { |
| 233 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
| 234 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 241 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
| 242 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 243 | + } |
|
| 235 | 244 | $added_files++; |
| 236 | 245 | } |
| 237 | 246 | } |
@@ -264,18 +273,21 @@ discard block |
||
| 264 | 273 | $zip = new ZipArchive(); |
| 265 | 274 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
| 266 | 275 | |
| 267 | - if ($result !== true) |
|
| 268 | - throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 276 | + if ($result !== true) { |
|
| 277 | + throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | 280 | $can_set_compression_level = method_exists($zip, 'setCompressionName'); |
| 271 | 281 | |
| 272 | 282 | foreach ($files as $localName => $fileName) { |
| 273 | 283 | if ($fileName === null) { |
| 274 | - if ($zip->addEmptyDir($localName) === false) |
|
| 275 | - throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 284 | + if ($zip->addEmptyDir($localName) === false) { |
|
| 285 | + throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 286 | + } |
|
| 276 | 287 | } else { |
| 277 | - if ($zip->addFile($fileName, $localName) === false) |
|
| 278 | - throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 288 | + if ($zip->addFile($fileName, $localName) === false) { |
|
| 289 | + throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 290 | + } |
|
| 279 | 291 | if ($can_set_compression_level) { |
| 280 | 292 | $zip->setCompressionName($localName, $compressionLevelMap[$compressionLevel]); |
| 281 | 293 | } |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | continue; |
| 170 | 170 | |
| 171 | 171 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 172 | - $information->compressedFilesSize += (int)$member->getSize(); |
|
| 173 | - $information->uncompressedFilesSize += (int)$member->getSize(); |
|
| 172 | + $information->compressedFilesSize += (int) $member->getSize(); |
|
| 173 | + $information->uncompressedFilesSize += (int) $member->getSize(); |
|
| 174 | 174 | } |
| 175 | 175 | return $information; |
| 176 | 176 | } |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | public function getFileContent($fileName) |
| 218 | 218 | { |
| 219 | 219 | $member = $this->getMember($fileName); |
| 220 | - return (string)$member; |
|
| 220 | + return (string) $member; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -53,11 +53,13 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | protected static function init() |
| 55 | 55 | { |
| 56 | - if (!class_exists('\Alchemy\Zippy\Zippy')) |
|
| 57 | - static::$zippy = false; |
|
| 56 | + if (!class_exists('\Alchemy\Zippy\Zippy')) { |
|
| 57 | + static::$zippy = false; |
|
| 58 | + } |
|
| 58 | 59 | |
| 59 | - if (static::$zippy === null) |
|
| 60 | - static::$zippy = Zippy::load(); |
|
| 60 | + if (static::$zippy === null) { |
|
| 61 | + static::$zippy = Zippy::load(); |
|
| 62 | + } |
|
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | /** |
@@ -68,8 +70,9 @@ discard block |
||
| 68 | 70 | { |
| 69 | 71 | static::init(); |
| 70 | 72 | |
| 71 | - if (static::$zippy === false) |
|
| 72 | - return false; |
|
| 73 | + if (static::$zippy === false) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 73 | 76 | |
| 74 | 77 | switch ($format) { |
| 75 | 78 | case Formats::TAR_BZIP: |
@@ -165,8 +168,9 @@ discard block |
||
| 165 | 168 | $information = new ArchiveInformation(); |
| 166 | 169 | |
| 167 | 170 | foreach ($this->archive->getMembers() as $member) { |
| 168 | - if ($member->isDir()) |
|
| 169 | - continue; |
|
| 171 | + if ($member->isDir()) { |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 170 | 174 | |
| 171 | 175 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 172 | 176 | $information->compressedFilesSize += (int)$member->getSize(); |
@@ -194,10 +198,12 @@ discard block |
||
| 194 | 198 | protected function getMember($fileName) |
| 195 | 199 | { |
| 196 | 200 | foreach ($this->archive->getMembers() as $member) { |
| 197 | - if ($member->isDir()) |
|
| 198 | - continue; |
|
| 199 | - if ($member->getLocation() === $fileName) |
|
| 200 | - return $member; |
|
| 201 | + if ($member->isDir()) { |
|
| 202 | + continue; |
|
| 203 | + } |
|
| 204 | + if ($member->getLocation() === $fileName) { |
|
| 205 | + return $member; |
|
| 206 | + } |
|
| 201 | 207 | } |
| 202 | 208 | return null; |
| 203 | 209 | } |