@@ -57,7 +57,9 @@ discard block |
||
57 | 57 | public static function checkFormatSupport($format) |
58 | 58 | { |
59 | 59 | $availability = class_exists('\Archive_Tar'); |
60 | - if (!$availability) return false; |
|
60 | + if (!$availability) { |
|
61 | + return false; |
|
62 | + } |
|
61 | 63 | switch ($format) { |
62 | 64 | case Formats::TAR: |
63 | 65 | return true; |
@@ -128,21 +130,24 @@ discard block |
||
128 | 130 | break; |
129 | 131 | } |
130 | 132 | |
131 | - if (isset($tar_aname)) |
|
132 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
133 | - else |
|
134 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
133 | + if (isset($tar_aname)) { |
|
134 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
135 | + } else { |
|
136 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
137 | + } |
|
135 | 138 | |
136 | 139 | foreach ($files as $localName => $filename) { |
137 | 140 | $remove_dir = dirname($filename); |
138 | 141 | $add_dir = dirname($localName); |
139 | 142 | |
140 | 143 | if (is_null($filename)) { |
141 | - if ($tar->addString($localName, '') === false) |
|
142 | - throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
144 | + if ($tar->addString($localName, '') === false) { |
|
145 | + throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
146 | + } |
|
143 | 147 | } else { |
144 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
145 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
148 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
149 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
150 | + } |
|
146 | 151 | } |
147 | 152 | } |
148 | 153 | $tar = null; |
@@ -199,8 +204,9 @@ discard block |
||
199 | 204 | continue; |
200 | 205 | } |
201 | 206 | // skip directories |
202 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
203 | - continue; |
|
207 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
208 | + continue; |
|
209 | + } |
|
204 | 210 | $information->files[] = $file['filename']; |
205 | 211 | $information->uncompressedFilesSize += $file['size']; |
206 | 212 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -245,14 +251,16 @@ discard block |
||
245 | 251 | */ |
246 | 252 | public function getFileData($fileName) |
247 | 253 | { |
248 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
249 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
254 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
255 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
256 | + } |
|
250 | 257 | |
251 | 258 | $index = $this->pearFilesIndex[$fileName]; |
252 | 259 | |
253 | 260 | $files_list = $this->tar->listContent(); |
254 | - if (!isset($files_list[$index])) |
|
255 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
261 | + if (!isset($files_list[$index])) { |
|
262 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
263 | + } |
|
256 | 264 | |
257 | 265 | $data = $files_list[$index]; |
258 | 266 | unset($files_list); |
@@ -267,8 +275,9 @@ discard block |
||
267 | 275 | */ |
268 | 276 | public function getFileContent($fileName) |
269 | 277 | { |
270 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
271 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
278 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
279 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
280 | + } |
|
272 | 281 | |
273 | 282 | return $this->tar->extractInString($fileName); |
274 | 283 | } |
@@ -278,8 +287,9 @@ discard block |
||
278 | 287 | */ |
279 | 288 | public function getFileStream($fileName) |
280 | 289 | { |
281 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
282 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
290 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
291 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
292 | + } |
|
283 | 293 | |
284 | 294 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
285 | 295 | } |
@@ -64,8 +64,9 @@ discard block |
||
64 | 64 | public function __construct($archiveFileName, $format, $password = null) |
65 | 65 | { |
66 | 66 | $this->open($archiveFileName); |
67 | - if ($password !== null) |
|
68 | - $this->zip->setPassword($password); |
|
67 | + if ($password !== null) { |
|
68 | + $this->zip->setPassword($password); |
|
69 | + } |
|
69 | 70 | } |
70 | 71 | |
71 | 72 | /** |
@@ -98,8 +99,9 @@ discard block |
||
98 | 99 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
99 | 100 | $file = $this->zip->statIndex($i); |
100 | 101 | // skip directories |
101 | - if (in_array(substr($file['name'], -1), ['/', '\\'], true)) |
|
102 | - continue; |
|
102 | + if (in_array(substr($file['name'], -1), ['/', '\\'], true)) { |
|
103 | + continue; |
|
104 | + } |
|
103 | 105 | $information->files[$i] = $file['name']; |
104 | 106 | $information->compressedFilesSize += $file['comp_size']; |
105 | 107 | $information->uncompressedFilesSize += $file['size']; |
@@ -133,8 +135,9 @@ discard block |
||
133 | 135 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
134 | 136 | $file_name = $this->zip->getNameIndex($i); |
135 | 137 | // skip directories |
136 | - if (in_array(substr($file_name, -1), ['/', '\\'], true)) |
|
137 | - continue; |
|
138 | + if (in_array(substr($file_name, -1), ['/', '\\'], true)) { |
|
139 | + continue; |
|
140 | + } |
|
138 | 141 | $files[] = $file_name; |
139 | 142 | } |
140 | 143 | return $files; |
@@ -171,8 +174,9 @@ discard block |
||
171 | 174 | public function getFileContent($fileName) |
172 | 175 | { |
173 | 176 | $result = $this->zip->getFromName($fileName); |
174 | - if ($result === false) |
|
175 | - throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
177 | + if ($result === false) { |
|
178 | + throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
179 | + } |
|
176 | 180 | return $result; |
177 | 181 | } |
178 | 182 | |
@@ -193,8 +197,9 @@ discard block |
||
193 | 197 | */ |
194 | 198 | public function extractFiles($outputFolder, array $files) |
195 | 199 | { |
196 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
197 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
200 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
201 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
202 | + } |
|
198 | 203 | |
199 | 204 | return count($files); |
200 | 205 | } |
@@ -206,8 +211,9 @@ discard block |
||
206 | 211 | */ |
207 | 212 | public function extractArchive($outputFolder) |
208 | 213 | { |
209 | - if ($this->zip->extractTo($outputFolder) === false) |
|
210 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
214 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
215 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
216 | + } |
|
211 | 217 | |
212 | 218 | return $this->zip->numFiles; |
213 | 219 | } |
@@ -222,8 +228,9 @@ discard block |
||
222 | 228 | { |
223 | 229 | $count = 0; |
224 | 230 | foreach ($files as $file) { |
225 | - if ($this->zip->deleteName($file) === false) |
|
226 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
231 | + if ($this->zip->deleteName($file) === false) { |
|
232 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
233 | + } |
|
227 | 234 | $count++; |
228 | 235 | } |
229 | 236 | |
@@ -246,11 +253,13 @@ discard block |
||
246 | 253 | $added_files = 0; |
247 | 254 | foreach ($files as $localName => $fileName) { |
248 | 255 | if (is_null($fileName)) { |
249 | - if ($this->zip->addEmptyDir($localName) === false) |
|
250 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
256 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
257 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
258 | + } |
|
251 | 259 | } else { |
252 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
253 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
260 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
261 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
262 | + } |
|
254 | 263 | $added_files++; |
255 | 264 | } |
256 | 265 | } |
@@ -296,8 +305,9 @@ discard block |
||
296 | 305 | $zip = new ZipArchive(); |
297 | 306 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
298 | 307 | |
299 | - if ($result !== true) |
|
300 | - throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
308 | + if ($result !== true) { |
|
309 | + throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
310 | + } |
|
301 | 311 | |
302 | 312 | $can_set_compression_level = method_exists($zip, 'setCompressionName'); |
303 | 313 | $can_encrypt = static::canEncrypt(Formats::ZIP); |
@@ -308,11 +318,13 @@ discard block |
||
308 | 318 | |
309 | 319 | foreach ($files as $localName => $fileName) { |
310 | 320 | if ($fileName === null) { |
311 | - if ($zip->addEmptyDir($localName) === false) |
|
312 | - throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
321 | + if ($zip->addEmptyDir($localName) === false) { |
|
322 | + throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
323 | + } |
|
313 | 324 | } else { |
314 | - if ($zip->addFile($fileName, $localName) === false) |
|
315 | - throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
325 | + if ($zip->addFile($fileName, $localName) === false) { |
|
326 | + throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
327 | + } |
|
316 | 328 | if ($can_set_compression_level) { |
317 | 329 | $zip->setCompressionName($localName, $compressionLevelMap[$compressionLevel]); |
318 | 330 | } |
@@ -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; |