@@ -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 |
@@ -25,10 +25,12 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct($archiveFileName, $format, $password = null) |
| 27 | 27 | { |
| 28 | - if (static::FORMAT_SUFFIX === null) |
|
| 29 | - throw new \Exception('Format should be initialized'); |
|
| 30 | - if ($password !== null) |
|
| 31 | - throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 28 | + if (static::FORMAT_SUFFIX === null) { |
|
| 29 | + throw new \Exception('Format should be initialized'); |
|
| 30 | + } |
|
| 31 | + if ($password !== null) { |
|
| 32 | + throw new UnsupportedOperationException(self::FORMAT_SUFFIX.' archive does not support password!'); |
|
| 33 | + } |
|
| 32 | 34 | |
| 33 | 35 | $this->fileName = $archiveFileName; |
| 34 | 36 | $this->inArchiveFileName = basename($archiveFileName, '.'.self::FORMAT_SUFFIX); |
@@ -96,8 +98,9 @@ discard block |
||
| 96 | 98 | public function extractArchive($outputFolder) |
| 97 | 99 | { |
| 98 | 100 | $data = $this->getFileContent($this->inArchiveFileName); |
| 99 | - if ($data === false) |
|
| 100 | - throw new ArchiveExtractionException('Could not extract archive'); |
|
| 101 | + if ($data === false) { |
|
| 102 | + throw new ArchiveExtractionException('Could not extract archive'); |
|
| 103 | + } |
|
| 101 | 104 | |
| 102 | 105 | $size = strlen($data); |
| 103 | 106 | $written = file_put_contents($outputFolder.$this->inArchiveFileName, $data); |
@@ -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 | } |
@@ -57,12 +57,14 @@ discard block |
||
| 57 | 57 | public static function checkFormatSupport($format) |
| 58 | 58 | { |
| 59 | 59 | $available = class_exists('\Archive7z\Archive7z') && Archive7z::getBinaryVersion() !== false; |
| 60 | - if (!$available) |
|
| 61 | - return false; |
|
| 60 | + if (!$available) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 62 | 63 | |
| 63 | 64 | // in 4.0.0 version it was supporting only 7z |
| 64 | - if (!Archive7z::supportsAllFormats()) |
|
| 65 | - return $format === Formats::SEVEN_ZIP; |
|
| 65 | + if (!Archive7z::supportsAllFormats()) { |
|
| 66 | + return $format === Formats::SEVEN_ZIP; |
|
| 67 | + } |
|
| 66 | 68 | |
| 67 | 69 | switch ($format) { |
| 68 | 70 | case Formats::SEVEN_ZIP: |
@@ -103,11 +105,13 @@ discard block |
||
| 103 | 105 | */ |
| 104 | 106 | public static function getInstallationInstruction() |
| 105 | 107 | { |
| 106 | - if (!class_exists('\Archive7z\Archive7z')) |
|
| 107 | - return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
| 108 | + if (!class_exists('\Archive7z\Archive7z')) { |
|
| 109 | + return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
| 110 | + } |
|
| 108 | 111 | |
| 109 | - if (Archive7z::getBinaryVersion() === false) |
|
| 110 | - return 'install console program p7zip (7za)'; |
|
| 112 | + if (Archive7z::getBinaryVersion() === false) { |
|
| 113 | + return 'install console program p7zip (7za)'; |
|
| 114 | + } |
|
| 111 | 115 | |
| 112 | 116 | return null; |
| 113 | 117 | } |
@@ -120,8 +124,9 @@ discard block |
||
| 120 | 124 | try { |
| 121 | 125 | $this->format = $format; |
| 122 | 126 | $this->sevenZip = new Archive7z($archiveFileName, null, null); |
| 123 | - if ($password !== null) |
|
| 124 | - $this->sevenZip->setPassword($password); |
|
| 127 | + if ($password !== null) { |
|
| 128 | + $this->sevenZip->setPassword($password); |
|
| 129 | + } |
|
| 125 | 130 | } catch (\Archive7z\Exception $e) { |
| 126 | 131 | throw new Exception('Could not open 7Zip archive: '.$e->getMessage(), $e->getCode(), $e); |
| 127 | 132 | } |
@@ -139,8 +144,9 @@ discard block |
||
| 139 | 144 | continue; |
| 140 | 145 | } |
| 141 | 146 | |
| 142 | - if (!isset($can_get_unix_path)) |
|
| 143 | - $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
| 147 | + if (!isset($can_get_unix_path)) { |
|
| 148 | + $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
| 149 | + } |
|
| 144 | 150 | |
| 145 | 151 | $information->files[] = $can_get_unix_path |
| 146 | 152 | ? $entry->getUnixPath() |
@@ -158,8 +164,9 @@ discard block |
||
| 158 | 164 | { |
| 159 | 165 | $files = []; |
| 160 | 166 | foreach ($this->sevenZip->getEntries() as $entry) { |
| 161 | - if ($entry->isDirectory()) |
|
| 162 | - continue; |
|
| 167 | + if ($entry->isDirectory()) { |
|
| 168 | + continue; |
|
| 169 | + } |
|
| 163 | 170 | $files[] = $entry->getPath(); |
| 164 | 171 | } |
| 165 | 172 | return $files; |
@@ -300,8 +307,9 @@ discard block |
||
| 300 | 307 | public function addFileFromString($inArchiveName, $content) |
| 301 | 308 | { |
| 302 | 309 | $tmp_file = tempnam(sys_get_temp_dir(), 'ua'); |
| 303 | - if (!$tmp_file) |
|
| 304 | - throw new ArchiveModificationException('Could not create temporarily file'); |
|
| 310 | + if (!$tmp_file) { |
|
| 311 | + throw new ArchiveModificationException('Could not create temporarily file'); |
|
| 312 | + } |
|
| 305 | 313 | |
| 306 | 314 | file_put_contents($tmp_file, $content); |
| 307 | 315 | $this->sevenZip->addEntry($tmp_file, true); |
@@ -330,8 +338,9 @@ discard block |
||
| 330 | 338 | |
| 331 | 339 | try { |
| 332 | 340 | $seven_zip = new Archive7z($archiveFileName); |
| 333 | - if ($password !== null) |
|
| 334 | - $seven_zip->setPassword($password); |
|
| 341 | + if ($password !== null) { |
|
| 342 | + $seven_zip->setPassword($password); |
|
| 343 | + } |
|
| 335 | 344 | $seven_zip->setCompressionLevel($compressionLevelMap[$compressionLevel]); |
| 336 | 345 | foreach ($files as $localName => $filename) { |
| 337 | 346 | if ($filename !== null) { |
@@ -360,8 +369,9 @@ discard block |
||
| 360 | 369 | Formats::TAR, |
| 361 | 370 | Formats::LZMA, |
| 362 | 371 | Formats::ZIP] |
| 363 | - )) |
|
| 364 | - return self::canRenameFiles(); |
|
| 372 | + )) { |
|
| 373 | + return self::canRenameFiles(); |
|
| 374 | + } |
|
| 365 | 375 | |
| 366 | 376 | return false; |
| 367 | 377 | } |
@@ -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; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public static function open($fileName, $password = null) |
| 56 | 56 | { |
| 57 | 57 | if (!file_exists($fileName) || !is_readable($fileName)) { |
| 58 | - throw new InvalidArgumentException('Could not open file: ' . $fileName.' is not readable'); |
|
| 58 | + throw new InvalidArgumentException('Could not open file: '.$fileName.' is not readable'); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $format = Formats::detectArchiveFormat($fileName); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | public function getFileData($fileName) |
| 266 | 266 | { |
| 267 | 267 | if (!in_array($fileName, $this->files, true)) { |
| 268 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 268 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | return $this->archive->getFileData($fileName); |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | public function getFileContent($fileName) |
| 282 | 282 | { |
| 283 | 283 | if (!in_array($fileName, $this->files, true)) { |
| 284 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 284 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | return $this->archive->getFileContent($fileName); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | public function getFileStream($fileName) |
| 298 | 298 | { |
| 299 | 299 | if (!in_array($fileName, $this->files, true)) { |
| 300 | - throw new NonExistentArchiveFileException('File ' . $fileName . ' does not exist in archive'); |
|
| 300 | + throw new NonExistentArchiveFileException('File '.$fileName.' does not exist in archive'); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | return $this->archive->getFileStream($fileName); |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | public static function archiveFile($file, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 539 | 539 | { |
| 540 | 540 | if (!is_file($file)) { |
| 541 | - throw new InvalidArgumentException($file . ' is not a valid file to archive'); |
|
| 541 | + throw new InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | return static::archiveFiles($file, $archiveName, $compressionLevel, $password) === 1; |
@@ -244,13 +244,15 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function getFileNames($filter = null) |
| 246 | 246 | { |
| 247 | - if ($filter === null) |
|
| 248 | - return $this->files; |
|
| 247 | + if ($filter === null) { |
|
| 248 | + return $this->files; |
|
| 249 | + } |
|
| 249 | 250 | |
| 250 | 251 | $result = []; |
| 251 | 252 | foreach ($this->files as $file) { |
| 252 | - if (fnmatch($filter, $file)) |
|
| 253 | - $result[] = $file; |
|
| 253 | + if (fnmatch($filter, $file)) { |
|
| 254 | + $result[] = $file; |
|
| 255 | + } |
|
| 254 | 256 | } |
| 255 | 257 | return $result; |
| 256 | 258 | } |
@@ -377,8 +379,9 @@ discard block |
||
| 377 | 379 | { |
| 378 | 380 | $files_list = static::createFilesList($fileOrFiles); |
| 379 | 381 | |
| 380 | - if (empty($files_list)) |
|
| 381 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 382 | + if (empty($files_list)) { |
|
| 383 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 384 | + } |
|
| 382 | 385 | |
| 383 | 386 | $result = $this->archive->addFiles($files_list); |
| 384 | 387 | $this->scanArchive(); |
@@ -397,8 +400,9 @@ discard block |
||
| 397 | 400 | */ |
| 398 | 401 | public function addFile($file, $inArchiveName = null) |
| 399 | 402 | { |
| 400 | - if (!is_file($file)) |
|
| 401 | - throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 403 | + if (!is_file($file)) { |
|
| 404 | + throw new InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 405 | + } |
|
| 402 | 406 | |
| 403 | 407 | return ($inArchiveName !== null |
| 404 | 408 | ? $this->addFiles([$inArchiveName => $file]) |
@@ -431,8 +435,9 @@ discard block |
||
| 431 | 435 | */ |
| 432 | 436 | public function addDirectory($directory, $inArchivePath = null) |
| 433 | 437 | { |
| 434 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 435 | - throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 438 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 439 | + throw new InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 440 | + } |
|
| 436 | 441 | |
| 437 | 442 | return ($inArchivePath !== null |
| 438 | 443 | ? $this->addFiles([$inArchivePath => $directory]) |
@@ -456,13 +461,15 @@ discard block |
||
| 456 | 461 | { |
| 457 | 462 | $archiveType = Formats::detectArchiveFormat($archiveName, false); |
| 458 | 463 | |
| 459 | - if ($archiveType === false) |
|
| 460 | - throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 464 | + if ($archiveType === false) { |
|
| 465 | + throw new UnsupportedArchiveException('Could not detect archive type for name "'.$archiveName.'"'); |
|
| 466 | + } |
|
| 461 | 467 | |
| 462 | 468 | $files_list = static::createFilesList($fileOrFiles); |
| 463 | 469 | |
| 464 | - if (empty($files_list)) |
|
| 465 | - throw new EmptyFileListException('Files list is empty!'); |
|
| 470 | + if (empty($files_list)) { |
|
| 471 | + throw new EmptyFileListException('Files list is empty!'); |
|
| 472 | + } |
|
| 466 | 473 | |
| 467 | 474 | $totalSize = 0; |
| 468 | 475 | foreach ($files_list as $fn) { |
@@ -507,16 +514,19 @@ discard block |
||
| 507 | 514 | */ |
| 508 | 515 | public static function archiveFiles($fileOrFiles, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 509 | 516 | { |
| 510 | - if (file_exists($archiveName)) |
|
| 511 | - throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 517 | + if (file_exists($archiveName)) { |
|
| 518 | + throw new FileAlreadyExistsException('Archive '.$archiveName.' already exists!'); |
|
| 519 | + } |
|
| 512 | 520 | |
| 513 | 521 | $info = static::prepareForArchiving($fileOrFiles, $archiveName); |
| 514 | 522 | |
| 515 | - if (!Formats::canCreate($info['type'])) |
|
| 516 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 523 | + if (!Formats::canCreate($info['type'])) { |
|
| 524 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$info['type'].' of archive '.$archiveName); |
|
| 525 | + } |
|
| 517 | 526 | |
| 518 | - if ($password !== null && !Formats::canEncrypt($info['type'])) |
|
| 519 | - throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 527 | + if ($password !== null && !Formats::canEncrypt($info['type'])) { |
|
| 528 | + throw new UnsupportedOperationException('Archive type '.$info['type'].' can not be encrypted'); |
|
| 529 | + } |
|
| 520 | 530 | |
| 521 | 531 | /** @var BasicDriver $driver */ |
| 522 | 532 | $driver = Formats::getFormatDriver($info['type'], true); |
@@ -557,8 +567,9 @@ discard block |
||
| 557 | 567 | */ |
| 558 | 568 | public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null) |
| 559 | 569 | { |
| 560 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 561 | - throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 570 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 571 | + throw new InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 572 | + } |
|
| 562 | 573 | |
| 563 | 574 | return static::archiveFiles($directory, $archiveName, $compressionLevel, $password) > 0; |
| 564 | 575 | } |
@@ -594,9 +605,9 @@ discard block |
||
| 594 | 605 | if (is_array($nodes)) { |
| 595 | 606 | foreach ($nodes as $destination => $source) { |
| 596 | 607 | // new format |
| 597 | - if (is_numeric($destination)) |
|
| 598 | - $destination = $source; |
|
| 599 | - else { |
|
| 608 | + if (is_numeric($destination)) { |
|
| 609 | + $destination = $source; |
|
| 610 | + } else { |
|
| 600 | 611 | // old format |
| 601 | 612 | if (!file_exists($source)) { |
| 602 | 613 | list($destination, $source) = [$source, $destination]; |
@@ -606,20 +617,22 @@ discard block |
||
| 606 | 617 | $destination = rtrim($destination, '/\\*'); |
| 607 | 618 | |
| 608 | 619 | // if is directory |
| 609 | - if (is_dir($source)) |
|
| 610 | - static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 620 | + if (is_dir($source)) { |
|
| 621 | + static::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 611 | 622 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 612 | - else if (is_file($source)) |
|
| 613 | - $files[$destination] = $source; |
|
| 623 | + } else if (is_file($source)) { |
|
| 624 | + $files[$destination] = $source; |
|
| 625 | + } |
|
| 614 | 626 | } |
| 615 | 627 | |
| 616 | 628 | } else if (is_string($nodes)) { // passed one file or directory |
| 617 | 629 | // if is directory |
| 618 | - if (is_dir($nodes)) |
|
| 619 | - static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 630 | + if (is_dir($nodes)) { |
|
| 631 | + static::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 620 | 632 | $files); |
| 621 | - else if (is_file($nodes)) |
|
| 622 | - $files[basename($nodes)] = $nodes; |
|
| 633 | + } else if (is_file($nodes)) { |
|
| 634 | + $files[basename($nodes)] = $nodes; |
|
| 635 | + } |
|
| 623 | 636 | } |
| 624 | 637 | |
| 625 | 638 | return $files; |
@@ -636,8 +649,9 @@ discard block |
||
| 636 | 649 | // $map[$destination] = rtrim($source, '/*'); |
| 637 | 650 | // do not map root archive folder |
| 638 | 651 | |
| 639 | - if ($destination !== null) |
|
| 640 | - $map[$destination] = null; |
|
| 652 | + if ($destination !== null) { |
|
| 653 | + $map[$destination] = null; |
|
| 654 | + } |
|
| 641 | 655 | |
| 642 | 656 | foreach (glob($source, GLOB_MARK) as $node) { |
| 643 | 657 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function checkFormats() |
| 32 | 32 | { |
| 33 | 33 | echo "format\topen\tstream\tcreate\tappend\tupdate\tencrypt\tdrivers".PHP_EOL; |
| 34 | - foreach(Formats::getFormatsReport() as $format => $config) { |
|
| 34 | + foreach (Formats::getFormatsReport() as $format => $config) { |
|
| 35 | 35 | echo $format."\t" |
| 36 | 36 | .($config['open'] ? '+' : '-')."\t" |
| 37 | 37 | .($config['stream'] ? '+' : '-')."\t" |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if (!empty($install)) { |
| 56 | 56 | $notInstalled[] = [$driverClass, $description, $install]; |
| 57 | 57 | } else { |
| 58 | - echo ($i++) . '. ' . $driverClass . ' - ' . $description . PHP_EOL; |
|
| 58 | + echo ($i++).'. '.$driverClass.' - '.$description.PHP_EOL; |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | echo PHP_EOL.'Not installed:'.PHP_EOL; |
| 64 | 64 | $i = 1; |
| 65 | 65 | foreach ($notInstalled as $data) { |
| 66 | - echo ($i++) . '. ' . $data[0] . ' - ' . $data[1] . PHP_EOL |
|
| 67 | - . '- ' . $data[2] . PHP_EOL.PHP_EOL; |
|
| 66 | + echo ($i++).'. '.$data[0].' - '.$data[1].PHP_EOL |
|
| 67 | + . '- '.$data[2].PHP_EOL.PHP_EOL; |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | echo str_repeat('-', $width).PHP_EOL; |
| 101 | 101 | foreach ($archive->getFileNames($filter) as $file) { |
| 102 | 102 | $info = $archive->getFileData($file); |
| 103 | - $file_name = strlen($file) > $name_width ? substr($file, 0, $name_width-2).'..' : $file; |
|
| 103 | + $file_name = strlen($file) > $name_width ? substr($file, 0, $name_width - 2).'..' : $file; |
|
| 104 | 104 | echo sprintf('%-'.$name_width.'s | %8s | %8s | %18s'.PHP_EOL, |
| 105 | 105 | $file_name, |
| 106 | 106 | implode(null, $this->formatSize($info->compressedSize, 3)), |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | else { |
| 308 | 308 | $size = $this->formatSize($len); |
| 309 | 309 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 310 | - $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
|
| 310 | + $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']).PHP_EOL; |
|
| 311 | 311 | } |
| 312 | 312 | } |
| 313 | 313 | |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | $archive = UnifiedArchive::open($args['ARCHIVE']); |
| 348 | 348 | $archive->setComment($args['--comment']); |
| 349 | 349 | } |
| 350 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
| 350 | + echo 'Created archive '.$args['ARCHIVE'].' with '.$archived_files.' file(s) of total size '.implode('', $this->formatSize(filesize($args['ARCHIVE']))).PHP_EOL; |
|
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | } |
@@ -15,12 +15,14 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | protected function open($file, $password = null) |
| 17 | 17 | { |
| 18 | - if (!UnifiedArchive::canOpen($file)) |
|
| 19 | - throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 18 | + if (!UnifiedArchive::canOpen($file)) { |
|
| 19 | + throw new Exception('Could not open archive '.$file.'. Try installing suggested packages or run `cam -f` to see formats support.'); |
|
| 20 | + } |
|
| 20 | 21 | |
| 21 | 22 | $archive = UnifiedArchive::open($file, $password); |
| 22 | - if ($archive === null) |
|
| 23 | - throw new Exception('Could not open archive '.$file); |
|
| 23 | + if ($archive === null) { |
|
| 24 | + throw new Exception('Could not open archive '.$file); |
|
| 25 | + } |
|
| 24 | 26 | |
| 25 | 27 | return $archive; |
| 26 | 28 | } |
@@ -145,17 +147,18 @@ discard block |
||
| 145 | 147 | */ |
| 146 | 148 | public function formatDate($unixtime) |
| 147 | 149 | { |
| 148 | - if (strtotime('today') < $unixtime) |
|
| 149 | - return 'Today, '.date('G:m', $unixtime); |
|
| 150 | - else if (strtotime('yesterday') < $unixtime) |
|
| 151 | - return 'Yesterday, '.date('G:m', $unixtime); |
|
| 152 | - else { |
|
| 150 | + if (strtotime('today') < $unixtime) { |
|
| 151 | + return 'Today, '.date('G:m', $unixtime); |
|
| 152 | + } else if (strtotime('yesterday') < $unixtime) { |
|
| 153 | + return 'Yesterday, '.date('G:m', $unixtime); |
|
| 154 | + } else { |
|
| 153 | 155 | $datetime = new \DateTime(); |
| 154 | 156 | $datetime->setTimestamp($unixtime); |
| 155 | - if ($datetime->format('Y') == date('Y')) |
|
| 156 | - return $datetime->format('d M, G:m'); |
|
| 157 | - else |
|
| 158 | - return $datetime->format('d M Y, G:m'); |
|
| 157 | + if ($datetime->format('Y') == date('Y')) { |
|
| 158 | + return $datetime->format('d M, G:m'); |
|
| 159 | + } else { |
|
| 160 | + return $datetime->format('d M Y, G:m'); |
|
| 161 | + } |
|
| 159 | 162 | } |
| 160 | 163 | } |
| 161 | 164 | |
@@ -173,8 +176,9 @@ discard block |
||
| 173 | 176 | echo 'Archive compressed size: '.implode(' ', $this->formatSize($archive->getCompressedSize(), 2)).PHP_EOL; |
| 174 | 177 | echo 'Archive uncompressed size: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2)).PHP_EOL; |
| 175 | 178 | echo 'Archive compression ratio: '.round($archive->getOriginalSize() / $archive->getCompressedSize(), 6).'/1 ('.floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100).'%)'.PHP_EOL; |
| 176 | - if (($comment = $archive->getComment()) !== null) |
|
| 177 | - echo 'Archive comment: '.$comment.PHP_EOL; |
|
| 179 | + if (($comment = $archive->getComment()) !== null) { |
|
| 180 | + echo 'Archive comment: '.$comment.PHP_EOL; |
|
| 181 | + } |
|
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | /** |
@@ -187,25 +191,36 @@ discard block |
||
| 187 | 191 | $archive = $this->open($args['ARCHIVE'], isset($args['--password']) ? $args['--password'] : null); |
| 188 | 192 | $output = getcwd(); |
| 189 | 193 | if (isset($args['--output'])) { |
| 190 | - if (!is_dir($args['--output'])) |
|
| 191 | - mkdir($args['--output']); |
|
| 194 | + if (!is_dir($args['--output'])) { |
|
| 195 | + mkdir($args['--output']); |
|
| 196 | + } |
|
| 192 | 197 | $output = realpath($args['--output']); |
| 193 | 198 | } |
| 194 | 199 | |
| 195 | 200 | if (empty($args['FILES_IN_ARCHIVE']) || $args['FILES_IN_ARCHIVE'] == array('/') || $args['FILES_IN_ARCHIVE'] == array('*')) { |
| 196 | 201 | $result = $archive->extractFiles($output); |
| 197 | - if ($result === false) echo 'Error occured'.PHP_EOL; |
|
| 198 | - else echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 202 | + if ($result === false) { |
|
| 203 | + echo 'Error occured'.PHP_EOL; |
|
| 204 | + } else { |
|
| 205 | + echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
| 206 | + } |
|
| 199 | 207 | } else { |
| 200 | 208 | $extracted = 0; |
| 201 | 209 | $errored = []; |
| 202 | 210 | foreach ($args['FILES_IN_ARCHIVE'] as $file) { |
| 203 | 211 | $result = $archive->extractFiles($output, $file); |
| 204 | - if ($result === false) $errored[] = $file; |
|
| 205 | - else $extracted += $result; |
|
| 212 | + if ($result === false) { |
|
| 213 | + $errored[] = $file; |
|
| 214 | + } else { |
|
| 215 | + $extracted += $result; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + if (!empty($errored)) { |
|
| 219 | + echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 220 | + } |
|
| 221 | + if ($extracted > 0) { |
|
| 222 | + echo 'Extracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 206 | 223 | } |
| 207 | - if (!empty($errored)) echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
| 208 | - if ($extracted > 0) echo 'Extracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
| 209 | 224 | } |
| 210 | 225 | } |
| 211 | 226 | |
@@ -248,8 +263,9 @@ discard block |
||
| 248 | 263 | echo 'Is compressed : '.($info->isCompressed ? 'yes' : 'no').PHP_EOL; |
| 249 | 264 | echo 'Date modification: '.$this->formatDate($info->modificationTime).PHP_EOL; |
| 250 | 265 | $comment = $info->comment; |
| 251 | - if ($comment !== null) |
|
| 252 | - echo 'Comment: '.$comment.PHP_EOL; |
|
| 266 | + if ($comment !== null) { |
|
| 267 | + echo 'Comment: '.$comment.PHP_EOL; |
|
| 268 | + } |
|
| 253 | 269 | } |
| 254 | 270 | } |
| 255 | 271 | |
@@ -267,8 +283,9 @@ discard block |
||
| 267 | 283 | echo 'File '.$file.' is NOT in archive'.PHP_EOL; |
| 268 | 284 | continue; |
| 269 | 285 | } |
| 270 | - if ($archive->deleteFiles($file) === false) |
|
| 271 | - echo 'Error file '.$file.PHP_EOL; |
|
| 286 | + if ($archive->deleteFiles($file) === false) { |
|
| 287 | + echo 'Error file '.$file.PHP_EOL; |
|
| 288 | + } |
|
| 272 | 289 | } |
| 273 | 290 | } |
| 274 | 291 | |
@@ -281,10 +298,11 @@ discard block |
||
| 281 | 298 | { |
| 282 | 299 | $archive = $this->open($args['ARCHIVE']); |
| 283 | 300 | $added_files = $archive->addFiles($args['FILES_ON_DISK']); |
| 284 | - if ($added_files === false) |
|
| 285 | - echo 'Error'.PHP_EOL; |
|
| 286 | - else |
|
| 287 | - echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 301 | + if ($added_files === false) { |
|
| 302 | + echo 'Error'.PHP_EOL; |
|
| 303 | + } else { |
|
| 304 | + echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
| 305 | + } |
|
| 288 | 306 | } |
| 289 | 307 | |
| 290 | 308 | /** |
@@ -302,9 +320,9 @@ discard block |
||
| 302 | 320 | $len = strlen($content); |
| 303 | 321 | |
| 304 | 322 | $added_files = $archive->addFileFromString($args['FILE_IN_ARCHIVE'], $content); |
| 305 | - if ($added_files === false) |
|
| 306 | - echo 'Error'.PHP_EOL; |
|
| 307 | - else { |
|
| 323 | + if ($added_files === false) { |
|
| 324 | + echo 'Error'.PHP_EOL; |
|
| 325 | + } else { |
|
| 308 | 326 | $size = $this->formatSize($len); |
| 309 | 327 | echo sprintf('Added %s(%1.1f%s) file to %s', |
| 310 | 328 | $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
@@ -321,9 +339,9 @@ discard block |
||
| 321 | 339 | $compression_level = isset($args['--compressionLevel']) ? $args['--compressionLevel'] : BasicDriver::COMPRESSION_AVERAGE; |
| 322 | 340 | |
| 323 | 341 | if (file_exists($args['ARCHIVE'])) { |
| 324 | - if (is_dir($args['ARCHIVE'])) |
|
| 325 | - echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 326 | - else { |
|
| 342 | + if (is_dir($args['ARCHIVE'])) { |
|
| 343 | + echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
| 344 | + } else { |
|
| 327 | 345 | echo 'File '.$args['ARCHIVE'].' already exists!'.PHP_EOL; |
| 328 | 346 | } |
| 329 | 347 | } else { |
@@ -340,9 +358,9 @@ discard block |
||
| 340 | 358 | } |
| 341 | 359 | |
| 342 | 360 | $archived_files = UnifiedArchive::archiveFiles($files, $args['ARCHIVE'], $compression_level, $password); |
| 343 | - if ($archived_files === false) |
|
| 344 | - echo 'Error'.PHP_EOL; |
|
| 345 | - else { |
|
| 361 | + if ($archived_files === false) { |
|
| 362 | + echo 'Error'.PHP_EOL; |
|
| 363 | + } else { |
|
| 346 | 364 | if (isset($args['--comment'])) { |
| 347 | 365 | $archive = UnifiedArchive::open($args['ARCHIVE']); |
| 348 | 366 | $archive->setComment($args['--comment']); |
@@ -377,12 +395,14 @@ discard block |
||
| 377 | 395 | |
| 378 | 396 | if (function_exists('shell_exec')) { |
| 379 | 397 | // try for bash |
| 380 | - if (is_numeric($bash_width = trim(shell_exec('tput cols')))) |
|
| 381 | - return $bash_width; |
|
| 398 | + if (is_numeric($bash_width = trim(shell_exec('tput cols')))) { |
|
| 399 | + return $bash_width; |
|
| 400 | + } |
|
| 382 | 401 | |
| 383 | 402 | // try for windows |
| 384 | - if (!empty($win_width_val = trim(shell_exec('mode con'))) && preg_match('~columns: (\d+)~i', $win_width_val, $win_width)) |
|
| 385 | - return $win_width[1]; |
|
| 403 | + if (!empty($win_width_val = trim(shell_exec('mode con'))) && preg_match('~columns: (\d+)~i', $win_width_val, $win_width)) { |
|
| 404 | + return $win_width[1]; |
|
| 405 | + } |
|
| 386 | 406 | } |
| 387 | 407 | |
| 388 | 408 | return 80; |