@@ -15,7 +15,7 @@ |
||
15 | 15 | { |
16 | 16 | $fp = fopen($file, 'rb'); |
17 | 17 | if (filesize($file) < 18 || strcmp(fread($fp, 2), "\x1f\x8b")) { |
18 | - return false; // Not GZIP format (See RFC 1952) |
|
18 | + return false; // Not GZIP format (See RFC 1952) |
|
19 | 19 | } |
20 | 20 | $method = fread($fp, 1); |
21 | 21 | $flags = fread($fp, 1); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | */ |
12 | 12 | class Lzma extends OneFileDriver |
13 | 13 | { |
14 | - const FORMAT_SUFFIX = 'xz'; |
|
14 | + const FORMAT_SUFFIX = 'xz'; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * @return array |
@@ -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 |
@@ -139,8 +139,8 @@ |
||
139 | 139 | $information->files[] = $can_get_unix_path |
140 | 140 | ? $entry->getUnixPath() |
141 | 141 | : str_replace('\\', '/', $entry->getPath()); |
142 | - $information->compressedFilesSize += (int)$entry->getPackedSize(); |
|
143 | - $information->uncompressedFilesSize += (int)$entry->getSize(); |
|
142 | + $information->compressedFilesSize += (int) $entry->getPackedSize(); |
|
143 | + $information->uncompressedFilesSize += (int) $entry->getSize(); |
|
144 | 144 | } |
145 | 145 | return $information; |
146 | 146 | } |
@@ -58,12 +58,14 @@ discard block |
||
58 | 58 | public static function checkFormatSupport($format) |
59 | 59 | { |
60 | 60 | $available = class_exists('\Archive7z\Archive7z') && Archive7z::getBinaryVersion() !== false; |
61 | - if (!$available) |
|
62 | - return false; |
|
61 | + if (!$available) { |
|
62 | + return false; |
|
63 | + } |
|
63 | 64 | |
64 | 65 | // in 4.0.0 version it was supporting only 7z |
65 | - if (!Archive7z::supportsAllFormats()) |
|
66 | - return $format === Formats::SEVEN_ZIP; |
|
66 | + if (!Archive7z::supportsAllFormats()) { |
|
67 | + return $format === Formats::SEVEN_ZIP; |
|
68 | + } |
|
67 | 69 | |
68 | 70 | switch ($format) { |
69 | 71 | case Formats::SEVEN_ZIP: |
@@ -104,11 +106,13 @@ discard block |
||
104 | 106 | */ |
105 | 107 | public static function getInstallationInstruction() |
106 | 108 | { |
107 | - if (!class_exists('\Archive7z\Archive7z')) |
|
108 | - return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
109 | + if (!class_exists('\Archive7z\Archive7z')) { |
|
110 | + return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
111 | + } |
|
109 | 112 | |
110 | - if (Archive7z::getBinaryVersion() === false) |
|
111 | - return 'install console program p7zip (7za)'; |
|
113 | + if (Archive7z::getBinaryVersion() === false) { |
|
114 | + return 'install console program p7zip (7za)'; |
|
115 | + } |
|
112 | 116 | |
113 | 117 | return null; |
114 | 118 | } |
@@ -121,8 +125,9 @@ discard block |
||
121 | 125 | try { |
122 | 126 | $this->format = $format; |
123 | 127 | $this->sevenZip = new Archive7z($archiveFileName, null, null); |
124 | - if ($password !== null) |
|
125 | - $this->sevenZip->setPassword($password); |
|
128 | + if ($password !== null) { |
|
129 | + $this->sevenZip->setPassword($password); |
|
130 | + } |
|
126 | 131 | } catch (\Archive7z\Exception $e) { |
127 | 132 | throw new Exception('Could not open 7Zip archive: '.$e->getMessage(), $e->getCode(), $e); |
128 | 133 | } |
@@ -140,8 +145,9 @@ discard block |
||
140 | 145 | continue; |
141 | 146 | } |
142 | 147 | |
143 | - if (!isset($can_get_unix_path)) |
|
144 | - $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
148 | + if (!isset($can_get_unix_path)) { |
|
149 | + $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
150 | + } |
|
145 | 151 | |
146 | 152 | $information->files[] = $can_get_unix_path |
147 | 153 | ? $entry->getUnixPath() |
@@ -159,8 +165,9 @@ discard block |
||
159 | 165 | { |
160 | 166 | $files = []; |
161 | 167 | foreach ($this->sevenZip->getEntries() as $entry) { |
162 | - if ($entry->isDirectory()) |
|
163 | - continue; |
|
168 | + if ($entry->isDirectory()) { |
|
169 | + continue; |
|
170 | + } |
|
164 | 171 | $files[] = $entry->getPath(); |
165 | 172 | } |
166 | 173 | return $files; |
@@ -301,8 +308,9 @@ discard block |
||
301 | 308 | public function addFileFromString($inArchiveName, $content) |
302 | 309 | { |
303 | 310 | $tmp_file = tempnam(sys_get_temp_dir(), 'ua'); |
304 | - if (!$tmp_file) |
|
305 | - throw new ArchiveModificationException('Could not create temporarily file'); |
|
311 | + if (!$tmp_file) { |
|
312 | + throw new ArchiveModificationException('Could not create temporarily file'); |
|
313 | + } |
|
306 | 314 | |
307 | 315 | file_put_contents($tmp_file, $content); |
308 | 316 | $this->sevenZip->addEntry($tmp_file, true); |
@@ -352,8 +360,9 @@ discard block |
||
352 | 360 | $total_files = count($files); |
353 | 361 | |
354 | 362 | $seven_zip = new Archive7z($archiveFileName); |
355 | - if ($password !== null) |
|
356 | - $seven_zip->setPassword($password); |
|
363 | + if ($password !== null) { |
|
364 | + $seven_zip->setPassword($password); |
|
365 | + } |
|
357 | 366 | $seven_zip->setCompressionLevel($compressionLevelMap[$compressionLevel]); |
358 | 367 | foreach ($files as $localName => $filename) { |
359 | 368 | if ($filename !== null) { |
@@ -385,8 +394,9 @@ discard block |
||
385 | 394 | Formats::TAR, |
386 | 395 | Formats::LZMA, |
387 | 396 | Formats::ZIP] |
388 | - )) |
|
389 | - return self::canRenameFiles(); |
|
397 | + )) { |
|
398 | + return self::canRenameFiles(); |
|
399 | + } |
|
390 | 400 | |
391 | 401 | return false; |
392 | 402 | } |
@@ -43,8 +43,9 @@ |
||
43 | 43 | $this->compressedSize = $compressedSize; |
44 | 44 | $this->uncompressedSize = $uncompressedSize; |
45 | 45 | $this->modificationTime = $modificationTime; |
46 | - if ($isCompressed === null) |
|
47 | - $isCompressed = $uncompressedSize !== $compressedSize; |
|
46 | + if ($isCompressed === null) { |
|
47 | + $isCompressed = $uncompressedSize !== $compressedSize; |
|
48 | + } |
|
48 | 49 | $this->isCompressed = $isCompressed; |
49 | 50 | $this->comment = $comment; |
50 | 51 | } |
@@ -158,8 +158,9 @@ discard block |
||
158 | 158 | // by file content |
159 | 159 | if ($contentCheck) { |
160 | 160 | $mime_type = mime_content_type($fileName); |
161 | - if (isset(static::$mimeTypes[$mime_type])) |
|
162 | - return static::$mimeTypes[$mime_type]; |
|
161 | + if (isset(static::$mimeTypes[$mime_type])) { |
|
162 | + return static::$mimeTypes[$mime_type]; |
|
163 | + } |
|
163 | 164 | } |
164 | 165 | |
165 | 166 | return false; |
@@ -251,12 +252,14 @@ discard block |
||
251 | 252 | protected static function checkFormatSupport($format, $function) |
252 | 253 | { |
253 | 254 | static::retrieveAllFormats(); |
254 | - if (!static::canOpen($format)) |
|
255 | - return false; |
|
255 | + if (!static::canOpen($format)) { |
|
256 | + return false; |
|
257 | + } |
|
256 | 258 | |
257 | 259 | foreach (static::$formatsSupport[$format] as $driver) { |
258 | - if ($driver::$function($format)) |
|
259 | - return true; |
|
260 | + if ($driver::$function($format)) { |
|
261 | + return true; |
|
262 | + } |
|
260 | 263 | } |
261 | 264 | |
262 | 265 | return false; |
@@ -271,15 +274,18 @@ discard block |
||
271 | 274 | { |
272 | 275 | static::retrieveAllFormats(); |
273 | 276 | |
274 | - if (!static::canOpen($format)) |
|
275 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
277 | + if (!static::canOpen($format)) { |
|
278 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
279 | + } |
|
276 | 280 | |
277 | - if (!$createAbility) |
|
278 | - return static::$formatsSupport[$format][0]; |
|
281 | + if (!$createAbility) { |
|
282 | + return static::$formatsSupport[$format][0]; |
|
283 | + } |
|
279 | 284 | |
280 | 285 | foreach (static::$formatsSupport[$format] as $driver) { |
281 | - if ($driver::canCreateArchive($format)) |
|
282 | - return $driver; |
|
286 | + if ($driver::canCreateArchive($format)) { |
|
287 | + return $driver; |
|
288 | + } |
|
283 | 289 | } |
284 | 290 | |
285 | 291 | return false; |
@@ -24,10 +24,12 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function __construct($archiveFileName, $format, $password = null) |
26 | 26 | { |
27 | - if (static::FORMAT_SUFFIX === null) |
|
28 | - throw new \Exception('Format should be initialized'); |
|
29 | - if ($password !== null) |
|
30 | - throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
27 | + if (static::FORMAT_SUFFIX === null) { |
|
28 | + throw new \Exception('Format should be initialized'); |
|
29 | + } |
|
30 | + if ($password !== null) { |
|
31 | + throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | $this->fileName = $archiveFileName; |
33 | 35 | $this->inArchiveFileName = basename($archiveFileName, '.'.static::FORMAT_SUFFIX); |
@@ -95,8 +97,9 @@ discard block |
||
95 | 97 | public function extractArchive($outputFolder) |
96 | 98 | { |
97 | 99 | $data = $this->getFileContent($this->inArchiveFileName); |
98 | - if ($data === false) |
|
99 | - throw new ArchiveExtractionException('Could not extract archive'); |
|
100 | + if ($data === false) { |
|
101 | + throw new ArchiveExtractionException('Could not extract archive'); |
|
102 | + } |
|
100 | 103 | |
101 | 104 | $size = strlen($data); |
102 | 105 | $written = file_put_contents($outputFolder.$this->inArchiveFileName, $data); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public static function open($fileName, $password = null) |
63 | 63 | { |
64 | 64 | if (!file_exists($fileName) || !is_readable($fileName)) { |
65 | - throw new InvalidArgumentException('Could not open file: ' . $fileName.' is not readable'); |
|
65 | + throw new InvalidArgumentException('Could not open file: '.$fileName.' is not readable'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $format = Formats::detectArchiveFormat($fileName); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | public function getFileData($fileName) |
273 | 273 | { |
274 | 274 | if (!in_array($fileName, $this->files, true)) { |
275 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
275 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | return $this->archive->getFileData($fileName); |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | public function getFileContent($fileName) |
289 | 289 | { |
290 | 290 | if (!in_array($fileName, $this->files, true)) { |
291 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
291 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
292 | 292 | } |
293 | 293 | |
294 | 294 | return $this->archive->getFileContent($fileName); |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | public function getFileStream($fileName) |
305 | 305 | { |
306 | 306 | if (!in_array($fileName, $this->files, true)) { |
307 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
307 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | return $this->archive->getFileStream($fileName); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
560 | 560 | { |
561 | 561 | if (!is_file($file)) { |
562 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
562 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | return static::archiveFiles($file, $archiveName, $compressionLevel, $password) === 1; |
@@ -630,8 +630,8 @@ discard block |
||
630 | 630 | if (is_array($source)) { |
631 | 631 | foreach ($source as $sourceItem) { |
632 | 632 | static::importFilesFromDir( |
633 | - rtrim($sourceItem, '/\\*') . '/*', |
|
634 | - !empty($destination) ? $destination . '/' : null, |
|
633 | + rtrim($sourceItem, '/\\*').'/*', |
|
634 | + !empty($destination) ? $destination.'/' : null, |
|
635 | 635 | true, |
636 | 636 | $files |
637 | 637 | ); |
@@ -639,8 +639,8 @@ discard block |
||
639 | 639 | } else if (is_dir($source)) { |
640 | 640 | // one source for directories |
641 | 641 | static::importFilesFromDir( |
642 | - rtrim($source, '/\\*') . '/*', |
|
643 | - !empty($destination) ? $destination . '/' : null, |
|
642 | + rtrim($source, '/\\*').'/*', |
|
643 | + !empty($destination) ? $destination.'/' : null, |
|
644 | 644 | true, |
645 | 645 | $files |
646 | 646 | ); |
@@ -251,13 +251,15 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function getFileNames($filter = null) |
253 | 253 | { |
254 | - if ($filter === null) |
|
255 | - return $this->files; |
|
254 | + if ($filter === null) { |
|
255 | + return $this->files; |
|
256 | + } |
|
256 | 257 | |
257 | 258 | $result = []; |
258 | 259 | foreach ($this->files as $file) { |
259 | - if (fnmatch($filter, $file)) |
|
260 | - $result[] = $file; |
|
260 | + if (fnmatch($filter, $file)) { |
|
261 | + $result[] = $file; |
|
262 | + } |
|
261 | 263 | } |
262 | 264 | return $result; |
263 | 265 | } |
@@ -384,8 +386,9 @@ discard block |
||
384 | 386 | { |
385 | 387 | $files_list = static::createFilesList($fileOrFiles); |
386 | 388 | |
387 | - if (empty($files_list)) |
|
388 | - throw new EmptyFileListException('Files list is empty!'); |
|
389 | + if (empty($files_list)) { |
|
390 | + throw new EmptyFileListException('Files list is empty!'); |
|
391 | + } |
|
389 | 392 | |
390 | 393 | $result = $this->archive->addFiles($files_list); |
391 | 394 | $this->scanArchive(); |
@@ -404,8 +407,9 @@ discard block |
||
404 | 407 | */ |
405 | 408 | public function addFile($file, $inArchiveName = null) |
406 | 409 | { |
407 | - if (!is_file($file)) |
|
408 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
410 | + if (!is_file($file)) { |
|
411 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
412 | + } |
|
409 | 413 | |
410 | 414 | return ($inArchiveName !== null |
411 | 415 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -438,8 +442,9 @@ discard block |
||
438 | 442 | */ |
439 | 443 | public function addDirectory($directory, $inArchivePath = null) |
440 | 444 | { |
441 | - if (!is_dir($directory) || !is_readable($directory)) |
|
442 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
445 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
446 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
447 | + } |
|
443 | 448 | |
444 | 449 | return ($inArchivePath !== null |
445 | 450 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -463,13 +468,15 @@ discard block |
||
463 | 468 | { |
464 | 469 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
465 | 470 | |
466 | - if ($archiveType === false) |
|
467 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
471 | + if ($archiveType === false) { |
|
472 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
473 | + } |
|
468 | 474 | |
469 | 475 | $files_list = static::createFilesList($fileOrFiles); |
470 | 476 | |
471 | - if (empty($files_list)) |
|
472 | - throw new EmptyFileListException('Files list is empty!'); |
|
477 | + if (empty($files_list)) { |
|
478 | + throw new EmptyFileListException('Files list is empty!'); |
|
479 | + } |
|
473 | 480 | |
474 | 481 | $totalSize = 0; |
475 | 482 | foreach ($files_list as $fn) { |
@@ -521,16 +528,19 @@ discard block |
||
521 | 528 | $fileProgressCallable = null |
522 | 529 | ) |
523 | 530 | { |
524 | - if (file_exists($archiveName)) |
|
525 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
531 | + if (file_exists($archiveName)) { |
|
532 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
533 | + } |
|
526 | 534 | |
527 | 535 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
528 | 536 | |
529 | - if (!Formats::canCreate($info['type'])) |
|
530 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
537 | + if (!Formats::canCreate($info['type'])) { |
|
538 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
539 | + } |
|
531 | 540 | |
532 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
533 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
541 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
542 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
543 | + } |
|
534 | 544 | |
535 | 545 | /** @var BasicDriver $driver */ |
536 | 546 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -578,8 +588,9 @@ discard block |
||
578 | 588 | */ |
579 | 589 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
580 | 590 | { |
581 | - if (!is_dir($directory) || !is_readable($directory)) |
|
582 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
591 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
592 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
593 | + } |
|
583 | 594 | |
584 | 595 | return static::archiveFiles($directory, $archiveName, $compressionLevel, $password) > 0; |
585 | 596 | } |
@@ -615,9 +626,9 @@ discard block |
||
615 | 626 | if (is_array($nodes)) { |
616 | 627 | foreach ($nodes as $destination => $source) { |
617 | 628 | // new format |
618 | - if (is_numeric($destination)) |
|
619 | - $destination = $source; |
|
620 | - else { |
|
629 | + if (is_numeric($destination)) { |
|
630 | + $destination = $source; |
|
631 | + } else { |
|
621 | 632 | // old format |
622 | 633 | if (is_string($source) && !file_exists($source)) { |
623 | 634 | list($destination, $source) = [$source, $destination]; |
@@ -651,11 +662,12 @@ discard block |
||
651 | 662 | |
652 | 663 | } else if (is_string($nodes)) { // passed one file or directory |
653 | 664 | // if is directory |
654 | - if (is_dir($nodes)) |
|
655 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
665 | + if (is_dir($nodes)) { |
|
666 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
656 | 667 | $files); |
657 | - else if (is_file($nodes)) |
|
658 | - $files[basename($nodes)] = $nodes; |
|
668 | + } else if (is_file($nodes)) { |
|
669 | + $files[basename($nodes)] = $nodes; |
|
670 | + } |
|
659 | 671 | } |
660 | 672 | |
661 | 673 | return $files; |
@@ -672,8 +684,9 @@ discard block |
||
672 | 684 | // $map[$destination] = rtrim($source, '/*'); |
673 | 685 | // do not map root archive folder |
674 | 686 | |
675 | - if ($destination !== null) |
|
676 | - $map[$destination] = null; |
|
687 | + if ($destination !== null) { |
|
688 | + $map[$destination] = null; |
|
689 | + } |
|
677 | 690 | |
678 | 691 | foreach (glob($source, GLOB_MARK) as $node) { |
679 | 692 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -29,7 +29,7 @@ |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | if (!empty($previous_comment = $archive->getComment())) { |
32 | - $output->writeln('Comment "' . $previous_comment . '" replaced', OutputInterface::OUTPUT_RAW); |
|
32 | + $output->writeln('Comment "'.$previous_comment.'" replaced', OutputInterface::OUTPUT_RAW); |
|
33 | 33 | } else if ($comment === null) { |
34 | 34 | $output->writeln('Comment deleted', OutputInterface::OUTPUT_RAW); |
35 | 35 | } else { |