@@ -29,20 +29,20 @@ |
||
| 29 | 29 | protected function getArchive(InputInterface $input, OutputInterface $output) |
| 30 | 30 | { |
| 31 | 31 | $file = realpath($input->getArgument('archive')); |
| 32 | - $output->writeln('<comment>Opening ' . $file . '</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 32 | + $output->writeln('<comment>Opening '.$file.'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 33 | 33 | if (!is_file($file)) { |
| 34 | - throw new \InvalidArgumentException('File ' . $input->getArgument('archive') . ' is not accessible'); |
|
| 34 | + throw new \InvalidArgumentException('File '.$input->getArgument('archive').' is not accessible'); |
|
| 35 | 35 | } |
| 36 | - $output->writeln('<comment>Format ' . Formats::detectArchiveFormat($file).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 36 | + $output->writeln('<comment>Format '.Formats::detectArchiveFormat($file).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 37 | 37 | $password = $input->getOption('password'); |
| 38 | 38 | if (empty($password)) { |
| 39 | 39 | $password = null; |
| 40 | 40 | } else { |
| 41 | - $output->writeln('<comment>Passing password: ' . strlen($password).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 41 | + $output->writeln('<comment>Passing password: '.strlen($password).'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
| 42 | 42 | } |
| 43 | 43 | $archive = $this->open($file, $password); |
| 44 | - $output->writeln('<comment>Driver ' . $archive->getDriverType() . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 45 | - $output->writeln('<comment>Driver abilities: ' . implode(', ', $this->getDriverFormatAbilities($archive->getDriverType(), $archive->getFormat())) . '</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 44 | + $output->writeln('<comment>Driver '.$archive->getDriverType().'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 45 | + $output->writeln('<comment>Driver abilities: '.implode(', ', $this->getDriverFormatAbilities($archive->getDriverType(), $archive->getFormat())).'</comment>', OutputInterface::VERBOSITY_VERBOSE); |
|
| 46 | 46 | return $archive; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $report = array(); |
| 274 | 274 | foreach ($this->listContent() as $file_header) { |
| 275 | - $file_header = (object)$file_header; |
|
| 275 | + $file_header = (object) $file_header; |
|
| 276 | 276 | // add file information to report |
| 277 | 277 | $report[] = $file_header; |
| 278 | 278 | // refuse by select rule |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | foreach ($report as $i => $reportItem) { |
| 409 | - $report[$i] = (array)$reportItem; |
|
| 409 | + $report[$i] = (array) $reportItem; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | return $report; |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | |
| 458 | 458 | $report = []; |
| 459 | 459 | foreach ($this->listContent() as $file_header) { |
| 460 | - $file_header = (object)$file_header; |
|
| 460 | + $file_header = (object) $file_header; |
|
| 461 | 461 | // select by select rule |
| 462 | 462 | if (call_user_func($selectFilter, $file_header->stored_filename, |
| 463 | 463 | $file_header->filename, $file_header->index) |
@@ -477,7 +477,7 @@ discard block |
||
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | foreach ($report as $i => $reportItem) { |
| 480 | - $report[$i] = (array)$reportItem; |
|
| 480 | + $report[$i] = (array) $reportItem; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | return $report; |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | } |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - call_user_func(function ($directory) { |
|
| 542 | + call_user_func(function($directory) { |
|
| 543 | 543 | foreach (glob($directory.'/*') as $f) { |
| 544 | 544 | if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
| 545 | 545 | else unlink($f); |
@@ -568,16 +568,16 @@ discard block |
||
| 568 | 568 | $filters = array(); |
| 569 | 569 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 570 | 570 | && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 571 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 571 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 572 | 572 | $key = str_replace($key, null, $key); |
| 573 | 573 | }; |
| 574 | 574 | if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
| 575 | - $filters[] = function (&$key, &$value) { |
|
| 575 | + $filters[] = function(&$key, &$value) { |
|
| 576 | 576 | $key = basename($key); |
| 577 | 577 | }; |
| 578 | 578 | if (isset($options[PCLZIP_OPT_ADD_PATH])) |
| 579 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 580 | - $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
|
| 579 | + $filters[] = function(&$key, &$value) use ($options) { |
|
| 580 | + $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/').'/'. |
|
| 581 | 581 | ltrim($key, '/'); |
| 582 | 582 | }; |
| 583 | 583 | return $filters; |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | private function extractCallbacks(array $options, $preCallbackConst, $postCallbackConst) |
| 593 | 593 | { |
| 594 | - $preCallback = $postCallback = function () { return true; }; |
|
| 594 | + $preCallback = $postCallback = function() { return true; }; |
|
| 595 | 595 | |
| 596 | 596 | if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
| 597 | 597 | $preCallback = $options[$preCallbackConst]; |
@@ -608,8 +608,8 @@ discard block |
||
| 608 | 608 | */ |
| 609 | 609 | private function makeKeyValueArrayFromList(array $options) |
| 610 | 610 | { |
| 611 | - $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY); |
|
| 612 | - $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY); |
|
| 611 | + $keys = array_filter($options, function($v) {return ($v % 2) == 0; }, ARRAY_FILTER_USE_KEY); |
|
| 612 | + $values = array_filter($options, function($v) {return ($v % 2) == 1; }, ARRAY_FILTER_USE_KEY); |
|
| 613 | 613 | if (count($values) < count($keys)) $values[] = true; |
| 614 | 614 | return array_combine($keys, $values); |
| 615 | 615 | } |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | range($parts[0], $parts[1]), $allowedIndexes); |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | - return function ($key, $value, $index) use ($allowedIndexes) { |
|
| 661 | + return function($key, $value, $index) use ($allowedIndexes) { |
|
| 662 | 662 | return in_array($index, $allowedIndexes) |
| 663 | 663 | ? self::SELECT_FILTER_PASS |
| 664 | 664 | : self::SELECT_FILTER_REFUSE; |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | ? $names |
| 676 | 676 | : explode(',', $names); |
| 677 | 677 | |
| 678 | - return function ($key, $value) use ($allowedNames) { |
|
| 678 | + return function($key, $value) use ($allowedNames) { |
|
| 679 | 679 | foreach ($allowedNames as $name) { |
| 680 | 680 | // select directory with nested files |
| 681 | 681 | if (in_array(substr($name, -1), ['/', '\\'])) { |
@@ -703,7 +703,7 @@ discard block |
||
| 703 | 703 | */ |
| 704 | 704 | protected function createByEregSelector($regex) |
| 705 | 705 | { |
| 706 | - return function ($key, $value) use ($regex) { |
|
| 706 | + return function($key, $value) use ($regex) { |
|
| 707 | 707 | return (ereg($regex, $key) !== false) |
| 708 | 708 | ? self::SELECT_FILTER_PASS |
| 709 | 709 | : self::SELECT_FILTER_REFUSE; |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | protected function createByPregSelector($regex) |
| 718 | 718 | { |
| 719 | - return function ($key, $value) use ($regex) { |
|
| 719 | + return function($key, $value) use ($regex) { |
|
| 720 | 720 | return preg_match($regex, $key) |
| 721 | 721 | ? self::SELECT_FILTER_PASS |
| 722 | 722 | : self::SELECT_FILTER_REFUSE; |
@@ -743,7 +743,7 @@ discard block |
||
| 743 | 743 | $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
| 744 | 744 | // no rule |
| 745 | 745 | else |
| 746 | - $selectFilter = function () { |
|
| 746 | + $selectFilter = function() { |
|
| 747 | 747 | return self::SELECT_FILTER_PASS; |
| 748 | 748 | }; |
| 749 | 749 | return $selectFilter; |
@@ -783,9 +783,9 @@ discard block |
||
| 783 | 783 | if (isset($options[PCLZIP_OPT_COMMENT])) |
| 784 | 784 | $comment = $options[PCLZIP_OPT_COMMENT]; |
| 785 | 785 | else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
| 786 | - $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 786 | + $comment = $currentComment.$options[PCLZIP_OPT_ADD_COMMENT]; |
|
| 787 | 787 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 788 | - $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
|
| 788 | + $comment = $options[PCLZIP_OPT_PREPEND_COMMENT].$currentComment; |
|
| 789 | 789 | } |
| 790 | 790 | return $comment; |
| 791 | 791 | } |
@@ -142,8 +142,11 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function create($content) |
| 144 | 144 | { |
| 145 | - if (is_array($content)) $paths_list = $content; |
|
| 146 | - else $paths_list = explode(',', $content); |
|
| 145 | + if (is_array($content)) { |
|
| 146 | + $paths_list = $content; |
|
| 147 | + } else { |
|
| 148 | + $paths_list = explode(',', $content); |
|
| 149 | + } |
|
| 147 | 150 | |
| 148 | 151 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 149 | 152 | |
@@ -151,8 +154,9 @@ discard block |
||
| 151 | 154 | $filters = $this->createFilters($options); |
| 152 | 155 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 153 | 156 | |
| 154 | - if (!empty($comment = $this->buildComment($options, null))) |
|
| 155 | - $this->archive->setComment($comment); |
|
| 157 | + if (!empty($comment = $this->buildComment($options, null))) { |
|
| 158 | + $this->archive->setComment($comment); |
|
| 159 | + } |
|
| 156 | 160 | |
| 157 | 161 | // scan filesystem for files list |
| 158 | 162 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -172,16 +176,18 @@ discard block |
||
| 172 | 176 | $localname = $fileToAdd; |
| 173 | 177 | $filename = $fileToAdd; |
| 174 | 178 | |
| 175 | - foreach ($filters as $filter) |
|
| 176 | - call_user_func($filter, $localname, $filename); |
|
| 179 | + foreach ($filters as $filter) { |
|
| 180 | + call_user_func($filter, $localname, $filename); |
|
| 181 | + } |
|
| 177 | 182 | |
| 178 | 183 | $file_header = $this->createFileHeader($localname, $filename); |
| 179 | 184 | if (call_user_func($preAddCallback, $file_header) == 1) { |
| 180 | 185 | // |
| 181 | 186 | // Check for max length > 255 |
| 182 | 187 | // |
| 183 | - if (strlen(basename($file_header->stored_filename)) > 255) |
|
| 184 | - $file_header->status = 'filename_too_long'; |
|
| 188 | + if (strlen(basename($file_header->stored_filename)) > 255) { |
|
| 189 | + $file_header->status = 'filename_too_long'; |
|
| 190 | + } |
|
| 185 | 191 | if (is_file($filename)) { |
| 186 | 192 | $this->archive->add([ |
| 187 | 193 | $file_header->stored_filename => $file_header->filename, |
@@ -253,27 +259,35 @@ discard block |
||
| 253 | 259 | } |
| 254 | 260 | |
| 255 | 261 | // filters initiation |
| 256 | - if (isset($options[PCLZIP_OPT_PATH])) |
|
| 257 | - $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 258 | - else $extractPath = rtrim(getcwd(), '/'); |
|
| 262 | + if (isset($options[PCLZIP_OPT_PATH])) { |
|
| 263 | + $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 264 | + } else { |
|
| 265 | + $extractPath = rtrim(getcwd(), '/'); |
|
| 266 | + } |
|
| 259 | 267 | |
| 260 | 268 | $filters = $this->createFilters($options); |
| 261 | 269 | list($preExtractCallback, $postExtractCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_EXTRACT, PCLZIP_CB_POST_EXTRACT); |
| 262 | 270 | $selectFilter = $this->createSelector($options); |
| 263 | 271 | |
| 264 | - if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
|
| 265 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 266 | - else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 267 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 268 | - else $anotherOutputFormat = false; |
|
| 272 | + if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 273 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 274 | + } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 275 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 276 | + } else { |
|
| 277 | + $anotherOutputFormat = false; |
|
| 278 | + } |
|
| 269 | 279 | |
| 270 | - if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 271 | - $doNotReplaceNewer = false; |
|
| 272 | - else $doNotReplaceNewer = true; |
|
| 280 | + if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) { |
|
| 281 | + $doNotReplaceNewer = false; |
|
| 282 | + } else { |
|
| 283 | + $doNotReplaceNewer = true; |
|
| 284 | + } |
|
| 273 | 285 | |
| 274 | - if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) |
|
| 275 | - $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 276 | - else $restrictExtractDir = false; |
|
| 286 | + if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 287 | + $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 288 | + } else { |
|
| 289 | + $restrictExtractDir = false; |
|
| 290 | + } |
|
| 277 | 291 | |
| 278 | 292 | $report = array(); |
| 279 | 293 | foreach ($this->listContent() as $file_header) { |
@@ -344,8 +358,10 @@ discard block |
||
| 344 | 358 | // extract content |
| 345 | 359 | else if ($anotherOutputFormat === false) { |
| 346 | 360 | // apply path filters |
| 347 | - foreach ($filters as $filter) call_user_func($filter, |
|
| 361 | + foreach ($filters as $filter) { |
|
| 362 | + call_user_func($filter, |
|
| 348 | 363 | $file_header->stored_filename, $file_header->filename); |
| 364 | + } |
|
| 349 | 365 | // dir extraction process |
| 350 | 366 | if ($file_header->folder) { |
| 351 | 367 | // if dir doesn't exist |
@@ -436,15 +452,19 @@ discard block |
||
| 436 | 452 | */ |
| 437 | 453 | public function add($content) |
| 438 | 454 | { |
| 439 | - if (is_array($content)) $paths_list = $content; |
|
| 440 | - else $paths_list = explode(',', $content); |
|
| 455 | + if (is_array($content)) { |
|
| 456 | + $paths_list = $content; |
|
| 457 | + } else { |
|
| 458 | + $paths_list = explode(',', $content); |
|
| 459 | + } |
|
| 441 | 460 | |
| 442 | 461 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 443 | 462 | $filters = $this->createFilters($options); |
| 444 | 463 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 445 | 464 | |
| 446 | - if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) |
|
| 447 | - $this->archive->setComment($comment); |
|
| 465 | + if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) { |
|
| 466 | + $this->archive->setComment($comment); |
|
| 467 | + } |
|
| 448 | 468 | |
| 449 | 469 | // scan filesystem for files list |
| 450 | 470 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -516,8 +536,12 @@ discard block |
||
| 516 | 536 | } |
| 517 | 537 | |
| 518 | 538 | $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging'); |
| 519 | - if (file_exists($tempDir)) unlink($tempDir); |
|
| 520 | - if (!mkdir($tempDir)) return 0; |
|
| 539 | + if (file_exists($tempDir)) { |
|
| 540 | + unlink($tempDir); |
|
| 541 | + } |
|
| 542 | + if (!mkdir($tempDir)) { |
|
| 543 | + return 0; |
|
| 544 | + } |
|
| 521 | 545 | |
| 522 | 546 | // go through archive content list and copy all files |
| 523 | 547 | foreach ($a->getFiles() as $filename) { |
@@ -546,8 +570,11 @@ discard block |
||
| 546 | 570 | |
| 547 | 571 | call_user_func(function ($directory) { |
| 548 | 572 | foreach (glob($directory.'/*') as $f) { |
| 549 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
| 550 | - else unlink($f); |
|
| 573 | + if (is_dir($f)) { |
|
| 574 | + call_user_func(__FUNCTION__, $f); |
|
| 575 | + } else { |
|
| 576 | + unlink($f); |
|
| 577 | + } |
|
| 551 | 578 | } |
| 552 | 579 | }, $tempDir); |
| 553 | 580 | |
@@ -572,18 +599,21 @@ discard block |
||
| 572 | 599 | { |
| 573 | 600 | $filters = array(); |
| 574 | 601 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 575 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 576 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 602 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 603 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 577 | 604 | $key = str_replace($key, null, $key); |
| 605 | + } |
|
| 578 | 606 | }; |
| 579 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 580 | - $filters[] = function (&$key, &$value) { |
|
| 607 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 608 | + $filters[] = function (&$key, &$value) { |
|
| 581 | 609 | $key = basename($key); |
| 610 | + } |
|
| 582 | 611 | }; |
| 583 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
| 584 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 612 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
| 613 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 585 | 614 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
| 586 | 615 | ltrim($key, '/'); |
| 616 | + } |
|
| 587 | 617 | }; |
| 588 | 618 | return $filters; |
| 589 | 619 | } |
@@ -598,11 +628,13 @@ discard block |
||
| 598 | 628 | { |
| 599 | 629 | $preCallback = $postCallback = function () { return true; }; |
| 600 | 630 | |
| 601 | - if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
|
| 602 | - $preCallback = $options[$preCallbackConst]; |
|
| 631 | + if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) { |
|
| 632 | + $preCallback = $options[$preCallbackConst]; |
|
| 633 | + } |
|
| 603 | 634 | |
| 604 | - if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) |
|
| 605 | - $postCallback = $options[$postCallbackConst]; |
|
| 635 | + if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) { |
|
| 636 | + $postCallback = $options[$postCallbackConst]; |
|
| 637 | + } |
|
| 606 | 638 | |
| 607 | 639 | return [$preCallback, $postCallback]; |
| 608 | 640 | } |
@@ -615,7 +647,9 @@ discard block |
||
| 615 | 647 | { |
| 616 | 648 | $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY); |
| 617 | 649 | $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY); |
| 618 | - if (count($values) < count($keys)) $values[] = true; |
|
| 650 | + if (count($values) < count($keys)) { |
|
| 651 | + $values[] = true; |
|
| 652 | + } |
|
| 619 | 653 | return array_combine($keys, $values); |
| 620 | 654 | } |
| 621 | 655 | |
@@ -658,9 +692,12 @@ discard block |
||
| 658 | 692 | $allowedIndexes = array(); |
| 659 | 693 | foreach ($indexes as $rule) { |
| 660 | 694 | $parts = explode('-', $rule); |
| 661 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
| 662 | - else $allowedIndexes = array_merge( |
|
| 695 | + if (count($parts) == 1) { |
|
| 696 | + $allowedIndexes[] = $rule; |
|
| 697 | + } else { |
|
| 698 | + $allowedIndexes = array_merge( |
|
| 663 | 699 | range($parts[0], $parts[1]), $allowedIndexes); |
| 700 | + } |
|
| 664 | 701 | } |
| 665 | 702 | |
| 666 | 703 | return function ($key, $value, $index) use ($allowedIndexes) { |
@@ -735,21 +772,26 @@ discard block |
||
| 735 | 772 | protected function createSelector(array $options) |
| 736 | 773 | { |
| 737 | 774 | // exact matching |
| 738 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
| 739 | - $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 775 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
| 776 | + $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 777 | + } |
|
| 740 | 778 | // <ereg> rule |
| 741 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
| 742 | - $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 779 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
| 780 | + $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 781 | + } |
|
| 743 | 782 | // <preg_match> rule |
| 744 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
| 745 | - $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 783 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
| 784 | + $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 785 | + } |
|
| 746 | 786 | // index rule |
| 747 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
| 748 | - $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 787 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
| 788 | + $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 789 | + } |
|
| 749 | 790 | // no rule |
| 750 | - else |
|
| 751 | - $selectFilter = function () { |
|
| 791 | + else { |
|
| 792 | + $selectFilter = function () { |
|
| 752 | 793 | return self::SELECT_FILTER_PASS; |
| 794 | + } |
|
| 753 | 795 | }; |
| 754 | 796 | return $selectFilter; |
| 755 | 797 | } |
@@ -785,9 +827,9 @@ discard block |
||
| 785 | 827 | protected function buildComment(array $options, $currentComment) |
| 786 | 828 | { |
| 787 | 829 | $comment = null; |
| 788 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
| 789 | - $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 790 | - else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 830 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
| 831 | + $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 832 | + } else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 791 | 833 | $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
| 792 | 834 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 793 | 835 | $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
@@ -27,14 +27,14 @@ |
||
| 27 | 27 | list($archive, $file) = $this->getArchiveAndFile($input, $output); |
| 28 | 28 | $destination = $input->getArgument('destination'); |
| 29 | 29 | if (is_dir($destination)) { |
| 30 | - $destination = $destination . '/' . basename($file); |
|
| 30 | + $destination = $destination.'/'.basename($file); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | $overwrite = $input->getOption('overwrite'); |
| 34 | 34 | |
| 35 | 35 | if (file_exists($destination) && !$overwrite) { |
| 36 | 36 | if ($input->getOption('no-interaction')) { |
| 37 | - throw new \LogicException('File destination ' . $destination . ' exists'); |
|
| 37 | + throw new \LogicException('File destination '.$destination.' exists'); |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
@@ -46,8 +46,9 @@ |
||
| 46 | 46 | $this->compressedSize = $compressedSize; |
| 47 | 47 | $this->uncompressedSize = $uncompressedSize; |
| 48 | 48 | $this->modificationTime = $modificationTime; |
| 49 | - if ($isCompressed === null) |
|
| 50 | - $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 49 | + if ($isCompressed === null) { |
|
| 50 | + $isCompressed = $uncompressedSize !== $compressedSize; |
|
| 51 | + } |
|
| 51 | 52 | $this->isCompressed = $isCompressed; |
| 52 | 53 | $this->comment = $comment; |
| 53 | 54 | $this->crc32 = $crc32; |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | public static function getInstallationInstruction() |
| 109 | 109 | { |
| 110 | 110 | if (!class_exists('\Archive7z\Archive7z')) |
| 111 | - return 'install library [gemorroj/archive7z]: `composer require gemorroj/archive7z`' . "\n" |
|
| 111 | + return 'install library [gemorroj/archive7z]: `composer require gemorroj/archive7z`'."\n" |
|
| 112 | 112 | . ' and console program p7zip [7za]: `apt install p7zip-full` - depends on OS'; |
| 113 | 113 | |
| 114 | 114 | if (Archive7z::getBinaryVersion() === false) |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | $information->files[] = $can_get_unix_path |
| 151 | 151 | ? $entry->getUnixPath() |
| 152 | 152 | : str_replace('\\', '/', $entry->getPath()); |
| 153 | - $information->compressedFilesSize += (int)$entry->getPackedSize(); |
|
| 154 | - $information->uncompressedFilesSize += (int)$entry->getSize(); |
|
| 153 | + $information->compressedFilesSize += (int) $entry->getPackedSize(); |
|
| 154 | + $information->uncompressedFilesSize += (int) $entry->getSize(); |
|
| 155 | 155 | } |
| 156 | 156 | return $information; |
| 157 | 157 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $entry = $this->sevenZip->getEntry($fileName); |
| 211 | 211 | if ($entry === null) { |
| 212 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist'); |
|
| 212 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist'); |
|
| 213 | 213 | } |
| 214 | 214 | return $entry->getContent(); |
| 215 | 215 | } |
@@ -36,12 +36,14 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public static function getInstallationInstruction() |
| 38 | 38 | { |
| 39 | - if (!class_exists('\Archive7z\Archive7z')) |
|
| 40 | - return 'install library [gemorroj/archive7z]: `composer require gemorroj/archive7z`' . "\n" |
|
| 39 | + if (!class_exists('\Archive7z\Archive7z')) { |
|
| 40 | + return 'install library [gemorroj/archive7z]: `composer require gemorroj/archive7z`' . "\n" |
|
| 41 | 41 | . ' and console program p7zip [7za]: `apt install p7zip-full` - depends on OS'; |
| 42 | + } |
|
| 42 | 43 | |
| 43 | - if (Archive7z::getBinaryVersion() === false) |
|
| 44 | - return 'install console program p7zip [7za]: `apt install p7zip-full` - depends on OS'; |
|
| 44 | + if (Archive7z::getBinaryVersion() === false) { |
|
| 45 | + return 'install console program p7zip [7za]: `apt install p7zip-full` - depends on OS'; |
|
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | return null; |
| 47 | 49 | } |
@@ -145,8 +147,9 @@ discard block |
||
| 145 | 147 | try { |
| 146 | 148 | $this->format = $format; |
| 147 | 149 | $this->sevenZip = new Archive7z($archiveFileName, null, null); |
| 148 | - if ($password !== null) |
|
| 149 | - $this->sevenZip->setPassword($password); |
|
| 150 | + if ($password !== null) { |
|
| 151 | + $this->sevenZip->setPassword($password); |
|
| 152 | + } |
|
| 150 | 153 | } catch (\Archive7z\Exception $e) { |
| 151 | 154 | throw new Exception('Could not open 7Zip archive: '.$e->getMessage(), $e->getCode(), $e); |
| 152 | 155 | } |
@@ -164,8 +167,9 @@ discard block |
||
| 164 | 167 | continue; |
| 165 | 168 | } |
| 166 | 169 | |
| 167 | - if (!isset($can_get_unix_path)) |
|
| 168 | - $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
| 170 | + if (!isset($can_get_unix_path)) { |
|
| 171 | + $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
| 172 | + } |
|
| 169 | 173 | |
| 170 | 174 | $information->files[] = $can_get_unix_path |
| 171 | 175 | ? $entry->getUnixPath() |
@@ -183,8 +187,9 @@ discard block |
||
| 183 | 187 | { |
| 184 | 188 | $files = []; |
| 185 | 189 | foreach ($this->sevenZip->getEntries() as $entry) { |
| 186 | - if ($entry->isDirectory()) |
|
| 187 | - continue; |
|
| 190 | + if ($entry->isDirectory()) { |
|
| 191 | + continue; |
|
| 192 | + } |
|
| 188 | 193 | $files[] = $entry->getPath(); |
| 189 | 194 | } |
| 190 | 195 | return $files; |
@@ -336,8 +341,9 @@ discard block |
||
| 336 | 341 | public function addFileFromString($inArchiveName, $content) |
| 337 | 342 | { |
| 338 | 343 | $tmp_file = tempnam(sys_get_temp_dir(), 'ua'); |
| 339 | - if (!$tmp_file) |
|
| 340 | - throw new ArchiveModificationException('Could not create temporarily file'); |
|
| 344 | + if (!$tmp_file) { |
|
| 345 | + throw new ArchiveModificationException('Could not create temporarily file'); |
|
| 346 | + } |
|
| 341 | 347 | |
| 342 | 348 | file_put_contents($tmp_file, $content); |
| 343 | 349 | $this->sevenZip->addEntry($tmp_file, true); |
@@ -387,8 +393,9 @@ discard block |
||
| 387 | 393 | $total_files = count($files); |
| 388 | 394 | |
| 389 | 395 | $seven_zip = new Archive7z($archiveFileName); |
| 390 | - if ($password !== null) |
|
| 391 | - $seven_zip->setPassword($password); |
|
| 396 | + if ($password !== null) { |
|
| 397 | + $seven_zip->setPassword($password); |
|
| 398 | + } |
|
| 392 | 399 | $seven_zip->setCompressionLevel($compressionLevelMap[$compressionLevel]); |
| 393 | 400 | foreach ($files as $archiveName => $localName) { |
| 394 | 401 | if ($localName !== null) { |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | $question = new ChoiceQuestion('Which format', array_keys($formats)); |
| 42 | 42 | $format = $helper->ask($input, $output, $question); |
| 43 | 43 | } |
| 44 | - $output->writeln('Format <info>' . $format . '</info> drivers support'); |
|
| 44 | + $output->writeln('Format <info>'.$format.'</info> drivers support'); |
|
| 45 | 45 | |
| 46 | 46 | $table = new Table($output); |
| 47 | 47 | $table->setHeaders(['format', ...array_keys(self::$abilitiesLabels)]); |
@@ -61,10 +61,11 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | protected static function init() |
| 63 | 63 | { |
| 64 | - if (!class_exists('\Alchemy\Zippy\Zippy')) |
|
| 65 | - static::$zippy = false; |
|
| 66 | - else if (static::$zippy === null) |
|
| 67 | - static::$zippy = Zippy::load(); |
|
| 64 | + if (!class_exists('\Alchemy\Zippy\Zippy')) { |
|
| 65 | + static::$zippy = false; |
|
| 66 | + } else if (static::$zippy === null) { |
|
| 67 | + static::$zippy = Zippy::load(); |
|
| 68 | + } |
|
| 68 | 69 | } |
| 69 | 70 | |
| 70 | 71 | /** |
@@ -75,8 +76,9 @@ discard block |
||
| 75 | 76 | { |
| 76 | 77 | static::init(); |
| 77 | 78 | |
| 78 | - if (static::$zippy === false) |
|
| 79 | - return []; |
|
| 79 | + if (static::$zippy === false) { |
|
| 80 | + return []; |
|
| 81 | + } |
|
| 80 | 82 | |
| 81 | 83 | switch ($format) { |
| 82 | 84 | case Formats::TAR_BZIP: |
@@ -212,8 +214,9 @@ discard block |
||
| 212 | 214 | $information = new ArchiveInformation(); |
| 213 | 215 | |
| 214 | 216 | foreach ($this->archive->getMembers() as $member) { |
| 215 | - if ($member->isDir()) |
|
| 216 | - continue; |
|
| 217 | + if ($member->isDir()) { |
|
| 218 | + continue; |
|
| 219 | + } |
|
| 217 | 220 | |
| 218 | 221 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 219 | 222 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | public static function getInstallationInstruction() |
| 64 | 64 | { |
| 65 | 65 | self::init(); |
| 66 | - return 'install library [alchemy/zippy]: `composer require alchemy/zippy`' . "\n" . ' and console programs (tar, zip): `apt install tar zip` - depends on OS' |
|
| 67 | - . "\n" . 'If you install SevenZip and AlchemyZippy:' . "\n" . |
|
| 68 | - '1. You should specify symfony/console version before installation to any **3.x.x version**:' . "\n" . '`composer require symfony/process:~3.4`, because they require different `symfony/process` versions.' . "\n" . |
|
| 66 | + return 'install library [alchemy/zippy]: `composer require alchemy/zippy`'."\n".' and console programs (tar, zip): `apt install tar zip` - depends on OS' |
|
| 67 | + . "\n".'If you install SevenZip and AlchemyZippy:'."\n". |
|
| 68 | + '1. You should specify symfony/console version before installation to any **3.x.x version**:'."\n".'`composer require symfony/process:~3.4`, because they require different `symfony/process` versions.'."\n". |
|
| 69 | 69 | '2. Install archive7z version 4.0.0: `composer require gemorroj/archive7z:~4.0`'; |
| 70 | 70 | } |
| 71 | 71 | |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 192 | 192 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
| 193 | - $information->compressedFilesSize += (int)$member->getSize(); |
|
| 194 | - $information->uncompressedFilesSize += (int)$member->getSize(); |
|
| 193 | + $information->compressedFilesSize += (int) $member->getSize(); |
|
| 194 | + $information->uncompressedFilesSize += (int) $member->getSize(); |
|
| 195 | 195 | } |
| 196 | 196 | return $information; |
| 197 | 197 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | public function getFileContent($fileName) |
| 241 | 241 | { |
| 242 | 242 | $member = $this->getMember($fileName); |
| 243 | - return (string)$member; |
|
| 243 | + return (string) $member; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | public function getFileStream($fileName) |
| 250 | 250 | { |
| 251 | 251 | $member = $this->getMember($fileName); |
| 252 | - return self::wrapStringInStream((string)$member); |
|
| 252 | + return self::wrapStringInStream((string) $member); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -86,8 +86,9 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | parent::__construct($archiveFileName, $format); |
| 88 | 88 | $this->open($archiveFileName); |
| 89 | - if ($password !== null) |
|
| 90 | - $this->zip->setPassword($password); |
|
| 89 | + if ($password !== null) { |
|
| 90 | + $this->zip->setPassword($password); |
|
| 91 | + } |
|
| 91 | 92 | } |
| 92 | 93 | |
| 93 | 94 | /** |
@@ -121,8 +122,9 @@ discard block |
||
| 121 | 122 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 122 | 123 | $file = $this->zip->statIndex($i); |
| 123 | 124 | // skip directories |
| 124 | - if (in_array(substr($file['name'], -1), ['/', '\\'], true)) |
|
| 125 | - continue; |
|
| 125 | + if (in_array(substr($file['name'], -1), ['/', '\\'], true)) { |
|
| 126 | + continue; |
|
| 127 | + } |
|
| 126 | 128 | $this->pureFilesNumber++; |
| 127 | 129 | $information->files[$i] = $file['name']; |
| 128 | 130 | $information->compressedFilesSize += $file['comp_size']; |
@@ -157,8 +159,9 @@ discard block |
||
| 157 | 159 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
| 158 | 160 | $file_name = $this->zip->getNameIndex($i); |
| 159 | 161 | // skip directories |
| 160 | - if (in_array(substr($file_name, -1), ['/', '\\'], true)) |
|
| 161 | - continue; |
|
| 162 | + if (in_array(substr($file_name, -1), ['/', '\\'], true)) { |
|
| 163 | + continue; |
|
| 164 | + } |
|
| 162 | 165 | $files[] = $file_name; |
| 163 | 166 | } |
| 164 | 167 | return $files; |
@@ -203,8 +206,9 @@ discard block |
||
| 203 | 206 | public function getFileContent($fileName) |
| 204 | 207 | { |
| 205 | 208 | $result = $this->zip->getFromName($fileName); |
| 206 | - if ($result === false) |
|
| 207 | - throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 209 | + if ($result === false) { |
|
| 210 | + throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
| 211 | + } |
|
| 208 | 212 | return $result; |
| 209 | 213 | } |
| 210 | 214 | |
@@ -225,8 +229,9 @@ discard block |
||
| 225 | 229 | */ |
| 226 | 230 | public function extractFiles($outputFolder, array $files) |
| 227 | 231 | { |
| 228 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
| 229 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 232 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
| 233 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 234 | + } |
|
| 230 | 235 | |
| 231 | 236 | return count($files); |
| 232 | 237 | } |
@@ -238,8 +243,9 @@ discard block |
||
| 238 | 243 | */ |
| 239 | 244 | public function extractArchive($outputFolder) |
| 240 | 245 | { |
| 241 | - if ($this->zip->extractTo($outputFolder) === false) |
|
| 242 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 246 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
| 247 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
| 248 | + } |
|
| 243 | 249 | |
| 244 | 250 | return $this->pureFilesNumber; |
| 245 | 251 | } |
@@ -254,8 +260,9 @@ discard block |
||
| 254 | 260 | { |
| 255 | 261 | $count = 0; |
| 256 | 262 | foreach ($files as $file) { |
| 257 | - if ($this->zip->deleteName($file) === false) |
|
| 258 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 263 | + if ($this->zip->deleteName($file) === false) { |
|
| 264 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 265 | + } |
|
| 259 | 266 | $count++; |
| 260 | 267 | } |
| 261 | 268 | |
@@ -278,11 +285,13 @@ discard block |
||
| 278 | 285 | $added_files = 0; |
| 279 | 286 | foreach ($files as $localName => $fileName) { |
| 280 | 287 | if (is_null($fileName)) { |
| 281 | - if ($this->zip->addEmptyDir($localName) === false) |
|
| 282 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 288 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
| 289 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 290 | + } |
|
| 283 | 291 | } else { |
| 284 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
| 285 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 292 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
| 293 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
| 294 | + } |
|
| 286 | 295 | $added_files++; |
| 287 | 296 | } |
| 288 | 297 | } |
@@ -335,8 +344,9 @@ discard block |
||
| 335 | 344 | $zip = new ZipArchive(); |
| 336 | 345 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
| 337 | 346 | |
| 338 | - if ($result !== true) |
|
| 339 | - throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 347 | + if ($result !== true) { |
|
| 348 | + throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
| 349 | + } |
|
| 340 | 350 | |
| 341 | 351 | $can_set_compression_level = method_exists($zip, 'setCompressionName'); |
| 342 | 352 | $can_encrypt = static::canEncrypt(Formats::ZIP); |
@@ -354,11 +364,13 @@ discard block |
||
| 354 | 364 | |
| 355 | 365 | foreach ($files as $localName => $fileName) { |
| 356 | 366 | if ($fileName === null) { |
| 357 | - if ($zip->addEmptyDir($localName) === false) |
|
| 358 | - throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 367 | + if ($zip->addEmptyDir($localName) === false) { |
|
| 368 | + throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
| 369 | + } |
|
| 359 | 370 | } else { |
| 360 | - if ($zip->addFile($fileName, $localName) === false) |
|
| 361 | - throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 371 | + if ($zip->addFile($fileName, $localName) === false) { |
|
| 372 | + throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
| 373 | + } |
|
| 362 | 374 | if ($can_set_compression_level) { |
| 363 | 375 | $zip->setCompressionName($localName, $compressionLevelMap[$compressionLevel]); |
| 364 | 376 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | |
| 29 | 29 | public static function getDescription() |
| 30 | 30 | { |
| 31 | - return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('. ZipArchive::LIBZIP_VERSION.')' : null); |
|
| 31 | + return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('.ZipArchive::LIBZIP_VERSION.')' : null); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public static function getInstallationInstruction() |
| 55 | 55 | { |
| 56 | - return 'install library [pear/archive_tar]: `composer require pear/archive_tar`' . "\n" . ' and optionally php-extensions (zlib, bz2)'; |
|
| 56 | + return 'install library [pear/archive_tar]: `composer require pear/archive_tar`'."\n".' and optionally php-extensions (zlib, bz2)'; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $compression = 'lzma2'; |
| 161 | 161 | break; |
| 162 | 162 | case 'z': |
| 163 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
| 163 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
| 164 | 164 | break; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | case Formats::TAR_LZW: |
| 219 | 219 | LzwStreamWrapper::registerWrapper(); |
| 220 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->fileName); |
|
| 220 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->fileName); |
|
| 221 | 221 | break; |
| 222 | 222 | |
| 223 | 223 | default: |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | $result = $this->tar->extractList($files, $outputFolder); |
| 336 | 336 | if ($result === false) { |
| 337 | 337 | if (isset($this->tar->error_object)) { |
| 338 | - throw new ArchiveExtractionException('Error when extracting from ' . $this->fileName . ': ' . $this->tar->error_object->getMessage(0)); |
|
| 338 | + throw new ArchiveExtractionException('Error when extracting from '.$this->fileName.': '.$this->tar->error_object->getMessage(0)); |
|
| 339 | 339 | } |
| 340 | 340 | throw new ArchiveExtractionException('Error when extracting from '.$this->fileName); |
| 341 | 341 | } |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | $result = $this->tar->extract($outputFolder); |
| 352 | 352 | if ($result === false) { |
| 353 | 353 | if (isset($this->tar->error_object)) { |
| 354 | - throw new ArchiveExtractionException('Error when extracting ' . $this->fileName . ': ' |
|
| 354 | + throw new ArchiveExtractionException('Error when extracting '.$this->fileName.': ' |
|
| 355 | 355 | . $this->tar->error_object->toString() |
| 356 | 356 | ); |
| 357 | 357 | } |
@@ -164,10 +164,11 @@ discard block |
||
| 164 | 164 | break; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if (isset($tar_aname)) |
|
| 168 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 169 | - else |
|
| 170 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 167 | + if (isset($tar_aname)) { |
|
| 168 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 169 | + } else { |
|
| 170 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 171 | + } |
|
| 171 | 172 | |
| 172 | 173 | $current_file = 0; |
| 173 | 174 | $total_files = count($files); |
@@ -179,8 +180,9 @@ discard block |
||
| 179 | 180 | // if ($tar->addString($localName, '') === false) |
| 180 | 181 | // throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
| 181 | 182 | } else { |
| 182 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 183 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 183 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 184 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 185 | + } |
|
| 184 | 186 | } |
| 185 | 187 | if ($fileProgressCallable !== null) { |
| 186 | 188 | call_user_func_array($fileProgressCallable, [$current_file++, $total_files, $filename, $localName]); |
@@ -241,8 +243,9 @@ discard block |
||
| 241 | 243 | continue; |
| 242 | 244 | } |
| 243 | 245 | // skip directories |
| 244 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
| 245 | - continue; |
|
| 246 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
| 247 | + continue; |
|
| 248 | + } |
|
| 246 | 249 | $information->files[] = $file['filename']; |
| 247 | 250 | $information->uncompressedFilesSize += $file['size']; |
| 248 | 251 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -288,14 +291,16 @@ discard block |
||
| 288 | 291 | */ |
| 289 | 292 | public function getFileData($fileName) |
| 290 | 293 | { |
| 291 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 292 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 294 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 295 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 296 | + } |
|
| 293 | 297 | |
| 294 | 298 | $index = $this->pearFilesIndex[$fileName]; |
| 295 | 299 | |
| 296 | 300 | $files_list = $this->tar->listContent(); |
| 297 | - if (!isset($files_list[$index])) |
|
| 298 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 301 | + if (!isset($files_list[$index])) { |
|
| 302 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 303 | + } |
|
| 299 | 304 | |
| 300 | 305 | $data = $files_list[$index]; |
| 301 | 306 | unset($files_list); |
@@ -310,8 +315,9 @@ discard block |
||
| 310 | 315 | */ |
| 311 | 316 | public function getFileContent($fileName) |
| 312 | 317 | { |
| 313 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 314 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 318 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 319 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 320 | + } |
|
| 315 | 321 | |
| 316 | 322 | return $this->tar->extractInString($fileName); |
| 317 | 323 | } |
@@ -321,8 +327,9 @@ discard block |
||
| 321 | 327 | */ |
| 322 | 328 | public function getFileStream($fileName) |
| 323 | 329 | { |
| 324 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 325 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 330 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 331 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 332 | + } |
|
| 326 | 333 | |
| 327 | 334 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
| 328 | 335 | } |