@@ -17,7 +17,7 @@ |
||
17 | 17 | private static $AVERAGE_COMPRESSION_RATIO = 2; |
18 | 18 | public static $forceTmpFile = false; |
19 | 19 | /** High limit. unit: MBytes. |
20 | - */ |
|
20 | + */ |
|
21 | 21 | public static $highLimit = 512; |
22 | 22 | |
23 | 23 | private $mode; |
@@ -237,8 +237,8 @@ |
||
237 | 237 | if ($code == 0 || $code == 2 || is_null($code)) { |
238 | 238 | // rewrite original file |
239 | 239 | if (rename($this->tmp2, $this->path) !== true) { |
240 | - throw new \RuntimeException(__FILE__ . ', line ' . __LINE__ . |
|
241 | - ': Could not replace original file ' . $this->path); |
|
240 | + throw new \RuntimeException(__FILE__.', line '.__LINE__. |
|
241 | + ': Could not replace original file '.$this->path); |
|
242 | 242 | } |
243 | 243 | } else { |
244 | 244 | throw new \RuntimeException(__FILE__.', line '.__LINE__. |
@@ -18,8 +18,9 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public static function registerWrapper() |
20 | 20 | { |
21 | - if (!self::$registered) |
|
22 | - stream_wrapper_register('compress.lzw', __CLASS__); |
|
21 | + if (!self::$registered) { |
|
22 | + stream_wrapper_register('compress.lzw', __CLASS__); |
|
23 | + } |
|
23 | 24 | self::$registered = true; |
24 | 25 | } |
25 | 26 | |
@@ -50,12 +51,14 @@ discard block |
||
50 | 51 | { |
51 | 52 | // check for compress & uncompress utility |
52 | 53 | $this->checkBinary(); |
53 | - if (self::$installed === false) |
|
54 | - throw new \Exception('compress and uncompress commands are required'); |
|
54 | + if (self::$installed === false) { |
|
55 | + throw new \Exception('compress and uncompress commands are required'); |
|
56 | + } |
|
55 | 57 | |
56 | 58 | $schema = 'compress.lzw://'; |
57 | - if (strncasecmp($schema, $path, strlen($schema)) == 0) |
|
58 | - $path = substr($path, strlen($schema)); |
|
59 | + if (strncasecmp($schema, $path, strlen($schema)) == 0) { |
|
60 | + $path = substr($path, strlen($schema)); |
|
61 | + } |
|
59 | 62 | |
60 | 63 | if (file_exists($path)) { |
61 | 64 | $this->path = realpath($path); |
@@ -69,14 +72,16 @@ discard block |
||
69 | 72 | $this->read(); |
70 | 73 | } else { |
71 | 74 | $prefix = basename(__FILE__, '.php'); |
72 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
73 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
75 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
76 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
74 | 77 | ': Could not create temporary file in '. |
75 | 78 | sys_get_temp_dir()); |
76 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
77 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
79 | + } |
|
80 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
81 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
78 | 82 | ': Could not create temporary file in '. |
79 | 83 | sys_get_temp_dir()); |
84 | + } |
|
80 | 85 | $this->tmp = $tmp; |
81 | 86 | $this->tmp2 = $tmp2; |
82 | 87 | $this->read(); |
@@ -85,14 +90,16 @@ discard block |
||
85 | 90 | $this->path = $path; |
86 | 91 | if (self::$forceTmpFile) { |
87 | 92 | $prefix = basename(__FILE__, '.php'); |
88 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
89 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
93 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
94 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
90 | 95 | ': Could not create temporary file in '. |
91 | 96 | sys_get_temp_dir()); |
92 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
93 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
97 | + } |
|
98 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
99 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
94 | 100 | ': Could not create temporary file in '. |
95 | 101 | sys_get_temp_dir()); |
102 | + } |
|
96 | 103 | $this->tmp = $tmp; |
97 | 104 | $this->tmp2 = $tmp2; |
98 | 105 | $this->pointer = 0; |
@@ -271,7 +278,9 @@ discard block |
||
271 | 278 | } |
272 | 279 | if ($this->tmp !== null) { |
273 | 280 | unlink($this->tmp); |
274 | - if (file_exists($this->tmp2)) unlink($this->tmp2); |
|
281 | + if (file_exists($this->tmp2)) { |
|
282 | + unlink($this->tmp2); |
|
283 | + } |
|
275 | 284 | } else { |
276 | 285 | $this->data = null; |
277 | 286 | $this->dataSize = 0; |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | */ |
11 | 11 | public static function getBinaryVersion() |
12 | 12 | { |
13 | - if (method_exists(__CLASS__, 'makeBinary7z')) |
|
14 | - try { |
|
13 | + if (method_exists(__CLASS__, 'makeBinary7z')) { |
|
14 | + try { |
|
15 | 15 | $binary = static::makeBinary7z(); |
16 | + } |
|
16 | 17 | } catch (\Exception $e) { |
17 | 18 | return false; |
18 | - } |
|
19 | - else { |
|
19 | + } else { |
|
20 | 20 | // some hack for gemorroj/archive7z 4.x version |
21 | 21 | try { |
22 | 22 | $seven_zip = new self(null); |
@@ -29,8 +29,9 @@ discard block |
||
29 | 29 | |
30 | 30 | $process = new Process([str_replace('\\', '/', $binary)]); |
31 | 31 | $result = $process->mustRun()->getOutput(); |
32 | - if (!preg_match('~7-Zip (\([a-z]\) )?(\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) |
|
33 | - return false; |
|
32 | + if (!preg_match('~7-Zip (\([a-z]\) )?(\[[\d]+\] )?(?<version>\d+\.\d+)~i', $result, $version)) { |
|
33 | + return false; |
|
34 | + } |
|
34 | 35 | |
35 | 36 | return $version['version']; |
36 | 37 | } |
@@ -203,8 +203,9 @@ |
||
203 | 203 | $deleted = 0; |
204 | 204 | |
205 | 205 | foreach ($files as $i => $file) { |
206 | - if ($this->tar->delete($file)) |
|
207 | - $deleted++; |
|
206 | + if ($this->tar->delete($file)) { |
|
207 | + $deleted++; |
|
208 | + } |
|
208 | 209 | } |
209 | 210 | |
210 | 211 | $this->tar = null; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function getFileStream($fileName) |
211 | 211 | { |
212 | - return fopen('phar://'.$this->fileName . '/' . $fileName, 'rb'); |
|
212 | + return fopen('phar://'.$this->fileName.'/'.$fileName, 'rb'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ) |
301 | 301 | { |
302 | 302 | if ($password !== null) { |
303 | - throw new UnsupportedOperationException('Driver (' . __CLASS__ . ') could not encrypt an archive'); |
|
303 | + throw new UnsupportedOperationException('Driver ('.__CLASS__.') could not encrypt an archive'); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | if ($fileProgressCallable !== null && !is_callable($fileProgressCallable)) { |
@@ -327,13 +327,13 @@ discard block |
||
327 | 327 | break; |
328 | 328 | } |
329 | 329 | |
330 | - $destination_file = $basename . '.' . ($archiveFormat === Formats::ZIP ? 'zip' : 'tar'); |
|
330 | + $destination_file = $basename.'.'.($archiveFormat === Formats::ZIP ? 'zip' : 'tar'); |
|
331 | 331 | // if compression used and there is .tar archive with that's name, |
332 | 332 | // use temp file |
333 | - if ($compression !== null && file_exists($basename . '.' . ($archiveFormat === Formats::ZIP ? 'zip' : 'tar'))) { |
|
333 | + if ($compression !== null && file_exists($basename.'.'.($archiveFormat === Formats::ZIP ? 'zip' : 'tar'))) { |
|
334 | 334 | $temp_basename = tempnam(sys_get_temp_dir(), 'tar-archive'); |
335 | 335 | unlink($temp_basename); |
336 | - $destination_file = $temp_basename. '.' . ($archiveFormat === Formats::ZIP ? 'zip' : 'tar'); |
|
336 | + $destination_file = $temp_basename.'.'.($archiveFormat === Formats::ZIP ? 'zip' : 'tar'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | $tar = new PharData( |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | |
383 | 383 | // it temp file was used, rename it to destination archive name |
384 | 384 | if (isset($temp_basename)) { |
385 | - rename($temp_basename . '.' . $ext, $archiveFileName); |
|
385 | + rename($temp_basename.'.'.$ext, $archiveFileName); |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | return count($files); |
@@ -100,7 +100,9 @@ discard block |
||
100 | 100 | { |
101 | 101 | $information = new ArchiveInformation(); |
102 | 102 | foreach ($this->rar->getEntries() as $i => $entry) { |
103 | - if ($entry->isDirectory()) continue; |
|
103 | + if ($entry->isDirectory()) { |
|
104 | + continue; |
|
105 | + } |
|
104 | 106 | $information->files[] = $entry->getName(); |
105 | 107 | $information->compressedFilesSize += $entry->getPackedSize(); |
106 | 108 | $information->uncompressedFilesSize += $entry->getUnpackedSize(); |
@@ -115,7 +117,9 @@ discard block |
||
115 | 117 | { |
116 | 118 | $files = []; |
117 | 119 | foreach ($this->rar->getEntries() as $i => $entry) { |
118 | - if ($entry->isDirectory()) continue; |
|
120 | + if ($entry->isDirectory()) { |
|
121 | + continue; |
|
122 | + } |
|
119 | 123 | $files[] = $entry->getName(); |
120 | 124 | } |
121 | 125 | return $files; |
@@ -151,7 +155,9 @@ discard block |
||
151 | 155 | public function getFileContent($fileName) |
152 | 156 | { |
153 | 157 | $entry = $this->rar->getEntry($fileName); |
154 | - if ($entry->isDirectory()) return false; |
|
158 | + if ($entry->isDirectory()) { |
|
159 | + return false; |
|
160 | + } |
|
155 | 161 | return stream_get_contents($entry->getStream()); |
156 | 162 | } |
157 | 163 | |
@@ -163,7 +169,9 @@ discard block |
||
163 | 169 | public function getFileStream($fileName) |
164 | 170 | { |
165 | 171 | $entry = $this->rar->getEntry($fileName); |
166 | - if ($entry->isDirectory()) return false; |
|
172 | + if ($entry->isDirectory()) { |
|
173 | + return false; |
|
174 | + } |
|
167 | 175 | return $entry->getStream(); |
168 | 176 | } |
169 | 177 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public static function getDescription() |
23 | 23 | { |
24 | - return 'adapter for ext-rar' . (self::isInstalled() ? ' (' . phpversion('rar') . ')' : null); |
|
24 | + return 'adapter for ext-rar'.(self::isInstalled() ? ' ('.phpversion('rar').')' : null); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function getInstallationInstruction() |
31 | 31 | { |
32 | - return 'install [rar] extension.' . "\n" . 'Can be installed with pecl: `pecl install rar`'; |
|
32 | + return 'install [rar] extension.'."\n".'Can be installed with pecl: `pecl install rar`'; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | protected function open($archiveFileName, $password) |
82 | 82 | { |
83 | - $this->rar = \RarArchive::open($archiveFileName, $password, function ($vol) { |
|
83 | + $this->rar = \RarArchive::open($archiveFileName, $password, function($vol) { |
|
84 | 84 | throw new Exception('Could not open volumed Rar archive'); |
85 | 85 | }); |
86 | 86 | $this->rar->setAllowBroken(true); |
@@ -29,7 +29,7 @@ |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | if (!empty($previous_comment = $archive->getComment())) { |
32 | - $output->writeln('Comment "' . $previous_comment . '" replaced', OutputInterface::OUTPUT_RAW); |
|
32 | + $output->writeln('Comment "'.$previous_comment.'" replaced', OutputInterface::OUTPUT_RAW); |
|
33 | 33 | } else if ($comment === null) { |
34 | 34 | $output->writeln('Comment deleted', OutputInterface::OUTPUT_RAW); |
35 | 35 | } else { |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | if (empty($destination)) { |
49 | 49 | throw new \LogicException('Source and destination can not be empty'); |
50 | 50 | } |
51 | - $output->writeln('<info>Read ' . $data_size . ' from input</info>'); |
|
51 | + $output->writeln('<info>Read '.$data_size.' from input</info>'); |
|
52 | 52 | } else { |
53 | 53 | $data_size = filesize($source); |
54 | 54 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | } |
76 | 76 | if ($added_files === 1) { |
77 | 77 | $details = $archive->getFileData($destination); |
78 | - $output->writeln('Added <comment>' . $source . '</comment>(' |
|
79 | - . implode($this->formatSize($data_size)) . ') as ' |
|
80 | - . $destination . ' (' |
|
78 | + $output->writeln('Added <comment>'.$source.'</comment>(' |
|
79 | + . implode($this->formatSize($data_size)).') as ' |
|
80 | + . $destination.' (' |
|
81 | 81 | . implode($this->formatSize($details->compressedSize)) |
82 | 82 | . ')'); |
83 | 83 | } |
@@ -31,18 +31,18 @@ |
||
31 | 31 | $detect_mimetype = $input->getOption('detect-mimetype'); |
32 | 32 | |
33 | 33 | $details = $archive->getFileData($file); |
34 | - $output->writeln('File <info>' . $file . '</info>'); |
|
34 | + $output->writeln('File <info>'.$file.'</info>'); |
|
35 | 35 | if ($detect_mimetype) { |
36 | - $output->writeln('Mime type: <info>' . $this->getMimeTypeByStream($archive->getFileStream($file)).'</info>'); |
|
36 | + $output->writeln('Mime type: <info>'.$this->getMimeTypeByStream($archive->getFileStream($file)).'</info>'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $output->writeln('Size:'); |
40 | - $output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($details->uncompressedSize, 2))); |
|
41 | - $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($details->compressedSize, 2))); |
|
42 | - $output->writeln("\t" . 'ratio: <info>' . round($details->uncompressedSize / $details->compressedSize, 6) . '/1 (' . floor($details->compressedSize / $details->uncompressedSize * 100) . '%</info>)'); |
|
43 | - $output->writeln('Modificated: ' . $this->formatDate($details->modificationTime)); |
|
40 | + $output->writeln("\t".'uncompressed: '.implode(' ', $this->formatSize($details->uncompressedSize, 2))); |
|
41 | + $output->writeln("\t".'compressed: '.implode(' ', $this->formatSize($details->compressedSize, 2))); |
|
42 | + $output->writeln("\t".'ratio: <info>'.round($details->uncompressedSize / $details->compressedSize, 6).'/1 ('.floor($details->compressedSize / $details->uncompressedSize * 100).'%</info>)'); |
|
43 | + $output->writeln('Modificated: '.$this->formatDate($details->modificationTime)); |
|
44 | 44 | if (!empty($comment = $details->comment)) |
45 | - $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
45 | + $output->writeln('Comment: <comment>'.$comment.'</comment>'); |
|
46 | 46 | |
47 | 47 | if (empty($input->getArgument('file'))) { |
48 | 48 | $helper = $this->getHelper('question'); |
@@ -41,8 +41,9 @@ |
||
41 | 41 | $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($details->compressedSize, 2))); |
42 | 42 | $output->writeln("\t" . 'ratio: <info>' . round($details->uncompressedSize / $details->compressedSize, 6) . '/1 (' . floor($details->compressedSize / $details->uncompressedSize * 100) . '%</info>)'); |
43 | 43 | $output->writeln('Modificated: ' . $this->formatDate($details->modificationTime)); |
44 | - if (!empty($comment = $details->comment)) |
|
45 | - $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
44 | + if (!empty($comment = $details->comment)) { |
|
45 | + $output->writeln('Comment: <comment>' . $comment . '</comment>'); |
|
46 | + } |
|
46 | 47 | |
47 | 48 | if (empty($input->getArgument('file'))) { |
48 | 49 | $helper = $this->getHelper('question'); |
@@ -88,7 +88,7 @@ |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | if ($sort !== null) { |
91 | - usort($rows, function (array $a, array $b) use ($sort_field) { |
|
91 | + usort($rows, function(array $a, array $b) use ($sort_field) { |
|
92 | 92 | if ($a[$sort_field] > $b[$sort_field]) { |
93 | 93 | return 1; |
94 | 94 | } |
@@ -37,9 +37,9 @@ |
||
37 | 37 | $question = new ChoiceQuestion('Which file', $files); |
38 | 38 | $file = $helper->ask($input, $output, $question); |
39 | 39 | } else if (!in_array($file, $files, true)) { |
40 | - throw new \InvalidArgumentException('File "' . $file . '" not found in archive'); |
|
40 | + throw new \InvalidArgumentException('File "'.$file.'" not found in archive'); |
|
41 | 41 | } |
42 | - $output->writeln('<comment>Selecting file ' . $file . '</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
42 | + $output->writeln('<comment>Selecting file '.$file.'</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
43 | 43 | |
44 | 44 | return [$archive, $file]; |
45 | 45 | } |