@@ -168,7 +168,7 @@ |
||
| 168 | 168 | * @return false|int |
| 169 | 169 | * @throws UnsupportedOperationException |
| 170 | 170 | */ |
| 171 | - public static function createArchive(array $files, $archiveFileName){ |
|
| 171 | + public static function createArchive(array $files, $archiveFileName) { |
|
| 172 | 172 | throw new UnsupportedOperationException(); |
| 173 | 173 | } |
| 174 | 174 | } |
| 175 | 175 | \ No newline at end of file |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $compression = 'lzma2'; |
| 173 | 173 | break; |
| 174 | 174 | case 'z': |
| 175 | - $tar_aname = 'compress.lzw://' . $archiveFileName; |
|
| 175 | + $tar_aname = 'compress.lzw://'.$archiveFileName; |
|
| 176 | 176 | break; |
| 177 | 177 | } |
| 178 | 178 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | LzwStreamWrapper::registerWrapper(); |
| 330 | - $this->tar = new Archive_Tar('compress.lzw://' . $this->archiveFileName); |
|
| 330 | + $this->tar = new Archive_Tar('compress.lzw://'.$this->archiveFileName); |
|
| 331 | 331 | break; |
| 332 | 332 | |
| 333 | 333 | default: |
@@ -141,11 +141,13 @@ discard block |
||
| 141 | 141 | { |
| 142 | 142 | static::checkRequirements(); |
| 143 | 143 | |
| 144 | - if (static::$enabledPharData) |
|
| 145 | - return static::createArchiveForPhar($files, $archiveFileName); |
|
| 144 | + if (static::$enabledPharData) { |
|
| 145 | + return static::createArchiveForPhar($files, $archiveFileName); |
|
| 146 | + } |
|
| 146 | 147 | |
| 147 | - if (static::$enabledPearTar) |
|
| 148 | - return static::createArchiveForPear($files, $archiveFileName); |
|
| 148 | + if (static::$enabledPearTar) { |
|
| 149 | + return static::createArchiveForPear($files, $archiveFileName); |
|
| 150 | + } |
|
| 149 | 151 | |
| 150 | 152 | throw new Exception('Archive_Tar nor PharData not available'); |
| 151 | 153 | } |
@@ -177,21 +179,24 @@ discard block |
||
| 177 | 179 | break; |
| 178 | 180 | } |
| 179 | 181 | |
| 180 | - if (isset($tar_aname)) |
|
| 181 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 182 | - else |
|
| 183 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 182 | + if (isset($tar_aname)) { |
|
| 183 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 184 | + } else { |
|
| 185 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 186 | + } |
|
| 184 | 187 | |
| 185 | 188 | foreach ($files as $localName => $filename) { |
| 186 | 189 | $remove_dir = dirname($filename); |
| 187 | 190 | $add_dir = dirname($localName); |
| 188 | 191 | |
| 189 | 192 | if (is_null($filename)) { |
| 190 | - if ($tar->addString($localName, '') === false) |
|
| 191 | - throw new Exception('Error when adding directory '.$localName.' to archive'); |
|
| 193 | + if ($tar->addString($localName, '') === false) { |
|
| 194 | + throw new Exception('Error when adding directory '.$localName.' to archive'); |
|
| 195 | + } |
|
| 192 | 196 | } else { |
| 193 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 194 | - throw new Exception('Error when adding file '.$filename.' to archive'); |
|
| 197 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 198 | + throw new Exception('Error when adding file '.$filename.' to archive'); |
|
| 199 | + } |
|
| 195 | 200 | } |
| 196 | 201 | } |
| 197 | 202 | $tar = null; |
@@ -279,8 +284,9 @@ discard block |
||
| 279 | 284 | |
| 280 | 285 | $this->archiveFileName = realpath($archiveFileName); |
| 281 | 286 | $this->archiveType = static::detectArchiveType($this->archiveFileName); |
| 282 | - if ($this->archiveType === false) |
|
| 283 | - throw new \Exception('Could not detect type for archive '.$this->archiveFileName); |
|
| 287 | + if ($this->archiveType === false) { |
|
| 288 | + throw new \Exception('Could not detect type for archive '.$this->archiveFileName); |
|
| 289 | + } |
|
| 284 | 290 | $this->open($this->archiveType); |
| 285 | 291 | } |
| 286 | 292 | |
@@ -392,8 +398,9 @@ discard block |
||
| 392 | 398 | */ |
| 393 | 399 | public function isFileExists($fileName) |
| 394 | 400 | { |
| 395 | - if ($this->tar instanceof Archive_Tar) |
|
| 396 | - return isset($this->pearFilesIndex[$fileName]); |
|
| 401 | + if ($this->tar instanceof Archive_Tar) { |
|
| 402 | + return isset($this->pearFilesIndex[$fileName]); |
|
| 403 | + } |
|
| 397 | 404 | |
| 398 | 405 | try { |
| 399 | 406 | $this->tar->offsetGet($fileName); |
@@ -411,14 +418,16 @@ discard block |
||
| 411 | 418 | public function getFileData($fileName) |
| 412 | 419 | { |
| 413 | 420 | if ($this->tar instanceof Archive_Tar) { |
| 414 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 415 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 421 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 422 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 423 | + } |
|
| 416 | 424 | |
| 417 | 425 | $index = $this->pearFilesIndex[$fileName]; |
| 418 | 426 | |
| 419 | 427 | $files_list = $this->tar->listContent(); |
| 420 | - if (!isset($files_list[$index])) |
|
| 421 | - throw new Exception('File '.$fileName.' is not found in Tar archive'); |
|
| 428 | + if (!isset($files_list[$index])) { |
|
| 429 | + throw new Exception('File '.$fileName.' is not found in Tar archive'); |
|
| 430 | + } |
|
| 422 | 431 | |
| 423 | 432 | $data = $files_list[$index]; |
| 424 | 433 | unset($files_list); |
@@ -442,8 +451,9 @@ discard block |
||
| 442 | 451 | public function getFileContent($fileName) |
| 443 | 452 | { |
| 444 | 453 | if ($this->tar instanceof Archive_Tar) { |
| 445 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 446 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 454 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 455 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 456 | + } |
|
| 447 | 457 | |
| 448 | 458 | return $this->tar->extractInString($fileName); |
| 449 | 459 | } |
@@ -460,12 +470,14 @@ discard block |
||
| 460 | 470 | { |
| 461 | 471 | $resource = fopen('php://temp', 'r+'); |
| 462 | 472 | if ($this->tar instanceof Archive_Tar) { |
| 463 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 464 | - throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 473 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 474 | + throw new Exception('File '.$fileName.' is not found in archive files list'); |
|
| 475 | + } |
|
| 465 | 476 | |
| 466 | 477 | fwrite($resource, $this->tar->extractInString($fileName)); |
| 467 | - } else |
|
| 468 | - fwrite($resource, $this->tar->offsetGet($fileName)->getContent()); |
|
| 478 | + } else { |
|
| 479 | + fwrite($resource, $this->tar->offsetGet($fileName)->getContent()); |
|
| 480 | + } |
|
| 469 | 481 | |
| 470 | 482 | rewind($resource); |
| 471 | 483 | return $resource; |
@@ -520,14 +532,16 @@ discard block |
||
| 520 | 532 | */ |
| 521 | 533 | public function deleteFiles(array $files) |
| 522 | 534 | { |
| 523 | - if ($this->tar instanceof Archive_Tar) |
|
| 524 | - throw new UnsupportedOperationException(); |
|
| 535 | + if ($this->tar instanceof Archive_Tar) { |
|
| 536 | + throw new UnsupportedOperationException(); |
|
| 537 | + } |
|
| 525 | 538 | |
| 526 | 539 | $deleted = 0; |
| 527 | 540 | |
| 528 | 541 | foreach ($files as $i => $file) { |
| 529 | - if ($this->tar->delete($file)) |
|
| 530 | - $deleted++; |
|
| 542 | + if ($this->tar->delete($file)) { |
|
| 543 | + $deleted++; |
|
| 544 | + } |
|
| 531 | 545 | } |
| 532 | 546 | |
| 533 | 547 | $this->tar = null; |
@@ -550,11 +564,13 @@ discard block |
||
| 550 | 564 | $remove_dir = dirname($filename); |
| 551 | 565 | $add_dir = dirname($localName); |
| 552 | 566 | if (is_null($filename)) { |
| 553 | - if ($this->tar->addString($localName, "") === false) |
|
| 554 | - return false; |
|
| 567 | + if ($this->tar->addString($localName, "") === false) { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 555 | 570 | } else { |
| 556 | - if ($this->tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 557 | - return false; |
|
| 571 | + if ($this->tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 572 | + return false; |
|
| 573 | + } |
|
| 558 | 574 | $added++; |
| 559 | 575 | } |
| 560 | 576 | } |
@@ -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); |
@@ -80,8 +80,9 @@ discard block |
||
| 80 | 80 | { |
| 81 | 81 | self::checkRequirements(); |
| 82 | 82 | |
| 83 | - if (!file_exists($fileName) || !is_readable($fileName)) |
|
| 84 | - throw new Exception('Could not open file: '.$fileName); |
|
| 83 | + if (!file_exists($fileName) || !is_readable($fileName)) { |
|
| 84 | + throw new Exception('Could not open file: '.$fileName); |
|
| 85 | + } |
|
| 85 | 86 | |
| 86 | 87 | $type = self::detectArchiveType($fileName); |
| 87 | 88 | if (!self::canOpenType($type)) { |
@@ -224,8 +225,9 @@ discard block |
||
| 224 | 225 | $this->type = $type; |
| 225 | 226 | $this->archiveSize = filesize($fileName); |
| 226 | 227 | |
| 227 | - if (!isset(static::$formatHandlers[$type])) |
|
| 228 | - throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 228 | + if (!isset(static::$formatHandlers[$type])) { |
|
| 229 | + throw new Exception('Unsupported archive type: '.$type.' of archive '.$fileName); |
|
| 230 | + } |
|
| 229 | 231 | |
| 230 | 232 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$type]; |
| 231 | 233 | |
@@ -342,8 +344,9 @@ discard block |
||
| 342 | 344 | */ |
| 343 | 345 | public function getFileData($fileName) |
| 344 | 346 | { |
| 345 | - if (!in_array($fileName, $this->files, true)) |
|
| 346 | - return false; |
|
| 347 | + if (!in_array($fileName, $this->files, true)) { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 347 | 350 | |
| 348 | 351 | return $this->archive->getFileData($fileName); |
| 349 | 352 | } |
@@ -358,8 +361,9 @@ discard block |
||
| 358 | 361 | */ |
| 359 | 362 | public function getFileContent($fileName) |
| 360 | 363 | { |
| 361 | - if (!in_array($fileName, $this->files, true)) |
|
| 362 | - return false; |
|
| 364 | + if (!in_array($fileName, $this->files, true)) { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 363 | 367 | |
| 364 | 368 | return $this->archive->getFileContent($fileName); |
| 365 | 369 | } |
@@ -371,8 +375,9 @@ discard block |
||
| 371 | 375 | */ |
| 372 | 376 | public function getFileResource($fileName) |
| 373 | 377 | { |
| 374 | - if (!in_array($fileName, $this->files, true)) |
|
| 375 | - return false; |
|
| 378 | + if (!in_array($fileName, $this->files, true)) { |
|
| 379 | + return false; |
|
| 380 | + } |
|
| 376 | 381 | |
| 377 | 382 | return $this->archive->getFileResource($fileName); |
| 378 | 383 | } |
@@ -388,10 +393,13 @@ discard block |
||
| 388 | 393 | public function extractFiles($outputFolder, $files = null, $expandFilesList = false) |
| 389 | 394 | { |
| 390 | 395 | if ($files !== null) { |
| 391 | - if (is_string($files)) $files = [$files]; |
|
| 396 | + if (is_string($files)) { |
|
| 397 | + $files = [$files]; |
|
| 398 | + } |
|
| 392 | 399 | |
| 393 | - if ($expandFilesList) |
|
| 394 | - $files = self::expandFileList($this->files, $files); |
|
| 400 | + if ($expandFilesList) { |
|
| 401 | + $files = self::expandFileList($this->files, $files); |
|
| 402 | + } |
|
| 395 | 403 | |
| 396 | 404 | return $this->archive->extractFiles($outputFolder, $files); |
| 397 | 405 | } else { |
@@ -412,8 +420,9 @@ discard block |
||
| 412 | 420 | { |
| 413 | 421 | $fileOrFiles = is_string($fileOrFiles) ? [$fileOrFiles] : $fileOrFiles; |
| 414 | 422 | |
| 415 | - if ($expandFilesList && $fileOrFiles !== null) |
|
| 416 | - $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 423 | + if ($expandFilesList && $fileOrFiles !== null) { |
|
| 424 | + $fileOrFiles = self::expandFileList($this->files, $fileOrFiles); |
|
| 425 | + } |
|
| 417 | 426 | |
| 418 | 427 | $result = $this->archive->deleteFiles($fileOrFiles); |
| 419 | 428 | $this->scanArchive(); |
@@ -446,23 +455,27 @@ discard block |
||
| 446 | 455 | */ |
| 447 | 456 | public static function archiveFiles($fileOrFiles, $archiveName, $emulate = false) |
| 448 | 457 | { |
| 449 | - if (file_exists($archiveName)) |
|
| 450 | - throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 458 | + if (file_exists($archiveName)) { |
|
| 459 | + throw new Exception('Archive '.$archiveName.' already exists!'); |
|
| 460 | + } |
|
| 451 | 461 | |
| 452 | 462 | self::checkRequirements(); |
| 453 | 463 | |
| 454 | 464 | $archiveType = self::detectArchiveType($archiveName, false); |
| 455 | 465 | // if (in_array($archiveType, [TarArchive::TAR, TarArchive::TAR_GZIP, TarArchive::TAR_BZIP, TarArchive::TAR_LZMA, TarArchive::TAR_LZW], true)) |
| 456 | 466 | // return TarArchive::archiveFiles($fileOrFiles, $archiveName, $emulate); |
| 457 | - if ($archiveType === false) |
|
| 458 | - return false; |
|
| 467 | + if ($archiveType === false) { |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 459 | 470 | |
| 460 | 471 | $files_list = self::createFilesList($fileOrFiles); |
| 461 | 472 | |
| 462 | 473 | // fake creation: return archive data |
| 463 | 474 | if ($emulate) { |
| 464 | 475 | $totalSize = 0; |
| 465 | - foreach ($files_list as $fn) $totalSize += filesize($fn); |
|
| 476 | + foreach ($files_list as $fn) { |
|
| 477 | + $totalSize += filesize($fn); |
|
| 478 | + } |
|
| 466 | 479 | |
| 467 | 480 | return array( |
| 468 | 481 | 'totalSize' => $totalSize, |
@@ -472,8 +485,9 @@ discard block |
||
| 472 | 485 | ); |
| 473 | 486 | } |
| 474 | 487 | |
| 475 | - if (!isset(static::$formatHandlers[$archiveType])) |
|
| 476 | - throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 488 | + if (!isset(static::$formatHandlers[$archiveType])) { |
|
| 489 | + throw new Exception('Unsupported archive type: '.$archiveType.' of archive '.$archiveName); |
|
| 490 | + } |
|
| 477 | 491 | |
| 478 | 492 | $handler_class = __NAMESPACE__.'\\Formats\\'.static::$formatHandlers[$archiveType]; |
| 479 | 493 | |
@@ -539,8 +553,9 @@ discard block |
||
| 539 | 553 | $newFiles = []; |
| 540 | 554 | foreach ($files as $file) { |
| 541 | 555 | foreach ($archiveFiles as $archiveFile) { |
| 542 | - if (fnmatch($file.'*', $archiveFile)) |
|
| 543 | - $newFiles[] = $archiveFile; |
|
| 556 | + if (fnmatch($file.'*', $archiveFile)) { |
|
| 557 | + $newFiles[] = $archiveFile; |
|
| 558 | + } |
|
| 544 | 559 | } |
| 545 | 560 | } |
| 546 | 561 | return $newFiles; |
@@ -557,26 +572,29 @@ discard block |
||
| 557 | 572 | // passed an extended list |
| 558 | 573 | if (is_array($nodes)) { |
| 559 | 574 | foreach ($nodes as $source => $destination) { |
| 560 | - if (is_numeric($source)) |
|
| 561 | - $source = $destination; |
|
| 575 | + if (is_numeric($source)) { |
|
| 576 | + $source = $destination; |
|
| 577 | + } |
|
| 562 | 578 | |
| 563 | 579 | $destination = rtrim($destination, '/\\*'); |
| 564 | 580 | |
| 565 | 581 | // if is directory |
| 566 | - if (is_dir($source)) |
|
| 567 | - self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 582 | + if (is_dir($source)) { |
|
| 583 | + self::importFilesFromDir(rtrim($source, '/\\*').'/*', |
|
| 568 | 584 | !empty($destination) ? $destination.'/' : null, true, $files); |
| 569 | - else if (is_file($source)) |
|
| 570 | - $files[$destination] = $source; |
|
| 585 | + } else if (is_file($source)) { |
|
| 586 | + $files[$destination] = $source; |
|
| 587 | + } |
|
| 571 | 588 | } |
| 572 | 589 | |
| 573 | 590 | } else if (is_string($nodes)) { // passed one file or directory |
| 574 | 591 | // if is directory |
| 575 | - if (is_dir($nodes)) |
|
| 576 | - self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 592 | + if (is_dir($nodes)) { |
|
| 593 | + self::importFilesFromDir(rtrim($nodes, '/\\*').'/*', null, true, |
|
| 577 | 594 | $files); |
| 578 | - else if (is_file($nodes)) |
|
| 579 | - $files[basename($nodes)] = $nodes; |
|
| 595 | + } else if (is_file($nodes)) { |
|
| 596 | + $files[basename($nodes)] = $nodes; |
|
| 597 | + } |
|
| 580 | 598 | } |
| 581 | 599 | |
| 582 | 600 | return $files; |
@@ -593,8 +611,9 @@ discard block |
||
| 593 | 611 | // $map[$destination] = rtrim($source, '/*'); |
| 594 | 612 | // do not map root archive folder |
| 595 | 613 | |
| 596 | - if ($destination !== null) |
|
| 597 | - $map[$destination] = null; |
|
| 614 | + if ($destination !== null) { |
|
| 615 | + $map[$destination] = null; |
|
| 616 | + } |
|
| 598 | 617 | |
| 599 | 618 | foreach (glob($source, GLOB_MARK) as $node) { |
| 600 | 619 | if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) { |
@@ -613,8 +632,9 @@ discard block |
||
| 613 | 632 | */ |
| 614 | 633 | static public function archiveFile($file, $archiveName) |
| 615 | 634 | { |
| 616 | - if (!is_file($file)) |
|
| 617 | - throw new \InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 635 | + if (!is_file($file)) { |
|
| 636 | + throw new \InvalidArgumentException($file.' is not a valid file to archive'); |
|
| 637 | + } |
|
| 618 | 638 | |
| 619 | 639 | return static::archiveFiles($file, $archiveName) === 1; |
| 620 | 640 | } |
@@ -627,8 +647,9 @@ discard block |
||
| 627 | 647 | */ |
| 628 | 648 | static public function archiveDirectory($directory, $archiveName) |
| 629 | 649 | { |
| 630 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 631 | - throw new \InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 650 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 651 | + throw new \InvalidArgumentException($directory.' is not a valid directory to archive'); |
|
| 652 | + } |
|
| 632 | 653 | |
| 633 | 654 | return static::archiveFiles($directory, $archiveName) > 0; |
| 634 | 655 | } |
@@ -641,8 +662,9 @@ discard block |
||
| 641 | 662 | */ |
| 642 | 663 | public function addFile($file, $inArchiveName = null) |
| 643 | 664 | { |
| 644 | - if (!is_file($file)) |
|
| 645 | - throw new \InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 665 | + if (!is_file($file)) { |
|
| 666 | + throw new \InvalidArgumentException($file.' is not a valid file to add in archive'); |
|
| 667 | + } |
|
| 646 | 668 | |
| 647 | 669 | return ($inArchiveName !== null |
| 648 | 670 | ? $this->addFiles([$file => $inArchiveName]) |
@@ -657,8 +679,9 @@ discard block |
||
| 657 | 679 | */ |
| 658 | 680 | public function addDirectory($directory, $inArchivePath = null) |
| 659 | 681 | { |
| 660 | - if (!is_dir($directory) || !is_readable($directory)) |
|
| 661 | - throw new \InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 682 | + if (!is_dir($directory) || !is_readable($directory)) { |
|
| 683 | + throw new \InvalidArgumentException($directory.' is not a valid directory to add in archive'); |
|
| 684 | + } |
|
| 662 | 685 | |
| 663 | 686 | return ($inArchivePath !== null |
| 664 | 687 | ? $this->addFiles([$directory => $inArchivePath]) |