Passed
Push — master ( d8ebfa...5b0a10 )
by smiley
01:22
created
src/ArchiveExtractor.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 use Psr\Log\{LoggerAwareInterface, LoggerAwareTrait, LoggerInterface, NullLogger};
22 22
 
23
-class ArchiveExtractor implements LoggerAwareInterface{
23
+class ArchiveExtractor implements LoggerAwareInterface {
24 24
 	use LoggerAwareTrait;
25 25
 
26 26
 	public const ARCHIVES = ['ClientData', 'ClientDataDE', 'ClientDataEN', 'ClientDataFR'];
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 *
50 50
 	 * @throws \codemasher\WildstarDB\WSDBException
51 51
 	 */
52
-	public function __construct(LoggerInterface $logger){
52
+	public function __construct(LoggerInterface $logger) {
53 53
 
54
-		if(!\extension_loaded('xz')){
54
+		if (!\extension_loaded('xz')) {
55 55
 			throw new WSDBException('required extension xz missing!');
56 56
 		}
57 57
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	public function open(string $index):ArchiveExtractor{
71 71
 		$this->archivename = \str_replace(['.index', '.archive'], '', \basename($index));
72 72
 
73
-		if(!in_array($this->archivename, $this::ARCHIVES)){
73
+		if (!in_array($this->archivename, $this::ARCHIVES)) {
74 74
 			throw new WSDBException('invalid archive file (Steam Wildstar not supported)');
75 75
 		}
76 76
 
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 		$this->destination = \rtrim($destination ?? $this->archivepath, '\\/');
93 93
 
94 94
 		// does the destination parent exist?
95
-		if(!$this->destination || !\file_exists(\dirname($this->destination))){
95
+		if (!$this->destination || !\file_exists(\dirname($this->destination))) {
96 96
 			throw new WSDBException('invalid destination: '.$this->destination);
97 97
 		}
98 98
 
99 99
 		// destination does not exist?
100
-		if(!\file_exists($this->destination)){
100
+		if (!\file_exists($this->destination)) {
101 101
 			// is the parent writable?
102
-			if(!\is_writable(\dirname($this->destination))){
102
+			if (!\is_writable(\dirname($this->destination))) {
103 103
 				throw new WSDBException('destination parent is not writable');
104 104
 			}
105 105
 			// create it
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 		}
108 108
 
109 109
 		// destination exists but isn't writable?
110
-		if(!\is_writable($this->destination)){
110
+		if (!\is_writable($this->destination)) {
111 111
 			throw new WSDBException('destination is not writable');
112 112
 		}
113 113
 
114 114
 		$this->fh       = \fopen($this->archivepath.'.archive', 'rb');
115 115
 		$this->warnings = [];
116 116
 
117
-		foreach($this->AIDX->data as $item){
117
+		foreach ($this->AIDX->data as $item) {
118 118
 			$this->read($item);
119 119
 		}
120 120
 
@@ -130,12 +130,12 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	protected function read(ArchiveItemAbstract $item):void{
132 132
 
133
-		if($item instanceof ArchiveDirectory){
133
+		if ($item instanceof ArchiveDirectory) {
134 134
 
135
-			foreach($item->Content as $dir){
135
+			foreach ($item->Content as $dir) {
136 136
 				$dest = $this->destination.$dir->Parent;
137 137
 
138
-				if(!\file_exists($dest)){
138
+				if (!\file_exists($dest)) {
139 139
 					\mkdir($dest, 0777, true);
140 140
 				}
141 141
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	protected function extractFile(ArchiveFile $file):void{
157 157
 		$dest = $this->destination.$file->Parent.$file->Name;
158 158
 
159
-		if(\file_exists($dest)){ // @todo: overwrite option
159
+		if (\file_exists($dest)) { // @todo: overwrite option
160 160
 			$this->logger->notice('file already exists: '.$dest);
161 161
 			return;
162 162
 		}
@@ -168,33 +168,33 @@  discard block
 block discarded – undo
168 168
 		$content = \fread($this->fh, $block['Size']);
169 169
 
170 170
 		// hash the read data
171
-		if(\sha1($content) !== $file->Hash){
171
+		if (\sha1($content) !== $file->Hash) {
172 172
 			throw new WSDBException('corrupt data, invalid hash: '.\sha1($content).' (expected '.$file->Hash.' for '.$file->Name.')');
173 173
 		}
174 174
 
175 175
 		// $Flags is supposed to be a bitmask
176
-		if($file->Flags === 1){ // no compression
176
+		if ($file->Flags === 1) { // no compression
177 177
 			// nada
178 178
 		}
179
-		elseif($file->Flags === 3){ // deflate (probably unsed)
179
+		elseif ($file->Flags === 3) { // deflate (probably unsed)
180 180
 			$content = \gzinflate($content);
181 181
 		}
182
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
182
+		elseif ($file->Flags === 5) { // lzma (requires ext-xz)
183 183
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
184 184
 			$content = \xzdecode(\substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5));
185 185
 		}
186
-		else{
186
+		else {
187 187
 			throw new WSDBException('invalid file flag');
188 188
 		}
189 189
 
190 190
 		$bytesWritten = \file_put_contents($dest, $content);
191 191
 
192
-		if($bytesWritten === false){
192
+		if ($bytesWritten === false) {
193 193
 			$this->errors[$file->Hash] = $file;
194 194
 			$this->logger->error('error writing '.$dest);
195 195
 
196 196
 		}
197
-		elseif($bytesWritten !== $file->SizeUncompressed){
197
+		elseif ($bytesWritten !== $file->SizeUncompressed) {
198 198
 			$this->warnings[$file->Hash] = $file;
199 199
 			// throw new WSDBException
200 200
 			$this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten);
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -175,15 +175,12 @@  discard block
 block discarded – undo
175 175
 		// $Flags is supposed to be a bitmask
176 176
 		if($file->Flags === 1){ // no compression
177 177
 			// nada
178
-		}
179
-		elseif($file->Flags === 3){ // deflate (probably unsed)
178
+		} elseif($file->Flags === 3){ // deflate (probably unsed)
180 179
 			$content = \gzinflate($content);
181
-		}
182
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
180
+		} elseif($file->Flags === 5){ // lzma (requires ext-xz)
183 181
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
184 182
 			$content = \xzdecode(\substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5));
185
-		}
186
-		else{
183
+		} else{
187 184
 			throw new WSDBException('invalid file flag');
188 185
 		}
189 186
 
@@ -193,8 +190,7 @@  discard block
 block discarded – undo
193 190
 			$this->errors[$file->Hash] = $file;
194 191
 			$this->logger->error('error writing '.$dest);
195 192
 
196
-		}
197
-		elseif($bytesWritten !== $file->SizeUncompressed){
193
+		} elseif($bytesWritten !== $file->SizeUncompressed){
198 194
 			$this->warnings[$file->Hash] = $file;
199 195
 			// throw new WSDBException
200 196
 			$this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten);
Please login to merge, or discard this patch.