@@ -47,7 +47,7 @@ |
||
47 | 47 | |
48 | 48 | public static function getDescription() |
49 | 49 | { |
50 | - return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('. ZipArchive::LIBZIP_VERSION.')' : null); |
|
50 | + return 'adapter for ext-zip'.(extension_loaded('zip') && defined('\ZipArchive::LIBZIP_VERSION') ? ' ('.ZipArchive::LIBZIP_VERSION.')' : null); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public static function getInstallationInstruction() |
@@ -63,8 +63,9 @@ discard block |
||
63 | 63 | public function __construct($archiveFileName, $format, $password = null) |
64 | 64 | { |
65 | 65 | $this->open($archiveFileName); |
66 | - if ($password !== null) |
|
67 | - $this->zip->setPassword($password); |
|
66 | + if ($password !== null) { |
|
67 | + $this->zip->setPassword($password); |
|
68 | + } |
|
68 | 69 | } |
69 | 70 | |
70 | 71 | /** |
@@ -97,8 +98,9 @@ discard block |
||
97 | 98 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
98 | 99 | $file = $this->zip->statIndex($i); |
99 | 100 | // skip directories |
100 | - if (in_array(substr($file['name'], -1), ['/', '\\'], true)) |
|
101 | - continue; |
|
101 | + if (in_array(substr($file['name'], -1), ['/', '\\'], true)) { |
|
102 | + continue; |
|
103 | + } |
|
102 | 104 | $information->files[$i] = $file['name']; |
103 | 105 | $information->compressedFilesSize += $file['comp_size']; |
104 | 106 | $information->uncompressedFilesSize += $file['size']; |
@@ -115,8 +117,9 @@ discard block |
||
115 | 117 | for ($i = 0; $i < $this->zip->numFiles; $i++) { |
116 | 118 | $file_name = $this->zip->getNameIndex($i); |
117 | 119 | // skip directories |
118 | - if (in_array(substr($file_name, -1), ['/', '\\'], true)) |
|
119 | - continue; |
|
120 | + if (in_array(substr($file_name, -1), ['/', '\\'], true)) { |
|
121 | + continue; |
|
122 | + } |
|
120 | 123 | $files[] = $file_name; |
121 | 124 | } |
122 | 125 | return $files; |
@@ -153,8 +156,9 @@ discard block |
||
153 | 156 | public function getFileContent($fileName) |
154 | 157 | { |
155 | 158 | $result = $this->zip->getFromName($fileName); |
156 | - if ($result === false) |
|
157 | - throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
159 | + if ($result === false) { |
|
160 | + throw new Exception('Could not get file information: '.$result.'. May use password?'); |
|
161 | + } |
|
158 | 162 | return $result; |
159 | 163 | } |
160 | 164 | |
@@ -175,8 +179,9 @@ discard block |
||
175 | 179 | */ |
176 | 180 | public function extractFiles($outputFolder, array $files) |
177 | 181 | { |
178 | - if ($this->zip->extractTo($outputFolder, $files) === false) |
|
179 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
182 | + if ($this->zip->extractTo($outputFolder, $files) === false) { |
|
183 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
184 | + } |
|
180 | 185 | |
181 | 186 | return count($files); |
182 | 187 | } |
@@ -188,8 +193,9 @@ discard block |
||
188 | 193 | */ |
189 | 194 | public function extractArchive($outputFolder) |
190 | 195 | { |
191 | - if ($this->zip->extractTo($outputFolder) === false) |
|
192 | - throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
196 | + if ($this->zip->extractTo($outputFolder) === false) { |
|
197 | + throw new ArchiveExtractionException($this->zip->getStatusString(), $this->zip->status); |
|
198 | + } |
|
193 | 199 | |
194 | 200 | return $this->zip->numFiles; |
195 | 201 | } |
@@ -204,8 +210,9 @@ discard block |
||
204 | 210 | { |
205 | 211 | $count = 0; |
206 | 212 | foreach ($files as $file) { |
207 | - if ($this->zip->deleteName($file) === false) |
|
208 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
213 | + if ($this->zip->deleteName($file) === false) { |
|
214 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
215 | + } |
|
209 | 216 | $count++; |
210 | 217 | } |
211 | 218 | |
@@ -228,11 +235,13 @@ discard block |
||
228 | 235 | $added_files = 0; |
229 | 236 | foreach ($files as $localName => $fileName) { |
230 | 237 | if (is_null($fileName)) { |
231 | - if ($this->zip->addEmptyDir($localName) === false) |
|
232 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
238 | + if ($this->zip->addEmptyDir($localName) === false) { |
|
239 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
240 | + } |
|
233 | 241 | } else { |
234 | - if ($this->zip->addFile($fileName, $localName) === false) |
|
235 | - throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
242 | + if ($this->zip->addFile($fileName, $localName) === false) { |
|
243 | + throw new ArchiveModificationException($this->zip->getStatusString(), $this->zip->status); |
|
244 | + } |
|
236 | 245 | $added_files++; |
237 | 246 | } |
238 | 247 | } |
@@ -267,8 +276,9 @@ discard block |
||
267 | 276 | $zip = new ZipArchive(); |
268 | 277 | $result = $zip->open($archiveFileName, ZipArchive::CREATE); |
269 | 278 | |
270 | - if ($result !== true) |
|
271 | - throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
279 | + if ($result !== true) { |
|
280 | + throw new ArchiveCreationException('ZipArchive error: '.$result); |
|
281 | + } |
|
272 | 282 | |
273 | 283 | $can_set_compression_level = method_exists($zip, 'setCompressionName'); |
274 | 284 | $can_encrypt = method_exists($zip, 'setEncryptionName'); |
@@ -279,11 +289,13 @@ discard block |
||
279 | 289 | |
280 | 290 | foreach ($files as $localName => $fileName) { |
281 | 291 | if ($fileName === null) { |
282 | - if ($zip->addEmptyDir($localName) === false) |
|
283 | - throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
292 | + if ($zip->addEmptyDir($localName) === false) { |
|
293 | + throw new ArchiveCreationException('Could not archive directory "'.$localName.'": '.$zip->getStatusString(), $zip->status); |
|
294 | + } |
|
284 | 295 | } else { |
285 | - if ($zip->addFile($fileName, $localName) === false) |
|
286 | - throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
296 | + if ($zip->addFile($fileName, $localName) === false) { |
|
297 | + throw new ArchiveCreationException('Could not archive file "'.$fileName.'": '.$zip->getStatusString(), $zip->status); |
|
298 | + } |
|
287 | 299 | if ($can_set_compression_level) { |
288 | 300 | $zip->setCompressionName($localName, $compressionLevelMap[$compressionLevel]); |
289 | 301 | } |
@@ -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 | } |
@@ -97,11 +97,13 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public static function getInstallationInstruction() |
99 | 99 | { |
100 | - if (!class_exists('\Archive7z\Archive7z')) |
|
101 | - return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
100 | + if (!class_exists('\Archive7z\Archive7z')) { |
|
101 | + return 'install library `gemorroj/archive7z` and console program p7zip (7za)'; |
|
102 | + } |
|
102 | 103 | |
103 | - if (Archive7z::getBinaryVersion() === false) |
|
104 | - return 'install console program p7zip (7za)'; |
|
104 | + if (Archive7z::getBinaryVersion() === false) { |
|
105 | + return 'install console program p7zip (7za)'; |
|
106 | + } |
|
105 | 107 | |
106 | 108 | return null; |
107 | 109 | } |
@@ -114,8 +116,9 @@ discard block |
||
114 | 116 | try { |
115 | 117 | $this->format = $format; |
116 | 118 | $this->sevenZip = new Archive7z($archiveFileName, null, null); |
117 | - if ($password !== null) |
|
118 | - $this->sevenZip->setPassword($password); |
|
119 | + if ($password !== null) { |
|
120 | + $this->sevenZip->setPassword($password); |
|
121 | + } |
|
119 | 122 | } catch (\Archive7z\Exception $e) { |
120 | 123 | throw new Exception('Could not open 7Zip archive: '.$e->getMessage(), $e->getCode(), $e); |
121 | 124 | } |
@@ -133,8 +136,9 @@ discard block |
||
133 | 136 | continue; |
134 | 137 | } |
135 | 138 | |
136 | - if (!isset($can_get_unix_path)) |
|
137 | - $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
139 | + if (!isset($can_get_unix_path)) { |
|
140 | + $can_get_unix_path = method_exists($entry, 'getUnixPath'); |
|
141 | + } |
|
138 | 142 | |
139 | 143 | $information->files[] = $can_get_unix_path |
140 | 144 | ? $entry->getUnixPath() |
@@ -152,8 +156,9 @@ discard block |
||
152 | 156 | { |
153 | 157 | $files = []; |
154 | 158 | foreach ($this->sevenZip->getEntries() as $entry) { |
155 | - if ($entry->isDirectory()) |
|
156 | - continue; |
|
159 | + if ($entry->isDirectory()) { |
|
160 | + continue; |
|
161 | + } |
|
157 | 162 | $files[] = $entry->getPath(); |
158 | 163 | } |
159 | 164 | return $files; |
@@ -294,8 +299,9 @@ discard block |
||
294 | 299 | public function addFileFromString($inArchiveName, $content) |
295 | 300 | { |
296 | 301 | $tmp_file = tempnam(sys_get_temp_dir(), 'ua'); |
297 | - if (!$tmp_file) |
|
298 | - throw new ArchiveModificationException('Could not create temporarily file'); |
|
302 | + if (!$tmp_file) { |
|
303 | + throw new ArchiveModificationException('Could not create temporarily file'); |
|
304 | + } |
|
299 | 305 | |
300 | 306 | file_put_contents($tmp_file, $content); |
301 | 307 | unset($content); |
@@ -325,8 +331,9 @@ discard block |
||
325 | 331 | |
326 | 332 | try { |
327 | 333 | $seven_zip = new Archive7z($archiveFileName); |
328 | - if ($password !== null) |
|
329 | - $seven_zip->setPassword($password); |
|
334 | + if ($password !== null) { |
|
335 | + $seven_zip->setPassword($password); |
|
336 | + } |
|
330 | 337 | $seven_zip->setCompressionLevel($compressionLevelMap[$compressionLevel]); |
331 | 338 | foreach ($files as $localName => $filename) { |
332 | 339 | if ($filename !== null) { |
@@ -355,8 +362,9 @@ discard block |
||
355 | 362 | Formats::TAR, |
356 | 363 | Formats::LZMA, |
357 | 364 | Formats::ZIP] |
358 | - )) |
|
359 | - return self::canRenameFiles(); |
|
365 | + )) { |
|
366 | + return self::canRenameFiles(); |
|
367 | + } |
|
360 | 368 | |
361 | 369 | return false; |
362 | 370 | } |
@@ -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 | } |
@@ -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 | } |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | else { |
299 | 299 | $size = $this->formatSize($len); |
300 | 300 | echo sprintf('Added %s(%1.1f%s) file to %s', |
301 | - $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
|
301 | + $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']).PHP_EOL; |
|
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | if ($archived_files === false) |
333 | 333 | echo 'Error'.PHP_EOL; |
334 | 334 | else |
335 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
335 | + echo 'Created archive '.$args['ARCHIVE'].' with '.$archived_files.' file(s) of total size '.implode('', $this->formatSize(filesize($args['ARCHIVE']))).PHP_EOL; |
|
336 | 336 | } |
337 | 337 | } |
338 | 338 |
@@ -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 | } |
@@ -141,17 +143,18 @@ discard block |
||
141 | 143 | */ |
142 | 144 | public function formatDate($unixtime) |
143 | 145 | { |
144 | - if (strtotime('today') < $unixtime) |
|
145 | - return 'Today, '.date('G:m', $unixtime); |
|
146 | - else if (strtotime('yesterday') < $unixtime) |
|
147 | - return 'Yesterday, '.date('G:m', $unixtime); |
|
148 | - else { |
|
146 | + if (strtotime('today') < $unixtime) { |
|
147 | + return 'Today, '.date('G:m', $unixtime); |
|
148 | + } else if (strtotime('yesterday') < $unixtime) { |
|
149 | + return 'Yesterday, '.date('G:m', $unixtime); |
|
150 | + } else { |
|
149 | 151 | $datetime = new \DateTime(); |
150 | 152 | $datetime->setTimestamp($unixtime); |
151 | - if ($datetime->format('Y') == date('Y')) |
|
152 | - return $datetime->format('d M, G:m'); |
|
153 | - else |
|
154 | - return $datetime->format('d M Y, G:m'); |
|
153 | + if ($datetime->format('Y') == date('Y')) { |
|
154 | + return $datetime->format('d M, G:m'); |
|
155 | + } else { |
|
156 | + return $datetime->format('d M Y, G:m'); |
|
157 | + } |
|
155 | 158 | } |
156 | 159 | } |
157 | 160 | |
@@ -181,25 +184,36 @@ discard block |
||
181 | 184 | $archive = $this->open($args['ARCHIVE'], isset($args['--password']) ? $args['--password'] : null); |
182 | 185 | $output = getcwd(); |
183 | 186 | if (isset($args['--output'])) { |
184 | - if (!is_dir($args['--output'])) |
|
185 | - mkdir($args['--output']); |
|
187 | + if (!is_dir($args['--output'])) { |
|
188 | + mkdir($args['--output']); |
|
189 | + } |
|
186 | 190 | $output = realpath($args['--output']); |
187 | 191 | } |
188 | 192 | |
189 | 193 | if (empty($args['FILES_IN_ARCHIVE']) || $args['FILES_IN_ARCHIVE'] == array('/') || $args['FILES_IN_ARCHIVE'] == array('*')) { |
190 | 194 | $result = $archive->extractFiles($output); |
191 | - if ($result === false) echo 'Error occured'.PHP_EOL; |
|
192 | - else echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
195 | + if ($result === false) { |
|
196 | + echo 'Error occured'.PHP_EOL; |
|
197 | + } else { |
|
198 | + echo 'Extracted '.$result.' file(s) to '.$output.PHP_EOL; |
|
199 | + } |
|
193 | 200 | } else { |
194 | 201 | $extracted = 0; |
195 | 202 | $errored = []; |
196 | 203 | foreach ($args['FILES_IN_ARCHIVE'] as $file) { |
197 | 204 | $result = $archive->extractFiles($output, $file); |
198 | - if ($result === false) $errored[] = $file; |
|
199 | - else $extracted += $result; |
|
205 | + if ($result === false) { |
|
206 | + $errored[] = $file; |
|
207 | + } else { |
|
208 | + $extracted += $result; |
|
209 | + } |
|
210 | + } |
|
211 | + if (!empty($errored)) { |
|
212 | + echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
213 | + } |
|
214 | + if ($extracted > 0) { |
|
215 | + echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
200 | 216 | } |
201 | - if (!empty($errored)) echo 'Errored: '.implode(', ', $errored).PHP_EOL; |
|
202 | - if ($extracted > 0) echo 'Exctracted '.$extracted.' file(s) to '.$output.PHP_EOL; |
|
203 | 217 | } |
204 | 218 | } |
205 | 219 | |
@@ -258,8 +272,9 @@ discard block |
||
258 | 272 | echo 'File '.$file.' is NOT in archive'.PHP_EOL; |
259 | 273 | continue; |
260 | 274 | } |
261 | - if ($archive->deleteFiles($file) === false) |
|
262 | - echo 'Error file '.$file.PHP_EOL; |
|
275 | + if ($archive->deleteFiles($file) === false) { |
|
276 | + echo 'Error file '.$file.PHP_EOL; |
|
277 | + } |
|
263 | 278 | } |
264 | 279 | } |
265 | 280 | |
@@ -272,10 +287,11 @@ discard block |
||
272 | 287 | { |
273 | 288 | $archive = $this->open($args['ARCHIVE']); |
274 | 289 | $added_files = $archive->addFiles($args['FILES_ON_DISK']); |
275 | - if ($added_files === false) |
|
276 | - echo 'Error'.PHP_EOL; |
|
277 | - else |
|
278 | - echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
290 | + if ($added_files === false) { |
|
291 | + echo 'Error'.PHP_EOL; |
|
292 | + } else { |
|
293 | + echo 'Added '.$added_files.' file(s)'.PHP_EOL; |
|
294 | + } |
|
279 | 295 | } |
280 | 296 | |
281 | 297 | /** |
@@ -293,9 +309,9 @@ discard block |
||
293 | 309 | $len = strlen($content); |
294 | 310 | |
295 | 311 | $added_files = $archive->addFileFromString($args['FILE_IN_ARCHIVE'], $content); |
296 | - if ($added_files === false) |
|
297 | - echo 'Error'.PHP_EOL; |
|
298 | - else { |
|
312 | + if ($added_files === false) { |
|
313 | + echo 'Error'.PHP_EOL; |
|
314 | + } else { |
|
299 | 315 | $size = $this->formatSize($len); |
300 | 316 | echo sprintf('Added %s(%1.1f%s) file to %s', |
301 | 317 | $args['FILE_IN_ARCHIVE'], $size[0], $size[1], $args['ARCHIVE']) . PHP_EOL; |
@@ -310,9 +326,9 @@ discard block |
||
310 | 326 | { |
311 | 327 | $password = isset($args['--password']) ? $args['--password'] : null; |
312 | 328 | if (file_exists($args['ARCHIVE'])) { |
313 | - if (is_dir($args['ARCHIVE'])) |
|
314 | - echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
315 | - else { |
|
329 | + if (is_dir($args['ARCHIVE'])) { |
|
330 | + echo $args['ARCHIVE'].' is a directory!'.PHP_EOL; |
|
331 | + } else { |
|
316 | 332 | echo 'File '.$args['ARCHIVE'].' already exists!'.PHP_EOL; |
317 | 333 | } |
318 | 334 | } else { |
@@ -329,10 +345,11 @@ discard block |
||
329 | 345 | } |
330 | 346 | |
331 | 347 | $archived_files = UnifiedArchive::archiveFiles($files, $args['ARCHIVE'], BasicDriver::COMPRESSION_AVERAGE, $password); |
332 | - if ($archived_files === false) |
|
333 | - echo 'Error'.PHP_EOL; |
|
334 | - else |
|
335 | - echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
348 | + if ($archived_files === false) { |
|
349 | + echo 'Error'.PHP_EOL; |
|
350 | + } else { |
|
351 | + echo 'Created archive ' . $args['ARCHIVE'] . ' with ' . $archived_files . ' file(s) of total size ' . implode('', $this->formatSize(filesize($args['ARCHIVE']))) . PHP_EOL; |
|
352 | + } |
|
336 | 353 | } |
337 | 354 | } |
338 | 355 |
@@ -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 current(static::$formatsSupport[$format]); |
|
281 | + if (!$createAbility) { |
|
282 | + return current(static::$formatsSupport[$format]); |
|
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 | return false; |
285 | 291 | } |