@@ -11,8 +11,9 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public static function registerWrapper() |
| 13 | 13 | { |
| 14 | - if (!self::$registered) |
|
| 15 | - stream_wrapper_register('compress.lzw', __CLASS__); |
|
| 14 | + if (!self::$registered) { |
|
| 15 | + stream_wrapper_register('compress.lzw', __CLASS__); |
|
| 16 | + } |
|
| 16 | 17 | self::$registered = true; |
| 17 | 18 | } |
| 18 | 19 | |
@@ -43,12 +44,14 @@ discard block |
||
| 43 | 44 | { |
| 44 | 45 | // check for compress & uncompress utility |
| 45 | 46 | $this->checkBinary(); |
| 46 | - if (self::$installed === false) |
|
| 47 | - throw new \Exception('compress and uncompress commands are required'); |
|
| 47 | + if (self::$installed === false) { |
|
| 48 | + throw new \Exception('compress and uncompress commands are required'); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | $schema = 'compress.lzw://'; |
| 50 | - if (strncasecmp($schema, $path, strlen($schema)) == 0) |
|
| 51 | - $path = substr($path, strlen($schema)); |
|
| 52 | + if (strncasecmp($schema, $path, strlen($schema)) == 0) { |
|
| 53 | + $path = substr($path, strlen($schema)); |
|
| 54 | + } |
|
| 52 | 55 | |
| 53 | 56 | if (file_exists($path)) { |
| 54 | 57 | $this->path = realpath($path); |
@@ -62,14 +65,16 @@ discard block |
||
| 62 | 65 | $this->read(); |
| 63 | 66 | } else { |
| 64 | 67 | $prefix = basename(__FILE__, '.php'); |
| 65 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 66 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 68 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 69 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 67 | 70 | ': Could not create temporary file in '. |
| 68 | 71 | sys_get_temp_dir()); |
| 69 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 70 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 72 | + } |
|
| 73 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 74 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 71 | 75 | ': Could not create temporary file in '. |
| 72 | 76 | sys_get_temp_dir()); |
| 77 | + } |
|
| 73 | 78 | $this->tmp = $tmp; |
| 74 | 79 | $this->tmp2 = $tmp2; |
| 75 | 80 | $this->read(); |
@@ -78,14 +83,16 @@ discard block |
||
| 78 | 83 | $this->path = $path; |
| 79 | 84 | if (self::$forceTmpFile) { |
| 80 | 85 | $prefix = basename(__FILE__, '.php'); |
| 81 | - if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 82 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 86 | + if (($tmp = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 87 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 83 | 88 | ': Could not create temporary file in '. |
| 84 | 89 | sys_get_temp_dir()); |
| 85 | - if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) |
|
| 86 | - throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 90 | + } |
|
| 91 | + if (($tmp2 = tempnam(sys_get_temp_dir(), $prefix)) === false) { |
|
| 92 | + throw new \Exception(__CLASS__.', line '.__LINE__. |
|
| 87 | 93 | ': Could not create temporary file in '. |
| 88 | 94 | sys_get_temp_dir()); |
| 95 | + } |
|
| 89 | 96 | $this->tmp = $tmp; |
| 90 | 97 | $this->tmp2 = $tmp2; |
| 91 | 98 | $this->pointer = 0; |
@@ -266,7 +273,9 @@ discard block |
||
| 266 | 273 | } |
| 267 | 274 | if ($this->tmp !== null) { |
| 268 | 275 | unlink($this->tmp); |
| 269 | - if (file_exists($this->tmp2)) unlink($this->tmp2); |
|
| 276 | + if (file_exists($this->tmp2)) { |
|
| 277 | + unlink($this->tmp2); |
|
| 278 | + } |
|
| 270 | 279 | } else { |
| 271 | 280 | $this->data = null; |
| 272 | 281 | } |
@@ -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; |
@@ -60,8 +60,9 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function __construct($archiveFileName, $format, $password = null) |
| 62 | 62 | { |
| 63 | - if ($password !== null) |
|
| 64 | - throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
| 63 | + if ($password !== null) { |
|
| 64 | + throw new UnsupportedOperationException('Cab archive does not support password!'); |
|
| 65 | + } |
|
| 65 | 66 | $this->open($archiveFileName); |
| 66 | 67 | } |
| 67 | 68 | |
@@ -60,10 +60,11 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | protected static function init() |
| 62 | 62 | { |
| 63 | - if (!class_exists('\Alchemy\Zippy\Zippy')) |
|
| 64 | - static::$zippy = false; |
|
| 65 | - else if (static::$zippy === null) |
|
| 66 | - static::$zippy = Zippy::load(); |
|
| 63 | + if (!class_exists('\Alchemy\Zippy\Zippy')) { |
|
| 64 | + static::$zippy = false; |
|
| 65 | + } else if (static::$zippy === null) { |
|
| 66 | + static::$zippy = Zippy::load(); |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | 69 | |
| 69 | 70 | /** |
@@ -74,8 +75,9 @@ discard block |
||
| 74 | 75 | { |
| 75 | 76 | static::init(); |
| 76 | 77 | |
| 77 | - if (static::$zippy === false) |
|
| 78 | - return false; |
|
| 78 | + if (static::$zippy === false) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 79 | 81 | |
| 80 | 82 | switch ($format) { |
| 81 | 83 | case Formats::TAR_BZIP: |
@@ -189,8 +191,9 @@ discard block |
||
| 189 | 191 | $information = new ArchiveInformation(); |
| 190 | 192 | |
| 191 | 193 | foreach ($this->archive->getMembers() as $member) { |
| 192 | - if ($member->isDir()) |
|
| 193 | - continue; |
|
| 194 | + if ($member->isDir()) { |
|
| 195 | + continue; |
|
| 196 | + } |
|
| 194 | 197 | |
| 195 | 198 | $this->files[] = $information->files[] = str_replace('\\', '/', $member->getLocation()); |
| 196 | 199 | $this->members[str_replace('\\', '/', $member->getLocation())] = $member; |
@@ -69,8 +69,9 @@ discard block |
||
| 69 | 69 | public function __construct($archiveFileName, $format, $password = null) |
| 70 | 70 | { |
| 71 | 71 | $this->open($archiveFileName); |
| 72 | - if ($password !== null) |
|
| 73 | - throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
| 72 | + if ($password !== null) { |
|
| 73 | + throw new UnsupportedOperationException('Iso archive does not support password!'); |
|
| 74 | + } |
|
| 74 | 75 | } |
| 75 | 76 | |
| 76 | 77 | /** |
@@ -93,8 +94,9 @@ discard block |
||
| 93 | 94 | |
| 94 | 95 | /** @var \CVolumeDescriptor $usedDesc */ |
| 95 | 96 | $usedDesc = $this->iso->GetDescriptor(SUPPLEMENTARY_VOLUME_DESC); |
| 96 | - if (!$usedDesc) |
|
| 97 | - $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 97 | + if (!$usedDesc) { |
|
| 98 | + $usedDesc = $this->iso->GetDescriptor(PRIMARY_VOLUME_DESC); |
|
| 99 | + } |
|
| 98 | 100 | $this->blockSize = $usedDesc->iBlockSize; |
| 99 | 101 | $directories = $usedDesc->LoadMPathTable($this->iso); |
| 100 | 102 | // iterate over all directories |
@@ -115,8 +117,9 @@ discard block |
||
| 115 | 117 | if ($files) { |
| 116 | 118 | /** @var \CFileDirDescriptors $file */ |
| 117 | 119 | foreach ($files as $file) { |
| 118 | - if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) |
|
| 119 | - continue; |
|
| 120 | + if (in_array($file->strd_FileId, ['.', '..']) || $file->IsDirectory()) { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 120 | 123 | $this->files[$file->Location] = $directory.$file->strd_FileId; |
| 121 | 124 | $this->filesSize += $file->DataLen; |
| 122 | 125 | |
@@ -168,8 +171,9 @@ discard block |
||
| 168 | 171 | */ |
| 169 | 172 | public function getFileData($fileName) |
| 170 | 173 | { |
| 171 | - if (!isset($this->filesData[$fileName])) |
|
| 172 | - return false; |
|
| 174 | + if (!isset($this->filesData[$fileName])) { |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 173 | 177 | |
| 174 | 178 | return new ArchiveEntry($fileName, $this->filesData[$fileName]['size'], |
| 175 | 179 | $this->filesData[$fileName]['size'], $this->filesData[$fileName]['mtime'],false); |
@@ -204,11 +208,14 @@ discard block |
||
| 204 | 208 | protected function prepareForFileExtracting($fileName) |
| 205 | 209 | { |
| 206 | 210 | $Location = array_search($fileName, $this->files, true); |
| 207 | - if (!isset($this->filesData[$fileName])) return false; |
|
| 211 | + if (!isset($this->filesData[$fileName])) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 208 | 214 | $data = $this->filesData[$fileName]; |
| 209 | 215 | $Location_Real = $Location * $this->blockSize; |
| 210 | - if ($this->iso->Seek($Location_Real, SEEK_SET) === false) |
|
| 211 | - return false; |
|
| 216 | + if ($this->iso->Seek($Location_Real, SEEK_SET) === false) { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 212 | 219 | return $data; |
| 213 | 220 | } |
| 214 | 221 | |
@@ -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 | |
@@ -158,8 +158,9 @@ discard block |
||
| 158 | 158 | // by file content |
| 159 | 159 | if ($contentCheck) { |
| 160 | 160 | $mime_type = mime_content_type($fileName); |
| 161 | - if (isset(static::$mimeTypes[$mime_type])) |
|
| 162 | - return static::$mimeTypes[$mime_type]; |
|
| 161 | + if (isset(static::$mimeTypes[$mime_type])) { |
|
| 162 | + return static::$mimeTypes[$mime_type]; |
|
| 163 | + } |
|
| 163 | 164 | } |
| 164 | 165 | |
| 165 | 166 | return false; |
@@ -251,12 +252,14 @@ discard block |
||
| 251 | 252 | protected static function checkFormatSupport($format, $function) |
| 252 | 253 | { |
| 253 | 254 | static::retrieveAllFormats(); |
| 254 | - if (!static::canOpen($format)) |
|
| 255 | - return false; |
|
| 255 | + if (!static::canOpen($format)) { |
|
| 256 | + return false; |
|
| 257 | + } |
|
| 256 | 258 | |
| 257 | 259 | foreach (static::$formatsSupport[$format] as $driver) { |
| 258 | - if ($driver::$function($format)) |
|
| 259 | - return true; |
|
| 260 | + if ($driver::$function($format)) { |
|
| 261 | + return true; |
|
| 262 | + } |
|
| 260 | 263 | } |
| 261 | 264 | |
| 262 | 265 | return false; |
@@ -271,15 +274,18 @@ discard block |
||
| 271 | 274 | { |
| 272 | 275 | static::retrieveAllFormats(); |
| 273 | 276 | |
| 274 | - if (!static::canOpen($format)) |
|
| 275 | - throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
| 277 | + if (!static::canOpen($format)) { |
|
| 278 | + throw new UnsupportedArchiveException('Unsupported archive type: '.$format.' of archive '); |
|
| 279 | + } |
|
| 276 | 280 | |
| 277 | - if (!$createAbility) |
|
| 278 | - return static::$formatsSupport[$format][0]; |
|
| 281 | + if (!$createAbility) { |
|
| 282 | + return static::$formatsSupport[$format][0]; |
|
| 283 | + } |
|
| 279 | 284 | |
| 280 | 285 | foreach (static::$formatsSupport[$format] as $driver) { |
| 281 | - if ($driver::canCreateArchive($format)) |
|
| 282 | - return $driver; |
|
| 286 | + if ($driver::canCreateArchive($format)) { |
|
| 287 | + return $driver; |
|
| 288 | + } |
|
| 283 | 289 | } |
| 284 | 290 | |
| 285 | 291 | return false; |
@@ -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; |
@@ -140,10 +142,11 @@ discard block |
||
| 140 | 142 | break; |
| 141 | 143 | } |
| 142 | 144 | |
| 143 | - if (isset($tar_aname)) |
|
| 144 | - $tar = new Archive_Tar($tar_aname, $compression); |
|
| 145 | - else |
|
| 146 | - $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 145 | + if (isset($tar_aname)) { |
|
| 146 | + $tar = new Archive_Tar($tar_aname, $compression); |
|
| 147 | + } else { |
|
| 148 | + $tar = new Archive_Tar($archiveFileName, $compression); |
|
| 149 | + } |
|
| 147 | 150 | |
| 148 | 151 | $current_file = 0; |
| 149 | 152 | $total_files = count($files); |
@@ -152,11 +155,13 @@ discard block |
||
| 152 | 155 | $add_dir = dirname($localName); |
| 153 | 156 | |
| 154 | 157 | if (is_null($filename)) { |
| 155 | - if ($tar->addString($localName, '') === false) |
|
| 156 | - throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 158 | + if ($tar->addString($localName, '') === false) { |
|
| 159 | + throw new ArchiveCreationException('Error when adding directory '.$localName.' to archive'); |
|
| 160 | + } |
|
| 157 | 161 | } else { |
| 158 | - if ($tar->addModify($filename, $add_dir, $remove_dir) === false) |
|
| 159 | - throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 162 | + if ($tar->addModify($filename, $add_dir, $remove_dir) === false) { |
|
| 163 | + throw new ArchiveCreationException('Error when adding file '.$filename.' to archive'); |
|
| 164 | + } |
|
| 160 | 165 | } |
| 161 | 166 | if ($fileProgressCallable !== null) { |
| 162 | 167 | call_user_func_array($fileProgressCallable, [$current_file++, $total_files, $filename, $localName]); |
@@ -216,8 +221,9 @@ discard block |
||
| 216 | 221 | continue; |
| 217 | 222 | } |
| 218 | 223 | // skip directories |
| 219 | - if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') |
|
| 220 | - continue; |
|
| 224 | + if ($file['typeflag'] == '5' || substr($file['filename'], -1) === '/') { |
|
| 225 | + continue; |
|
| 226 | + } |
|
| 221 | 227 | $information->files[] = $file['filename']; |
| 222 | 228 | $information->uncompressedFilesSize += $file['size']; |
| 223 | 229 | $this->pearFilesIndex[$file['filename']] = $i; |
@@ -262,14 +268,16 @@ discard block |
||
| 262 | 268 | */ |
| 263 | 269 | public function getFileData($fileName) |
| 264 | 270 | { |
| 265 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 266 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 271 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 272 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 273 | + } |
|
| 267 | 274 | |
| 268 | 275 | $index = $this->pearFilesIndex[$fileName]; |
| 269 | 276 | |
| 270 | 277 | $files_list = $this->tar->listContent(); |
| 271 | - if (!isset($files_list[$index])) |
|
| 272 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 278 | + if (!isset($files_list[$index])) { |
|
| 279 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in Tar archive'); |
|
| 280 | + } |
|
| 273 | 281 | |
| 274 | 282 | $data = $files_list[$index]; |
| 275 | 283 | unset($files_list); |
@@ -284,8 +292,9 @@ discard block |
||
| 284 | 292 | */ |
| 285 | 293 | public function getFileContent($fileName) |
| 286 | 294 | { |
| 287 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 288 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 295 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 296 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 297 | + } |
|
| 289 | 298 | |
| 290 | 299 | return $this->tar->extractInString($fileName); |
| 291 | 300 | } |
@@ -295,8 +304,9 @@ discard block |
||
| 295 | 304 | */ |
| 296 | 305 | public function getFileStream($fileName) |
| 297 | 306 | { |
| 298 | - if (!isset($this->pearFilesIndex[$fileName])) |
|
| 299 | - throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 307 | + if (!isset($this->pearFilesIndex[$fileName])) { |
|
| 308 | + throw new NonExistentArchiveFileException('File '.$fileName.' is not found in archive files list'); |
|
| 309 | + } |
|
| 300 | 310 | |
| 301 | 311 | return self::wrapStringInStream($this->tar->extractInString($fileName)); |
| 302 | 312 | } |