@@ -35,13 +35,13 @@ |
||
| 35 | 35 | if (!empty($install)) { |
| 36 | 36 | $notInstalled[] = [$driverClass, $description, $install]; |
| 37 | 37 | } else { |
| 38 | - $output->writeln($formatter->formatSection($driverClass, $description) . ': ' . implode(', ', $driverClass::getSupportedFormats())); |
|
| 38 | + $output->writeln($formatter->formatSection($driverClass, $description).': '.implode(', ', $driverClass::getSupportedFormats())); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | if (!empty($notInstalled)) { |
| 43 | 43 | foreach ($notInstalled as $data) { |
| 44 | - $output->writeln($formatter->formatSection($data[0], $data[1] . ': ' . implode(', ', $data[0]::getSupportedFormats()), 'error')); |
|
| 44 | + $output->writeln($formatter->formatSection($data[0], $data[1].': '.implode(', ', $data[0]::getSupportedFormats()), 'error')); |
|
| 45 | 45 | $data[2] = preg_replace('~`(.+?)`~', '<options=bold,underscore>$1</>', $data[2]); |
| 46 | 46 | $output->writeln($formatter->formatSection($data[0], $data[2], 'comment')); |
| 47 | 47 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | public static function getInstallationInstruction() |
| 91 | 91 | { |
| 92 | 92 | return !class_exists('\Archive_Tar') |
| 93 | - ? 'install library [pear/archive_tar]: `composer require pear/archive_tar`' . "\n" . ' and optionally php-extensions (zlib, bzip2)' |
|
| 93 | + ? 'install library [pear/archive_tar]: `composer require pear/archive_tar`'."\n".' and optionally php-extensions (zlib, bzip2)' |
|
| 94 | 94 | : null; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $compression = 'lzma2'; |
| 137 | 137 | break; |
| 138 | 138 | case 'z': |
| 139 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
| 139 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
| 140 | 140 | break; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | case Formats::TAR_LZW: |
| 195 | 195 | LzwStreamWrapper::registerWrapper(); |
| 196 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->archiveFileName); |
|
| 196 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->archiveFileName); |
|
| 197 | 197 | break; |
| 198 | 198 | |
| 199 | 199 | default: |
@@ -165,10 +165,11 @@ discard block |
||
| 165 | 165 | break; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if (isset($tar_aname)) |
|
| 169 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 170 | - else |
|
| 171 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 168 | + if (isset($tar_aname)) { |
|
| 169 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 170 | + } else { |
|
| 171 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 172 | + } |
|
| 172 | 173 | |
| 173 | 174 | $current_file = 0; |
| 174 | 175 | $total_files = count($files); |
@@ -177,11 +178,13 @@ discard block |
||
| 177 | 178 | $add_dir = dirname($localName); |
| 178 | 179 | |
| 179 | 180 | if (is_null($filename)) { |
| 180 | - if ($tar->addString($localName, '') === false) |
|
| 181 | - throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 181 | + if ($tar->addString($localName, '') === false) { |
|
| 182 | + throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 183 | + } |
|
| 182 | 184 | } else { |
| 183 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 184 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 185 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 186 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 187 | + } |
|
| 185 | 188 | } |
| 186 | 189 | if ($fileProgressCallable !== null) { |
| 187 | 190 | call_user_func_array($fileProgressCallable, [$current_file++, $total_files, $filename, $localName]); |
@@ -242,8 +245,9 @@ discard block |
||
| 242 | 245 | continue; |
| 243 | 246 | } |
| 244 | 247 | // skip directories |
| 245 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
| 246 | - continue; |
|
| 248 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
| 249 | + continue; |
|
| 250 | + } |
|
| 247 | 251 | $information->files[] = $file['filename']; |
| 248 | 252 | $information->uncompressedFilesSize += $file['size']; |
| 249 | 253 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -289,14 +293,16 @@ discard block |
||
| 289 | 293 | */ |
| 290 | 294 | public function getFileData($fileName) |
| 291 | 295 | { |
| 292 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 293 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 296 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 297 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 298 | + } |
|
| 294 | 299 | |
| 295 | 300 | $index = $this->pearFilesIndex[$fileName]; |
| 296 | 301 | |
| 297 | 302 | $files_list = $this->tar->listContent(); |
| 298 | - if (!isset($files_list[$index])) |
|
| 299 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 303 | + if (!isset($files_list[$index])) { |
|
| 304 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 305 | + } |
|
| 300 | 306 | |
| 301 | 307 | $data = $files_list[$index]; |
| 302 | 308 | unset($files_list); |
@@ -311,8 +317,9 @@ discard block |
||
| 311 | 317 | */ |
| 312 | 318 | public function getFileContent($fileName) |
| 313 | 319 | { |
| 314 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 315 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 320 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 321 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 322 | + } |
|
| 316 | 323 | |
| 317 | 324 | return $this->tar->extractInString($fileName); |
| 318 | 325 | } |
@@ -322,8 +329,9 @@ discard block |
||
| 322 | 329 | */ |
| 323 | 330 | public function getFileStream($fileName) |
| 324 | 331 | { |
| 325 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 326 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 332 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 333 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 334 | + } |
|
| 327 | 335 | |
| 328 | 336 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
| 329 | 337 | } |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | self::init(); |
| 104 | 104 | return static::$zippy === false |
| 105 | - ? 'install library [alchemy/zippy]: `composer require alchemy/zippy`' . "\n" . ' and console programs (tar, zip): `apt install tar zip` - depends on OS' |
|
| 106 | - . "\n" . 'If you install SevenZip and AlchemyZippy:' . "\n" . |
|
| 107 | -'1. You should specify symfony/console version before installation to any **3.x.x version**: `composer require symfony/process:~3.4`, because they require different `symfony/process` versions.' . "\n" . |
|
| 105 | + ? 'install library [alchemy/zippy]: `composer require alchemy/zippy`'."\n".' and console programs (tar, zip): `apt install tar zip` - depends on OS' |
|
| 106 | + . "\n".'If you install SevenZip and AlchemyZippy:'."\n". |
|
| 107 | +'1. You should specify symfony/console version before installation to any **3.x.x version**: `composer require symfony/process:~3.4`, because they require different `symfony/process` versions.'."\n". |
|
| 108 | 108 | '2. Install archive7z version 4.0.0: `composer require gemorroj/archive7z:~4.0`' |
| 109 | 109 | : null; |
| 110 | 110 | } |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 209 | 209 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
| 210 | - $information->compressedFilesSize += (int)$member->getSize(); |
|
| 211 | - $information->uncompressedFilesSize += (int)$member->getSize(); |
|
| 210 | + $information->compressedFilesSize += (int) $member->getSize(); |
|
| 211 | + $information->uncompressedFilesSize += (int) $member->getSize(); |
|
| 212 | 212 | } |
| 213 | 213 | return $information; |
| 214 | 214 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | public function getFileContent($fileName) |
| 258 | 258 | { |
| 259 | 259 | $member = $this->getMember($fileName); |
| 260 | - return (string)$member; |
|
| 260 | + return (string) $member; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | public function getFileStream($fileName) |
| 267 | 267 | { |
| 268 | 268 | $member = $this->getMember($fileName); |
| 269 | - return self::wrapStringInStream((string)$member); |
|
| 269 | + return self::wrapStringInStream((string) $member); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -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; |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class Lzma extends OneFileDriver |
| 14 | 14 | { |
| 15 | - const FORMAT_SUFFIX = 'xz'; |
|
| 15 | + const FORMAT_SUFFIX = 'xz'; |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @return array |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | public static function getInstallationInstruction() |
| 51 | 51 | { |
| 52 | 52 | return !extension_loaded('xz') |
| 53 | - ? 'install [xz] extension' . "\n" . 'For 5.x: https://github.com/payden/php-xz' . "\n" . 'For 7.x: https://github.com/codemasher/php-ext-xz' |
|
| 53 | + ? 'install [xz] extension'."\n".'For 5.x: https://github.com/payden/php-xz'."\n".'For 7.x: https://github.com/codemasher/php-ext-xz' |
|
| 54 | 54 | : null; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -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 | } |
@@ -137,8 +137,11 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function create($content) |
| 139 | 139 | { |
| 140 | - if (is_array($content)) $paths_list = $content; |
|
| 141 | - else $paths_list = explode(',', $content); |
|
| 140 | + if (is_array($content)) { |
|
| 141 | + $paths_list = $content; |
|
| 142 | + } else { |
|
| 143 | + $paths_list = explode(',', $content); |
|
| 144 | + } |
|
| 142 | 145 | |
| 143 | 146 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 144 | 147 | |
@@ -146,8 +149,9 @@ discard block |
||
| 146 | 149 | $filters = $this->createFilters($options); |
| 147 | 150 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 148 | 151 | |
| 149 | - if (!empty($comment = $this->buildComment($options, null))) |
|
| 150 | - $this->archive->setComment($comment); |
|
| 152 | + if (!empty($comment = $this->buildComment($options, null))) { |
|
| 153 | + $this->archive->setComment($comment); |
|
| 154 | + } |
|
| 151 | 155 | |
| 152 | 156 | // scan filesystem for files list |
| 153 | 157 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -167,16 +171,18 @@ discard block |
||
| 167 | 171 | $localname = $fileToAdd; |
| 168 | 172 | $filename = $fileToAdd; |
| 169 | 173 | |
| 170 | - foreach ($filters as $filter) |
|
| 171 | - call_user_func($filter, $localname, $filename); |
|
| 174 | + foreach ($filters as $filter) { |
|
| 175 | + call_user_func($filter, $localname, $filename); |
|
| 176 | + } |
|
| 172 | 177 | |
| 173 | 178 | $file_header = $this->createFileHeader($localname, $filename); |
| 174 | 179 | if (call_user_func($preAddCallback, $file_header) == 1) { |
| 175 | 180 | // |
| 176 | 181 | // Check for max length > 255 |
| 177 | 182 | // |
| 178 | - if (strlen(basename($file_header->stored_filename)) > 255) |
|
| 179 | - $file_header->status = 'filename_too_long'; |
|
| 183 | + if (strlen(basename($file_header->stored_filename)) > 255) { |
|
| 184 | + $file_header->status = 'filename_too_long'; |
|
| 185 | + } |
|
| 180 | 186 | if (is_file($filename)) { |
| 181 | 187 | $this->archive->addFiles([ |
| 182 | 188 | $file_header->stored_filename => $file_header->filename, |
@@ -248,27 +254,35 @@ discard block |
||
| 248 | 254 | } |
| 249 | 255 | |
| 250 | 256 | // filters initiation |
| 251 | - if (isset($options[PCLZIP_OPT_PATH])) |
|
| 252 | - $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 253 | - else $extractPath = rtrim(getcwd(), '/'); |
|
| 257 | + if (isset($options[PCLZIP_OPT_PATH])) { |
|
| 258 | + $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/'); |
|
| 259 | + } else { |
|
| 260 | + $extractPath = rtrim(getcwd(), '/'); |
|
| 261 | + } |
|
| 254 | 262 | |
| 255 | 263 | $filters = $this->createFilters($options); |
| 256 | 264 | list($preExtractCallback, $postExtractCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_EXTRACT, PCLZIP_CB_POST_EXTRACT); |
| 257 | 265 | $selectFilter = $this->createSelector($options); |
| 258 | 266 | |
| 259 | - if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) |
|
| 260 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 261 | - else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) |
|
| 262 | - $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 263 | - else $anotherOutputFormat = false; |
|
| 267 | + if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) { |
|
| 268 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING; |
|
| 269 | + } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) { |
|
| 270 | + $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT; |
|
| 271 | + } else { |
|
| 272 | + $anotherOutputFormat = false; |
|
| 273 | + } |
|
| 264 | 274 | |
| 265 | - if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) |
|
| 266 | - $doNotReplaceNewer = false; |
|
| 267 | - else $doNotReplaceNewer = true; |
|
| 275 | + if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) { |
|
| 276 | + $doNotReplaceNewer = false; |
|
| 277 | + } else { |
|
| 278 | + $doNotReplaceNewer = true; |
|
| 279 | + } |
|
| 268 | 280 | |
| 269 | - if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) |
|
| 270 | - $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 271 | - else $restrictExtractDir = false; |
|
| 281 | + if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) { |
|
| 282 | + $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]; |
|
| 283 | + } else { |
|
| 284 | + $restrictExtractDir = false; |
|
| 285 | + } |
|
| 272 | 286 | |
| 273 | 287 | $report = array(); |
| 274 | 288 | foreach ($this->listContent() as $file_header) { |
@@ -339,8 +353,10 @@ discard block |
||
| 339 | 353 | // extract content |
| 340 | 354 | else if ($anotherOutputFormat === false) { |
| 341 | 355 | // apply path filters |
| 342 | - foreach ($filters as $filter) call_user_func($filter, |
|
| 356 | + foreach ($filters as $filter) { |
|
| 357 | + call_user_func($filter, |
|
| 343 | 358 | $file_header->stored_filename, $file_header->filename); |
| 359 | + } |
|
| 344 | 360 | // dir extraction process |
| 345 | 361 | if ($file_header->folder) { |
| 346 | 362 | // if dir doesn't exist |
@@ -431,15 +447,19 @@ discard block |
||
| 431 | 447 | */ |
| 432 | 448 | public function add($content) |
| 433 | 449 | { |
| 434 | - if (is_array($content)) $paths_list = $content; |
|
| 435 | - else $paths_list = explode(',', $content); |
|
| 450 | + if (is_array($content)) { |
|
| 451 | + $paths_list = $content; |
|
| 452 | + } else { |
|
| 453 | + $paths_list = explode(',', $content); |
|
| 454 | + } |
|
| 436 | 455 | |
| 437 | 456 | $options = $this->makeOptionsFromArguments(func_get_args()); |
| 438 | 457 | $filters = $this->createFilters($options); |
| 439 | 458 | list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD); |
| 440 | 459 | |
| 441 | - if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) |
|
| 442 | - $this->archive->setComment($comment); |
|
| 460 | + if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) { |
|
| 461 | + $this->archive->setComment($comment); |
|
| 462 | + } |
|
| 443 | 463 | |
| 444 | 464 | // scan filesystem for files list |
| 445 | 465 | return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback); |
@@ -511,8 +531,12 @@ discard block |
||
| 511 | 531 | } |
| 512 | 532 | |
| 513 | 533 | $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging'); |
| 514 | - if (file_exists($tempDir)) unlink($tempDir); |
|
| 515 | - if (!mkdir($tempDir)) return 0; |
|
| 534 | + if (file_exists($tempDir)) { |
|
| 535 | + unlink($tempDir); |
|
| 536 | + } |
|
| 537 | + if (!mkdir($tempDir)) { |
|
| 538 | + return 0; |
|
| 539 | + } |
|
| 516 | 540 | |
| 517 | 541 | // go through archive content list and copy all files |
| 518 | 542 | foreach ($a->getFileNames() as $filename) { |
@@ -541,8 +565,11 @@ discard block |
||
| 541 | 565 | |
| 542 | 566 | call_user_func(function ($directory) { |
| 543 | 567 | foreach (glob($directory.'/*') as $f) { |
| 544 | - if (is_dir($f)) call_user_func(__FUNCTION__, $f); |
|
| 545 | - else unlink($f); |
|
| 568 | + if (is_dir($f)) { |
|
| 569 | + call_user_func(__FUNCTION__, $f); |
|
| 570 | + } else { |
|
| 571 | + unlink($f); |
|
| 572 | + } |
|
| 546 | 573 | } |
| 547 | 574 | }, $tempDir); |
| 548 | 575 | |
@@ -567,18 +594,21 @@ discard block |
||
| 567 | 594 | { |
| 568 | 595 | $filters = array(); |
| 569 | 596 | if (isset($options[PCLZIP_OPT_REMOVE_PATH]) |
| 570 | - && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 571 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 597 | + && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 598 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 572 | 599 | $key = str_replace($key, null, $key); |
| 600 | + } |
|
| 573 | 601 | }; |
| 574 | - if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) |
|
| 575 | - $filters[] = function (&$key, &$value) { |
|
| 602 | + if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) { |
|
| 603 | + $filters[] = function (&$key, &$value) { |
|
| 576 | 604 | $key = basename($key); |
| 605 | + } |
|
| 577 | 606 | }; |
| 578 | - if (isset($options[PCLZIP_OPT_ADD_PATH])) |
|
| 579 | - $filters[] = function (&$key, &$value) use ($options) { |
|
| 607 | + if (isset($options[PCLZIP_OPT_ADD_PATH])) { |
|
| 608 | + $filters[] = function (&$key, &$value) use ($options) { |
|
| 580 | 609 | $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' . |
| 581 | 610 | ltrim($key, '/'); |
| 611 | + } |
|
| 582 | 612 | }; |
| 583 | 613 | return $filters; |
| 584 | 614 | } |
@@ -593,11 +623,13 @@ discard block |
||
| 593 | 623 | { |
| 594 | 624 | $preCallback = $postCallback = function () { return true; }; |
| 595 | 625 | |
| 596 | - if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) |
|
| 597 | - $preCallback = $options[$preCallbackConst]; |
|
| 626 | + if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) { |
|
| 627 | + $preCallback = $options[$preCallbackConst]; |
|
| 628 | + } |
|
| 598 | 629 | |
| 599 | - if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) |
|
| 600 | - $postCallback = $options[$postCallbackConst]; |
|
| 630 | + if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) { |
|
| 631 | + $postCallback = $options[$postCallbackConst]; |
|
| 632 | + } |
|
| 601 | 633 | |
| 602 | 634 | return [$preCallback, $postCallback]; |
| 603 | 635 | } |
@@ -610,7 +642,9 @@ discard block |
||
| 610 | 642 | { |
| 611 | 643 | $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY); |
| 612 | 644 | $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY); |
| 613 | - if (count($values) < count($keys)) $values[] = true; |
|
| 645 | + if (count($values) < count($keys)) { |
|
| 646 | + $values[] = true; |
|
| 647 | + } |
|
| 614 | 648 | return array_combine($keys, $values); |
| 615 | 649 | } |
| 616 | 650 | |
@@ -653,9 +687,12 @@ discard block |
||
| 653 | 687 | $allowedIndexes = array(); |
| 654 | 688 | foreach ($indexes as $rule) { |
| 655 | 689 | $parts = explode('-', $rule); |
| 656 | - if (count($parts) == 1) $allowedIndexes[] = $rule; |
|
| 657 | - else $allowedIndexes = array_merge( |
|
| 690 | + if (count($parts) == 1) { |
|
| 691 | + $allowedIndexes[] = $rule; |
|
| 692 | + } else { |
|
| 693 | + $allowedIndexes = array_merge( |
|
| 658 | 694 | range($parts[0], $parts[1]), $allowedIndexes); |
| 695 | + } |
|
| 659 | 696 | } |
| 660 | 697 | |
| 661 | 698 | return function ($key, $value, $index) use ($allowedIndexes) { |
@@ -730,21 +767,26 @@ discard block |
||
| 730 | 767 | protected function createSelector(array $options) |
| 731 | 768 | { |
| 732 | 769 | // exact matching |
| 733 | - if (isset($options[PCLZIP_OPT_BY_NAME])) |
|
| 734 | - $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 770 | + if (isset($options[PCLZIP_OPT_BY_NAME])) { |
|
| 771 | + $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]); |
|
| 772 | + } |
|
| 735 | 773 | // <ereg> rule |
| 736 | - else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) |
|
| 737 | - $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 774 | + else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) { |
|
| 775 | + $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]); |
|
| 776 | + } |
|
| 738 | 777 | // <preg_match> rule |
| 739 | - else if (isset($options[PCLZIP_OPT_BY_PREG])) |
|
| 740 | - $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 778 | + else if (isset($options[PCLZIP_OPT_BY_PREG])) { |
|
| 779 | + $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]); |
|
| 780 | + } |
|
| 741 | 781 | // index rule |
| 742 | - else if (isset($options[PCLZIP_OPT_BY_INDEX])) |
|
| 743 | - $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 782 | + else if (isset($options[PCLZIP_OPT_BY_INDEX])) { |
|
| 783 | + $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]); |
|
| 784 | + } |
|
| 744 | 785 | // no rule |
| 745 | - else |
|
| 746 | - $selectFilter = function () { |
|
| 786 | + else { |
|
| 787 | + $selectFilter = function () { |
|
| 747 | 788 | return self::SELECT_FILTER_PASS; |
| 789 | + } |
|
| 748 | 790 | }; |
| 749 | 791 | return $selectFilter; |
| 750 | 792 | } |
@@ -780,9 +822,9 @@ discard block |
||
| 780 | 822 | protected function buildComment(array $options, $currentComment) |
| 781 | 823 | { |
| 782 | 824 | $comment = null; |
| 783 | - if (isset($options[PCLZIP_OPT_COMMENT])) |
|
| 784 | - $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 785 | - else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 825 | + if (isset($options[PCLZIP_OPT_COMMENT])) { |
|
| 826 | + $comment = $options[PCLZIP_OPT_COMMENT]; |
|
| 827 | + } else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {; |
|
| 786 | 828 | $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT]; |
| 787 | 829 | } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) { |
| 788 | 830 | $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment; |
@@ -31,11 +31,11 @@ |
||
| 31 | 31 | $archive = $this->getArchive($input, $output); |
| 32 | 32 | |
| 33 | 33 | if (disk_free_space($output_dir) < $archive->getOriginalSize()) { |
| 34 | - throw new \LogicException('Archive size ' . implode($this->formatSize($archive->getOriginalSize())) . ' is more that available on disk ' |
|
| 34 | + throw new \LogicException('Archive size '.implode($this->formatSize($archive->getOriginalSize())).' is more that available on disk ' |
|
| 35 | 35 | . implode($this->formatSize(disk_free_space($output_dir)))); |
| 36 | 36 | } |
| 37 | 37 | $archive->extractFiles($output_dir, $entry_selector, true); |
| 38 | - $output->writeln('<info>Extracted all archive contents (' . implode($this->formatSize($archive->getOriginalSize())) . ')</info>'); |
|
| 38 | + $output->writeln('<info>Extracted all archive contents ('.implode($this->formatSize($archive->getOriginalSize())).')</info>'); |
|
| 39 | 39 | |
| 40 | 40 | return 0; |
| 41 | 41 | } |
@@ -26,15 +26,15 @@ |
||
| 26 | 26 | $file = realpath($input->getArgument('archive')); |
| 27 | 27 | $archive = $this->getArchive($input, $output); |
| 28 | 28 | |
| 29 | - $output->writeln('Filename: ' . $file . ' (changed <comment>' . $this->formatDate(filemtime($file)) . '</comment>)'); |
|
| 30 | - $output->writeln('Type: <info>' . $archive->getFormat() . '</info>, mime <info>' . $archive->getMimeType() . '</info> (via driver <comment>' . $archive->getDriverType() . '</comment>)'); |
|
| 31 | - $output->writeln('Contains: ' . $archive->countFiles() . ' file' . ($archive->countFiles() > 1 ? 's' : null)); |
|
| 29 | + $output->writeln('Filename: '.$file.' (changed <comment>'.$this->formatDate(filemtime($file)).'</comment>)'); |
|
| 30 | + $output->writeln('Type: <info>'.$archive->getFormat().'</info>, mime <info>'.$archive->getMimeType().'</info> (via driver <comment>'.$archive->getDriverType().'</comment>)'); |
|
| 31 | + $output->writeln('Contains: '.$archive->countFiles().' file'.($archive->countFiles() > 1 ? 's' : null)); |
|
| 32 | 32 | $output->writeln('Size:'); |
| 33 | - $output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2))); |
|
| 34 | - $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($archive->getCompressedSize(), 2))); |
|
| 35 | - $output->writeln("\t" . 'ratio: <info>' . round($archive->getOriginalSize() / $archive->getCompressedSize(), 6) . '/1 (' . floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100) . '%</info>)'); |
|
| 33 | + $output->writeln("\t".'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2))); |
|
| 34 | + $output->writeln("\t".'compressed: '.implode(' ', $this->formatSize($archive->getCompressedSize(), 2))); |
|
| 35 | + $output->writeln("\t".'ratio: <info>'.round($archive->getOriginalSize() / $archive->getCompressedSize(), 6).'/1 ('.floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100).'%</info>)'); |
|
| 36 | 36 | if (!empty($comment = $archive->getComment())) |
| 37 | - $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
| 37 | + $output->writeln('Comment: <comment>'.$comment.'</comment>'); |
|
| 38 | 38 | |
| 39 | 39 | return 0; |
| 40 | 40 | } |
@@ -33,8 +33,9 @@ |
||
| 33 | 33 | $output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2))); |
| 34 | 34 | $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($archive->getCompressedSize(), 2))); |
| 35 | 35 | $output->writeln("\t" . 'ratio: <info>' . round($archive->getOriginalSize() / $archive->getCompressedSize(), 6) . '/1 (' . floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100) . '%</info>)'); |
| 36 | - if (!empty($comment = $archive->getComment())) |
|
| 37 | - $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
| 36 | + if (!empty($comment = $archive->getComment())) { |
|
| 37 | + $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | return 0; |
| 40 | 41 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | $entry_selector = $input->getArgument('entrySelector'); |
| 34 | 34 | |
| 35 | 35 | $archive->extractFiles($output_dir, $entry_selector, true); |
| 36 | - $output->writeln('<info>Extracted:</info> ' . implode(', ', $entry_selector) . ' (' . count($entry_selector) . ') file(s)'); |
|
| 36 | + $output->writeln('<info>Extracted:</info> '.implode(', ', $entry_selector).' ('.count($entry_selector).') file(s)'); |
|
| 37 | 37 | |
| 38 | 38 | return 0; |
| 39 | 39 | } |
@@ -33,7 +33,7 @@ |
||
| 33 | 33 | list($archive, $file) = $this->getArchiveAndFile($input, $output); |
| 34 | 34 | |
| 35 | 35 | $archive->deleteFiles($file); |
| 36 | - $output->writeln('<comment>- file "' . $file . '"</comment>'); |
|
| 36 | + $output->writeln('<comment>- file "'.$file.'"</comment>'); |
|
| 37 | 37 | |
| 38 | 38 | return 0; |
| 39 | 39 | } |