Passed
Push — master ( 2ef21c...d8ebfa )
by smiley
01:32
created
src/AIDXReader.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * @property array $dirs
19 19
  */
20
-class AIDXReader extends PACKReaderAbstract{
20
+class AIDXReader extends PACKReaderAbstract {
21 21
 
22 22
 	/** @var array */
23 23
 	protected $dirs;
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 			\fread($this->fh, 16)
34 34
 		);
35 35
 
36
-		if($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41"){ // XDIA
36
+		if ($rootInfo['ArchiveType'] !== "\x58\x44\x49\x41") { // XDIA
37 37
 			throw new WSDBException('invalid AIDX');
38 38
 		}
39 39
 
@@ -62,12 +62,12 @@  discard block
 block discarded – undo
62 62
 		$files = \array_fill(0, $n['files'], null);
63 63
 
64 64
 		// create a directory object for each dir (4+4 = 8 bytes)
65
-		foreach($dirs as $i => $_){
65
+		foreach ($dirs as $i => $_) {
66 66
 			$dirs[$i] = new ArchiveDirectory(\unpack('LNameOffset/LBlockIndex', \fread($this->fh, 8)), $parent);
67 67
 		}
68 68
 
69 69
 		// create a file object for each file (4+4+8+8+8+20+4 = 56 bytes)
70
-		foreach($files as $i => $_){
70
+		foreach ($files as $i => $_) {
71 71
 			$files[$i] = new ArchiveFile(
72 72
 				\unpack('LNameOffset/LFlags/QFiletime/QSizeUncompressed/QSizeCompressed/a20Hash/x4', \fread($this->fh, 56)),
73 73
 				$parent
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
 		};
83 83
 
84 84
 		// apply the names to each object in the block
85
-		foreach($dirs as $i => $e){
85
+		foreach ($dirs as $i => $e) {
86 86
 			$dirs[$i]->Name = $getname($e);
87 87
 		}
88 88
 
89
-		foreach($files as $i => $e){
89
+		foreach ($files as $i => $e) {
90 90
 			$files[$i]->Name = $getname($e);
91 91
 		}
92 92
 
93 93
 		// loop through the directory stucture recursively and add the block data
94
-		foreach($dirs as $i => $info){
95
-			if(isset($this->blocktable[$info->BlockIndex])){
94
+		foreach ($dirs as $i => $info) {
95
+			if (isset($this->blocktable[$info->BlockIndex])) {
96 96
 				$dirs[$i]->Content = $this->getBlock($this->blocktable[$info->BlockIndex], $parent.$info->Name);
97 97
 			}
98 98
 		}
Please login to merge, or discard this patch.
src/AARCReader.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 namespace codemasher\WildstarDB;
14 14
 
15
-class AARCReader extends PACKReaderAbstract{
15
+class AARCReader extends PACKReaderAbstract {
16 16
 
17 17
 	/**
18 18
 	 * @throws \codemasher\WildstarDB\WSDBException
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 			\fread($this->fh, 16)
26 26
 		);
27 27
 
28
-		if($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41"){ // CRAA
28
+		if ($rootInfo['ArchiveType'] !== "\x43\x52\x41\x41") { // CRAA
29 29
 			throw new WSDBException('invalid AARC');
30 30
 		}
31 31
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		\fseek($this->fh, $blockInfo['Offset']);
36 36
 
37 37
 		// read the data block info (4+20+8 = 32 bytes)
38
-		for($i = 0; $i < $rootInfo['Blockcount']; $i++){
38
+		for ($i = 0; $i < $rootInfo['Blockcount']; $i++) {
39 39
 			$data = unpack('LIndex/a20Hash/QSizeCompressed', \fread($this->fh, 32));
40 40
 			$hash = \bin2hex($data['Hash']);
41 41
 			unset($data['Hash']);
Please login to merge, or discard this patch.
src/ReaderAbstract.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @throws \codemasher\WildstarDB\WSDBException
80 80
 	 */
81
-	public function __construct(LoggerInterface $logger = null){
81
+	public function __construct(LoggerInterface $logger = null) {
82 82
 
83
-		if(\PHP_INT_SIZE < 8){
83
+		if (\PHP_INT_SIZE < 8) {
84 84
 			throw new WSDBException('64-bit PHP required');
85 85
 		}
86 86
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
 	/**
91 91
 	 * @return void
92 92
 	 */
93
-	public function __destruct(){
94
-		$this->logger->info('memory usage: '.round(\memory_get_usage(true)/1048576, 3).'MB');
95
-		$this->logger->info('peak memory usage: '.round(\memory_get_peak_usage(true)/1048576, 3).'MB');
93
+	public function __destruct() {
94
+		$this->logger->info('memory usage: '.round(\memory_get_usage(true) / 1048576, 3).'MB');
95
+		$this->logger->info('peak memory usage: '.round(\memory_get_peak_usage(true) / 1048576, 3).'MB');
96 96
 
97 97
 		$this->close();
98 98
 	}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 */
103 103
 	public function close():ReaderInterface{
104 104
 
105
-		if(\is_resource($this->fh)){
105
+		if (\is_resource($this->fh)) {
106 106
 			\fclose($this->fh);
107 107
 
108 108
 			$this->fh = null;
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 *
123 123
 	 * @return mixed|null
124 124
 	 */
125
-	public function __get(string $name){
125
+	public function __get(string $name) {
126 126
 		return \property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null;
127 127
 	}
128 128
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 		$this->close();
137 137
 		$filename = \realpath($filename);
138 138
 
139
-		if(!$filename || !\is_file($filename) || !\is_readable($filename)){
139
+		if (!$filename || !\is_file($filename) || !\is_readable($filename)) {
140 140
 			throw new WSDBException('input file not readable');
141 141
 		}
142 142
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
 		$this->logger->info('loading: '.$this->file);
148 148
 
149
-		if(\strlen($header) !== $this->headerSize){
149
+		if (\strlen($header) !== $this->headerSize) {
150 150
 			throw new WSDBException('cannot read header');
151 151
 		}
152 152
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 */
169 169
 	protected function checkData():void{
170 170
 
171
-		if(empty($this->data)){
171
+		if (empty($this->data)) {
172 172
 			throw new WSDBException('empty data, run ReaderInterface::read() first');
173 173
 		}
174 174
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	protected function saveToFile(string $data, string $file):bool{
185 185
 
186
-		if(!\is_writable(\dirname($file))){
186
+		if (!\is_writable(\dirname($file))) {
187 187
 			throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable');
188 188
 		}
189 189
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 		$json = \json_encode($this->data, $jsonOptions);
205 205
 
206
-		if($file !== null){
206
+		if ($file !== null) {
207 207
 			$this->saveToFile($json, $file);
208 208
 		}
209 209
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 
226 226
 		\fputcsv($mh, \array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar);
227 227
 
228
-		foreach($this->data as $row){
228
+		foreach ($this->data as $row) {
229 229
 			\fputcsv($mh, \array_values($row), $delimiter, $enclosure, $escapeChar);
230 230
 		}
231 231
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
 		\fclose($mh);
237 237
 
238
-		if($file !== null){
238
+		if ($file !== null) {
239 239
 			$this->saveToFile($csv, $file);
240 240
 		}
241 241
 
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
 		$sxe   = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', \LIBXML_BIGLINES);
256 256
 		$types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string'];
257 257
 
258
-		foreach($this->data as $row){
258
+		foreach ($this->data as $row) {
259 259
 			$item = $sxe->addChild('item');
260 260
 
261
-			foreach(\array_values($row) as $i => $value){
261
+			foreach (\array_values($row) as $i => $value) {
262 262
 				$item
263 263
 					->addChild($this->cols[$i]['name'], $value)
264 264
 					->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 		$xml = $sxe->asXML();
270 270
 
271
-		if($file !== null){
271
+		if ($file !== null) {
272 272
 			$this->saveToFile($xml, $file);
273 273
 		}
274 274
 
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
 			->ifNotExists()
289 289
 		;
290 290
 
291
-		foreach($this->cols as $i => $col){
291
+		foreach ($this->cols as $i => $col) {
292 292
 
293
-			switch($col['header']['DataType']){
293
+			switch ($col['header']['DataType']) {
294 294
 				case 3:   $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break;
295 295
 				case 4:   $createTable->decimal($col['name'], '7,3', 0); break;
296 296
 				case 11:  $createTable->field($col['name'], 'BOOLEAN'); break;
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 
305 305
 		$createTable->query();
306 306
 
307
-		if(\count($this->data) < 1){
307
+		if (\count($this->data) < 1) {
308 308
 			$this->logger->notice('no records available for table '.$this->name);
309 309
 			return $this;
310 310
 		}
Please login to merge, or discard this patch.
src/ArchiveExtractor.php 2 patches
Spacing   +19 added lines, -19 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'];
@@ -47,9 +47,9 @@  discard block
 block discarded – undo
47 47
 	 *
48 48
 	 * @throws \codemasher\WildstarDB\WSDBException
49 49
 	 */
50
-	public function __construct(LoggerInterface $logger){
50
+	public function __construct(LoggerInterface $logger) {
51 51
 
52
-		if(!\extension_loaded('xz')){
52
+		if (!\extension_loaded('xz')) {
53 53
 			throw new WSDBException('required extension xz missing!');
54 54
 		}
55 55
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	public function open(string $index):ArchiveExtractor{
69 69
 		$this->archivename = \str_replace(['.index', '.archive'], '', \basename($index));
70 70
 
71
-		if(!in_array($this->archivename, $this::ARCHIVES)){
71
+		if (!in_array($this->archivename, $this::ARCHIVES)) {
72 72
 			throw new WSDBException('invalid archive file (Steam Wildstar not supported)');
73 73
 		}
74 74
 
@@ -90,14 +90,14 @@  discard block
 block discarded – undo
90 90
 		$this->destination = \rtrim($destination ?? $this->archivepath, '\\/');
91 91
 
92 92
 		// does the destination parent exist?
93
-		if(!$this->destination || !\file_exists(\dirname($this->destination))){
93
+		if (!$this->destination || !\file_exists(\dirname($this->destination))) {
94 94
 			throw new WSDBException('invalid destination: '.$this->destination);
95 95
 		}
96 96
 
97 97
 		// destination does not exist?
98
-		if(!\file_exists($this->destination)){
98
+		if (!\file_exists($this->destination)) {
99 99
 			// is the parent writable?
100
-			if(!\is_writable(\dirname($this->destination))){
100
+			if (!\is_writable(\dirname($this->destination))) {
101 101
 				throw new WSDBException('destination parent is not writable');
102 102
 			}
103 103
 			// create it
@@ -105,14 +105,14 @@  discard block
 block discarded – undo
105 105
 		}
106 106
 
107 107
 		// destination exists but isn't writable?
108
-		if(!\is_writable($this->destination)){
108
+		if (!\is_writable($this->destination)) {
109 109
 			throw new WSDBException('destination is not writable');
110 110
 		}
111 111
 
112 112
 		$this->fh       = \fopen($this->archivepath.'.archive', 'rb');
113 113
 		$this->warnings = [];
114 114
 
115
-		foreach($this->AIDX->data as $item){
115
+		foreach ($this->AIDX->data as $item) {
116 116
 			$this->read($item);
117 117
 		}
118 118
 
@@ -128,12 +128,12 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	protected function read(ArchiveItemAbstract $item):void{
130 130
 
131
-		if($item instanceof ArchiveDirectory){
131
+		if ($item instanceof ArchiveDirectory) {
132 132
 
133
-			foreach($item->Content as $dir){
133
+			foreach ($item->Content as $dir) {
134 134
 				$dest = $this->destination.$dir->Parent;
135 135
 
136
-				if(!\file_exists($dest)){
136
+				if (!\file_exists($dest)) {
137 137
 					\mkdir($dest, 0777, true);
138 138
 				}
139 139
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	protected function extractFile(ArchiveFile $file):void{
155 155
 		$dest = $this->destination.$file->Parent.$file->Name;
156 156
 
157
-		if(\file_exists($dest)){ // @todo: overwrite option
157
+		if (\file_exists($dest)) { // @todo: overwrite option
158 158
 			$this->logger->notice('file already exists: '.$dest);
159 159
 			return;
160 160
 		}
@@ -166,27 +166,27 @@  discard block
 block discarded – undo
166 166
 		$content = \fread($this->fh, $block['Size']);
167 167
 
168 168
 		// hash the read data
169
-		if(\sha1($content) !== $file->Hash){
169
+		if (\sha1($content) !== $file->Hash) {
170 170
 			throw new WSDBException('corrupt data, invalid hash: '.\sha1($content).' (expected '.$file->Hash.' for '.$file->Name.')');
171 171
 		}
172 172
 
173 173
 		// $Flags is supposed to be a bitmask
174
-		if($file->Flags === 1){ // no compression
174
+		if ($file->Flags === 1) { // no compression
175 175
 			$bytesWritten = \file_put_contents($dest, $content);
176 176
 		}
177
-		elseif($file->Flags === 3){ // deflate (probably unsed)
177
+		elseif ($file->Flags === 3) { // deflate (probably unsed)
178 178
 			$bytesWritten = \file_put_contents($dest, \gzinflate($content));
179 179
 		}
180
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
180
+		elseif ($file->Flags === 5) { // lzma (requires ext-xz)
181 181
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
182 182
 			$content      = \substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5);
183 183
 			$bytesWritten = \file_put_contents($dest, \xzdecode($content));
184 184
 		}
185
-		else{
185
+		else {
186 186
 			throw new WSDBException('invalid file flag');
187 187
 		}
188 188
 
189
-		if($bytesWritten !== $file->SizeUncompressed){
189
+		if ($bytesWritten !== $file->SizeUncompressed) {
190 190
 			$this->warnings[$file->Hash] = $file;
191 191
 			// throw new WSDBException
192 192
 			$this->logger->warning('size discrepancy for '.$dest.', expected '.$file->SizeUncompressed.' got '.$bytesWritten);
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -173,16 +173,13 @@
 block discarded – undo
173 173
 		// $Flags is supposed to be a bitmask
174 174
 		if($file->Flags === 1){ // no compression
175 175
 			$bytesWritten = \file_put_contents($dest, $content);
176
-		}
177
-		elseif($file->Flags === 3){ // deflate (probably unsed)
176
+		} elseif($file->Flags === 3){ // deflate (probably unsed)
178 177
 			$bytesWritten = \file_put_contents($dest, \gzinflate($content));
179
-		}
180
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
178
+		} elseif($file->Flags === 5){ // lzma (requires ext-xz)
181 179
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
182 180
 			$content      = \substr($content, 0, 5).\pack('Q', $file->SizeUncompressed).\substr($content, 5);
183 181
 			$bytesWritten = \file_put_contents($dest, \xzdecode($content));
184
-		}
185
-		else{
182
+		} else{
186 183
 			throw new WSDBException('invalid file flag');
187 184
 		}
188 185
 
Please login to merge, or discard this patch.