Passed
Branch master (6198fb)
by smiley
02:41
created
examples/DTBL.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,20 +23,20 @@
 block discarded – undo
23 23
 $reader   = new DTBLReader($logger);
24 24
 $iterator = new RecursiveDirectoryIterator(__DIR__.'/tbl', FilesystemIterator::SKIP_DOTS);
25 25
 
26
-foreach(new RecursiveIteratorIterator($iterator) as $finfo){
26
+foreach (new RecursiveIteratorIterator($iterator) as $finfo) {
27 27
 
28
-	if($finfo->getExtension() !== 'tbl'){
28
+	if ($finfo->getExtension() !== 'tbl') {
29 29
 		$logger->notice($finfo->getFilename().' is probably not a DTBL');
30 30
 		continue;
31 31
 	}
32 32
 
33
-	try{
33
+	try {
34 34
 		$reader->read($finfo->getRealPath());
35 35
 		$reader->toDB($db);
36 36
 
37 37
 		$logger->info('success: '.$finfo->getFilename());
38 38
 	}
39
-	catch(\Exception $e){
39
+	catch (\Exception $e) {
40 40
 		$logger->error($finfo->getFilename().': '.$e->getMessage());
41 41
 	}
42 42
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,8 +35,7 @@
 block discarded – undo
35 35
 		$reader->toDB($db);
36 36
 
37 37
 		$logger->info('success: '.$finfo->getFilename());
38
-	}
39
-	catch(\Exception $e){
38
+	} catch(\Exception $e){
40 39
 		$logger->error($finfo->getFilename().': '.$e->getMessage());
41 40
 	}
42 41
 
Please login to merge, or discard this patch.
examples/common.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 	'minLogLevel' => 'info',
35 35
 ];
36 36
 
37
-$options = new class($o) extends SettingsContainerAbstract{
37
+$options = new class($o) extends SettingsContainerAbstract {
38 38
 	use DatabaseOptionsTrait, LogOptionsTrait;
39 39
 };
40 40
 
Please login to merge, or discard this patch.
src/DTBLReader.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
  * @property array  $cols
26 26
  * @property array  $data
27 27
  */
28
-class DTBLReader{
28
+class DTBLReader {
29 29
 	use LoggerAwareTrait;
30 30
 
31 31
 	protected const FORMAT_HEADER = 'a4Signature/LVersion/QTableNameLength/QUnknown1/QRecordSize/QFieldCount/QDescriptionOffset/QRecordCount/QFullRecordSize/QEntryOffset/QNextId/QIDLookupOffset/QUnknown2';
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @throws \codemasher\WildstarDB\WSDBException
70 70
 	 */
71
-	public function __construct(LoggerInterface $logger = null){
71
+	public function __construct(LoggerInterface $logger = null) {
72 72
 
73
-		if(PHP_INT_SIZE < 8){
73
+		if (PHP_INT_SIZE < 8) {
74 74
 			throw new WSDBException('64-bit PHP required');
75 75
 		}
76 76
 
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * @return void
82 82
 	 */
83
-	public function __destruct(){
83
+	public function __destruct() {
84 84
 
85
-		if(is_resource($this->fh)){
85
+		if (is_resource($this->fh)) {
86 86
 			fclose($this->fh);
87 87
 		}
88 88
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @return mixed|null
95 95
 	 */
96
-	public function __get(string $name){
96
+	public function __get(string $name) {
97 97
 		return property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null;
98 98
 	}
99 99
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$this->cols = [];
119 119
 		$this->data = [];
120 120
 
121
-		if(strlen($header) !== 0x60){
121
+		if (strlen($header) !== 0x60) {
122 122
 			throw new WSDBException('cannot read DTBL header');
123 123
 		}
124 124
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 		$this->logger->info('fields: '.$this->header['FieldCount'].', rows: '.$this->header['RecordCount']);
128 128
 
129 129
 
130
-		if($this->header['Signature'] !== "\x4c\x42\x54\x44"){ // LBTD
130
+		if ($this->header['Signature'] !== "\x4c\x42\x54\x44") { // LBTD
131 131
 			throw new WSDBException('invalid DTBL');
132 132
 		}
133 133
 
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
 
136 136
 		fseek($this->fh, $this->header['DescriptionOffset'] + 0x60);
137 137
 
138
-		for($i = 0; $i < $this->header['FieldCount']; $i++){
138
+		for ($i = 0; $i < $this->header['FieldCount']; $i++) {
139 139
 			$this->cols[$i]['header'] = unpack($this::FORMAT_COLUMN, fread($this->fh, 0x18));
140 140
 		}
141 141
 
142 142
 		$offset = $this->header['FieldCount'] * 0x18 + $this->header['DescriptionOffset'] + 0x60;
143 143
 
144
-		if($this->header['FieldCount'] % 2){
144
+		if ($this->header['FieldCount'] % 2) {
145 145
 			$offset += 8;
146 146
 		}
147 147
 
148
-		foreach($this->cols as $i => $col){
148
+		foreach ($this->cols as $i => $col) {
149 149
 			fseek($this->fh, $offset + $col['header']['NameOffset']);
150 150
 
151 151
 			$this->cols[$i]['name'] = $this->decodeString(fread($this->fh, $col['header']['NameLength'] * 2));
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 */
162 162
 	public function read(string $dtbl):DTBLReader{
163 163
 
164
-		if(!is_file($dtbl) || !is_readable($dtbl)){
164
+		if (!is_file($dtbl) || !is_readable($dtbl)) {
165 165
 			throw new WSDBException('DTBL not readable');
166 166
 		}
167 167
 
@@ -173,19 +173,19 @@  discard block
 block discarded – undo
173 173
 
174 174
 		fseek($this->fh, $offset);
175 175
 
176
-		for($i = 0; $i < $this->header['RecordCount']; $i++){
176
+		for ($i = 0; $i < $this->header['RecordCount']; $i++) {
177 177
 			$data = fread($this->fh, $this->header['RecordSize']);
178 178
 			$row  = [];
179 179
 			$j    = 0;
180 180
 			$skip = false;
181 181
 
182
-			foreach($this->cols as $c => $col){
182
+			foreach ($this->cols as $c => $col) {
183 183
 
184
-				if($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130){
184
+				if ($skip === true && ($c > 0 && $this->cols[$c - 1]['header']['DataType'] === 130) && $col['header']['DataType'] !== 130) {
185 185
 					$j += 4;
186 186
 				}
187 187
 
188
-				switch($col['header']['DataType']){
188
+				switch ($col['header']['DataType']) {
189 189
 					case 3:  // uint32
190 190
 					case 11: // booleans (stored as uint32 0/1)
191 191
 						$v = unpack('L', substr($data, $j, 4))[1]; $j += 4; break;
@@ -204,12 +204,12 @@  discard block
 block discarded – undo
204 204
 							$j += 8;
205 205
 							$v = '';
206 206
 
207
-							do{
207
+							do {
208 208
 								$s = fread($this->fh, 2);
209 209
 
210 210
 								$v .= $s;
211 211
 							}
212
-							while($s !== "\x00\x00" && $s !== '');
212
+							while ($s !== "\x00\x00" && $s !== '');
213 213
 
214 214
 							$v = $this->decodeString($v);
215 215
 							fseek($this->fh, $p);
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 				$row[$col['name']] = $v;
223 223
 			}
224 224
 
225
-			if(count($row) !== $this->header['FieldCount']){
225
+			if (count($row) !== $this->header['FieldCount']) {
226 226
 				throw new WSDBException('invalid field count');
227 227
 			}
228 228
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 		fclose($this->fh);
233 233
 
234
-		if(count($this->data) !== $this->header['RecordCount']){
234
+		if (count($this->data) !== $this->header['RecordCount']) {
235 235
 			throw new WSDBException('invalid row count');
236 236
 		}
237 237
 
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
 	 */
245 245
 	protected function checkData():void{
246 246
 
247
-		if(empty($this->data)){
247
+		if (empty($this->data)) {
248 248
 			throw new WSDBException('empty data, run DTBLReader::read() first');
249 249
 		}
250 250
 
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 */
260 260
 	protected function saveToFile(string $data, string $file):bool{
261 261
 
262
-		if(!is_writable(dirname($file))){
262
+		if (!is_writable(dirname($file))) {
263 263
 			throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable');
264 264
 		}
265 265
 
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 
278 278
 		$json = json_encode($this->data, $jsonOptions);
279 279
 
280
-		if($file !== null){
280
+		if ($file !== null) {
281 281
 			$this->saveToFile($json, $file);
282 282
 		}
283 283
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 
300 300
 		fputcsv($mh, array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar);
301 301
 
302
-		foreach($this->data as $row){
302
+		foreach ($this->data as $row) {
303 303
 			fputcsv($mh, array_values($row), $delimiter, $enclosure, $escapeChar);
304 304
 		}
305 305
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 
310 310
 		fclose($mh);
311 311
 
312
-		if($file !== null){
312
+		if ($file !== null) {
313 313
 			$this->saveToFile($csv, $file);
314 314
 		}
315 315
 
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
 
331 331
 		$types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string'];
332 332
 
333
-		foreach($this->data as $row){
333
+		foreach ($this->data as $row) {
334 334
 			$item = $sxe->addChild('item');
335 335
 
336
-			foreach(array_values($row) as $i => $value){
336
+			foreach (array_values($row) as $i => $value) {
337 337
 				$item
338 338
 					->addChild($this->cols[$i]['name'], $value)
339 339
 					->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']]);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
 		$xml = $sxe->asXML();
345 345
 
346
-		if($file !== null){
346
+		if ($file !== null) {
347 347
 			$this->saveToFile($xml, $file);
348 348
 		}
349 349
 
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 			->ifNotExists()
363 363
 		;
364 364
 
365
-		foreach($this->cols as $i => $col){
365
+		foreach ($this->cols as $i => $col) {
366 366
 
367
-			switch($col['header']['DataType']){
367
+			switch ($col['header']['DataType']) {
368 368
 				case 3:   $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break;
369 369
 				case 4:   $createTable->decimal($col['name'], '7,3', 0); break;
370 370
 				case 11:  $createTable->field($col['name'], 'BOOLEAN'); break;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 
377 377
 		$createTable->query();
378 378
 
379
-		if(count($this->data) < 1){
379
+		if (count($this->data) < 1) {
380 380
 			$this->logger->notice('no records available for table '.$this->name);
381 381
 			return;
382 382
 		}
Please login to merge, or discard this patch.
src/WSDBException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,4 +12,4 @@
 block discarded – undo
12 12
 
13 13
 namespace codemasher\WildstarDB;
14 14
 
15
-class WSDBException extends \Exception{}
15
+class WSDBException extends \Exception {}
Please login to merge, or discard this patch.