Passed
Push — master ( f13e15...7ae3bd )
by smiley
01:56
created
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.
src/includes.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,6 +9,6 @@
 block discarded – undo
9 9
 
10 10
 namespace codemasher\WildstarDB;
11 11
 
12
-if(!defined('WSDB_FUNCTIONS')){
12
+if (!defined('WSDB_FUNCTIONS')) {
13 13
 	require_once __DIR__.'/functions.php';
14 14
 }
Please login to merge, or discard this patch.
src/functions.php 2 patches
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,11 +17,9 @@  discard block
 block discarded – undo
17 17
 
18 18
 	if($endianness === true){ // big-endian
19 19
 		$f = 'N';
20
-	}
21
-	elseif($endianness === false){ // little-endian
20
+	} elseif($endianness === false){ // little-endian
22 21
 		$f = 'V';
23
-	}
24
-	else{ // machine byte order
22
+	} else{ // machine byte order
25 23
 		$f = 'L';
26 24
 	}
27 25
 
@@ -34,11 +32,9 @@  discard block
 block discarded – undo
34 32
 
35 33
 	if($endianness === true){ // big-endian
36 34
 		$f = 'J';
37
-	}
38
-	elseif($endianness === false){ // little-endian
35
+	} elseif($endianness === false){ // little-endian
39 36
 		$f = 'P';
40
-	}
41
-	else{ // machine byte order
37
+	} else{ // machine byte order
42 38
 		$f = 'Q';
43 39
 	}
44 40
 
@@ -51,11 +47,9 @@  discard block
 block discarded – undo
51 47
 
52 48
 	if($endianness === true){ // big-endian
53 49
 		$f = 'G';
54
-	}
55
-	elseif($endianness === false){ // little-endian
50
+	} elseif($endianness === false){ // little-endian
56 51
 		$f = 'g';
57
-	}
58
-	else{ // machine byte order
52
+	} else{ // machine byte order
59 53
 		$f = 'f';
60 54
 	}
61 55
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -19,15 +19,15 @@  discard block
 block discarded – undo
19 19
  *
20 20
  * @return array|string|false
21 21
  */
22
-function uint32($i, bool $endianness = null){
22
+function uint32($i, bool $endianness = null) {
23 23
 
24
-	if($endianness === true){ // big-endian
24
+	if ($endianness === true) { // big-endian
25 25
 		$f = 'N';
26 26
 	}
27
-	elseif($endianness === false){ // little-endian
27
+	elseif ($endianness === false) { // little-endian
28 28
 		$f = 'V';
29 29
 	}
30
-	else{ // machine byte order
30
+	else { // machine byte order
31 31
 		$f = 'L';
32 32
 	}
33 33
 
@@ -42,15 +42,15 @@  discard block
 block discarded – undo
42 42
  *
43 43
  * @return array|string|false
44 44
  */
45
-function uint64($i, bool $endianness = null){
45
+function uint64($i, bool $endianness = null) {
46 46
 
47
-	if($endianness === true){ // big-endian
47
+	if ($endianness === true) { // big-endian
48 48
 		$f = 'J';
49 49
 	}
50
-	elseif($endianness === false){ // little-endian
50
+	elseif ($endianness === false) { // little-endian
51 51
 		$f = 'P';
52 52
 	}
53
-	else{ // machine byte order
53
+	else { // machine byte order
54 54
 		$f = 'Q';
55 55
 	}
56 56
 
@@ -65,15 +65,15 @@  discard block
 block discarded – undo
65 65
  *
66 66
  * @return array|string|false
67 67
  */
68
-function float($i, bool $endianness = null){
68
+function float($i, bool $endianness = null) {
69 69
 
70
-	if($endianness === true){ // big-endian
70
+	if ($endianness === true) { // big-endian
71 71
 		$f = 'G';
72 72
 	}
73
-	elseif($endianness === false){ // little-endian
73
+	elseif ($endianness === false) { // little-endian
74 74
 		$f = 'g';
75 75
 	}
76
-	else{ // machine byte order
76
+	else { // machine byte order
77 77
 		$f = 'f';
78 78
 	}
79 79
 
Please login to merge, or discard this patch.
cli/common-cli.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@
 block discarded – undo
35 35
 	'password' => $env->DB_PASSWORD,
36 36
 ];
37 37
 
38
-$logger = new class() extends AbstractLogger{
38
+$logger = new class() extends AbstractLogger {
39 39
 
40
-	public function log($level, $message, array $context = []){
40
+	public function log($level, $message, array $context = []) {
41 41
 		echo sprintf('[%s][%s] %s', date('Y-m-d H:i:s'), substr($level, 0, 4), trim($message))."\n";
42 42
 	}
43 43
 
Please login to merge, or discard this patch.
src/Archive/Extractor.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
 use const DIRECTORY_SEPARATOR;
36 36
 
37
-class Extractor implements LoggerAwareInterface{
37
+class Extractor implements LoggerAwareInterface {
38 38
 	use LoggerAwareTrait;
39 39
 
40 40
 	public const ARCHIVES = ['ClientData', 'ClientDataDE', 'ClientDataEN', 'ClientDataFR'];
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @throws \codemasher\WildstarDB\WSDBException
63 63
 	 */
64
-	public function __construct(LoggerInterface $logger){
64
+	public function __construct(LoggerInterface $logger) {
65 65
 
66
-		if(!extension_loaded('xz')){
66
+		if (!extension_loaded('xz')) {
67 67
 			throw new WSDBException('required extension xz missing!');
68 68
 		}
69 69
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	public function open(string $index):Extractor{
85 85
 		$this->archivename = str_replace(['.index', '.archive'], '', basename($index));
86 86
 
87
-		if(!in_array($this->archivename, $this::ARCHIVES)){
87
+		if (!in_array($this->archivename, $this::ARCHIVES)) {
88 88
 			throw new WSDBException('invalid archive file (Steam Wildstar not supported)');
89 89
 		}
90 90
 
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
 		$this->destination = rtrim($destination ?? $this->archivepath, '\\/');
107 107
 
108 108
 		// does the destination parent exist?
109
-		if(!$this->destination || !file_exists(dirname($this->destination))){
109
+		if (!$this->destination || !file_exists(dirname($this->destination))) {
110 110
 			throw new WSDBException('invalid destination: '.$this->destination);
111 111
 		}
112 112
 
113 113
 		// destination does not exist?
114
-		if(!file_exists($this->destination)){
114
+		if (!file_exists($this->destination)) {
115 115
 			// is the parent writable?
116
-			if(!is_writable(dirname($this->destination))){
116
+			if (!is_writable(dirname($this->destination))) {
117 117
 				throw new WSDBException('destination parent is not writable');
118 118
 			}
119 119
 			// create it
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
 		}
122 122
 
123 123
 		// destination exists but isn't writable?
124
-		if(!is_writable($this->destination)){
124
+		if (!is_writable($this->destination)) {
125 125
 			throw new WSDBException('destination is not writable');
126 126
 		}
127 127
 
128 128
 		$this->warnings = [];
129 129
 
130
-		foreach($this->AIDX->data as $item){
130
+		foreach ($this->AIDX->data as $item) {
131 131
 			$this->read($item);
132 132
 		}
133 133
 
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	 */
142 142
 	protected function read(ItemAbstract $item):void{
143 143
 
144
-		if($item instanceof Directory){
144
+		if ($item instanceof Directory) {
145 145
 
146
-			foreach($item->Content as $dir){
146
+			foreach ($item->Content as $dir) {
147 147
 
148
-				if(!file_exists($this->destination.$dir->Parent)){
148
+				if (!file_exists($this->destination.$dir->Parent)) {
149 149
 					mkdir($this->destination.$dir->Parent, 0777, true);
150 150
 				}
151 151
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	protected function extractFile(File $file):void{
168 168
 		$dest = $this->destination.$file->Parent.$file->Name;
169 169
 
170
-		if(file_exists($dest)){ // @todo: overwrite option
170
+		if (file_exists($dest)) { // @todo: overwrite option
171 171
 			$this->logger->notice('file already exists: '.$dest);
172 172
 
173 173
 			return;
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 			$this->getContent($file, $block['Offset'], $block['Size'])
180 180
 		);
181 181
 
182
-		if($bytesWritten === false){
182
+		if ($bytesWritten === false) {
183 183
 #			$this->errors[$file->Hash] = $file;
184 184
 			$this->logger->error('error writing '.$dest);
185 185
 
186 186
 		}
187
-		elseif($bytesWritten !== $file->SizeUncompressed){
187
+		elseif ($bytesWritten !== $file->SizeUncompressed) {
188 188
 #			$this->warnings[$file->Hash] = $file;
189 189
 			// throw new WSDBException
190 190
 			$this->logger->warning(
@@ -211,20 +211,20 @@  discard block
 block discarded – undo
211 211
 		fclose($fh);
212 212
 
213 213
 		// hash the read data
214
-		if(sha1($content) !== $file->Hash){
214
+		if (sha1($content) !== $file->Hash) {
215 215
 			throw new WSDBException(
216 216
 				sprintf('corrupt data, invalid hash: %1$s (expected %2$s for %3$s)', sha1($content), $file->Hash, $file->Name)
217 217
 			);
218 218
 		}
219 219
 
220 220
 		// $Flags is supposed to be a bitmask
221
-		if($file->Flags === 1){ // no compression
221
+		if ($file->Flags === 1) { // no compression
222 222
 			return $content;
223 223
 		}
224
-		elseif($file->Flags === 3){ // deflate (probably unsed)
224
+		elseif ($file->Flags === 3) { // deflate (probably unsed)
225 225
 			return gzinflate($content);
226 226
 		}
227
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
227
+		elseif ($file->Flags === 5) { // lzma (requires ext-xz)
228 228
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
229 229
 			return xzdecode(substr($content, 0, 5).pack('Q', $file->SizeUncompressed).substr($content, 5));
230 230
 		}
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -183,8 +183,7 @@  discard block
 block discarded – undo
183 183
 #			$this->errors[$file->Hash] = $file;
184 184
 			$this->logger->error('error writing '.$dest);
185 185
 
186
-		}
187
-		elseif($bytesWritten !== $file->SizeUncompressed){
186
+		} elseif($bytesWritten !== $file->SizeUncompressed){
188 187
 #			$this->warnings[$file->Hash] = $file;
189 188
 			// throw new WSDBException
190 189
 			$this->logger->warning(
@@ -220,11 +219,9 @@  discard block
 block discarded – undo
220 219
 		// $Flags is supposed to be a bitmask
221 220
 		if($file->Flags === 1){ // no compression
222 221
 			return $content;
223
-		}
224
-		elseif($file->Flags === 3){ // deflate (probably unsed)
222
+		} elseif($file->Flags === 3){ // deflate (probably unsed)
225 223
 			return gzinflate($content);
226
-		}
227
-		elseif($file->Flags === 5){ // lzma (requires ext-xz)
224
+		} elseif($file->Flags === 5){ // lzma (requires ext-xz)
228 225
 			// https://bitbucket.org/mugadr_m/wildstar-studio/issues/23
229 226
 			return xzdecode(substr($content, 0, 5).pack('Q', $file->SizeUncompressed).substr($content, 5));
230 227
 		}
Please login to merge, or discard this patch.
src/Archive/LTEXReader.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,8 +39,8 @@
 block discarded – undo
39 39
 	 * @internal
40 40
 	 */
41 41
 	protected $FORMAT_HEADER = 'a4Signature/LVersion/LLanguage/LLCID/QTagNameStringLength/QTagNameStringPtr'.
42
-	                           '/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr'.
43
-	                           '/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr';
42
+							   '/QShortNameStringLength/QShortNameStringPtr/QLongNameStringLength/QLongNameStringPtr'.
43
+							   '/QEntryCount/QEntryIndexPtr/QNameStoreLength/QNameStorePtr';
44 44
 
45 45
 	/**
46 46
 	 * @var string
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 /**
25 25
  * @property string $prettyname
26 26
  */
27
-final class LTEXReader extends ReaderAbstract{
27
+final class LTEXReader extends ReaderAbstract {
28 28
 
29 29
 	// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c
30 30
 	private const LCID = [
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	public function read(string $filename):ReaderInterface{
57 57
 		$this->loadFile($filename);
58 58
 
59
-		if($this->header['Signature'] !== "\x58\x45\x54\x4c"){ // XETL
59
+		if ($this->header['Signature'] !== "\x58\x45\x54\x4c") { // XETL
60 60
 			throw new WSDBException('invalid LTEX');
61 61
 		}
62 62
 
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		$this->prettyname = $this->decodeString(fread($this->fh, $this->header['LongNameStringLength'] * 2));
66 66
 		$this->name       = 'LocalizedText_'.$this::LCID[$this->header['LCID']];
67 67
 		$this->cols       = [
68
-			['name' => 'ID',            'header' => ['DataType' =>   3]],
68
+			['name' => 'ID', 'header' => ['DataType' =>   3]],
69 69
 			['name' => 'LocalizedText', 'header' => ['DataType' => 130]],
70 70
 		];
71 71
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 		$this->data = array_fill(0, $this->header['EntryCount'], null);
86 86
 
87
-		foreach($this->data as $i => $_){
87
+		foreach ($this->data as $i => $_) {
88 88
 			// get the id and offset for the data block
89 89
 			$c = unpack('Lid/Loffset', fread($this->fh, 8));
90 90
 			// save the current position
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
 
96 96
 			$v = '';
97 97
 			// read until we hit a double nul or the void
98
-			do{
98
+			do {
99 99
 				$s = fread($this->fh, 2);
100 100
 				$v .= $s;
101 101
 			}
102
-			while($s !== "\x00\x00" && $s !== '');
102
+			while ($s !== "\x00\x00" && $s !== '');
103 103
 
104 104
 			$this->data[$i] = ['ID' => $c['id'], 'LocalizedText' => $this->decodeString($v)];
105 105
 
Please login to merge, or discard this patch.
src/Archive/ReaderInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\Database\Database;
16 16
 
17
-interface ReaderInterface{
17
+interface ReaderInterface {
18 18
 
19 19
 	/**
20 20
 	 * @param string $name
Please login to merge, or discard this patch.
src/Archive/ReaderAbstract.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @throws \codemasher\WildstarDB\WSDBException
87 87
 	 */
88
-	public function __construct(LoggerInterface $logger = null){
88
+	public function __construct(LoggerInterface $logger = null) {
89 89
 
90
-		if(PHP_INT_SIZE < 8){
90
+		if (PHP_INT_SIZE < 8) {
91 91
 			throw new WSDBException('64-bit PHP required');
92 92
 		}
93 93
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	/**
98 98
 	 * @return void
99 99
 	 */
100
-	public function __destruct(){
100
+	public function __destruct() {
101 101
 		$this->logger->info('memory usage: '.round(memory_get_usage(true) / 1048576, 3).'MB');
102 102
 		$this->logger->info('peak memory usage: '.round(memory_get_peak_usage(true) / 1048576, 3).'MB');
103 103
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 */
110 110
 	public function close():ReaderInterface{
111 111
 
112
-		if(is_resource($this->fh)){
112
+		if (is_resource($this->fh)) {
113 113
 			fclose($this->fh);
114 114
 
115 115
 			$this->fh = null;
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return mixed|null
131 131
 	 */
132
-	public function __get(string $name){
132
+	public function __get(string $name) {
133 133
 		return property_exists($this, $name) && $name !== 'fh' ? $this->{$name} : null;
134 134
 	}
135 135
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		$this->close();
144 144
 #		$filename = realpath($filename);
145 145
 
146
-		if(!$filename || !is_file($filename) || !is_readable($filename)){
146
+		if (!$filename || !is_file($filename) || !is_readable($filename)) {
147 147
 			throw new WSDBException('input file not readable');
148 148
 		}
149 149
 
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 
154 154
 		$this->logger->info('loading: '.$this->file);
155 155
 
156
-		if(strlen($header) !== $this->headerSize){
156
+		if (strlen($header) !== $this->headerSize) {
157 157
 			throw new WSDBException('cannot read header');
158 158
 		}
159 159
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 */
176 176
 	protected function checkData():void{
177 177
 
178
-		if(empty($this->data)){
178
+		if (empty($this->data)) {
179 179
 			throw new WSDBException('empty data, run ReaderInterface::read() first');
180 180
 		}
181 181
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	 */
191 191
 	protected function saveToFile(string $data, string $file):bool{
192 192
 
193
-		if(!is_writable(dirname($file))){
193
+		if (!is_writable(dirname($file))) {
194 194
 			throw new WSDBException('cannot write data to file: '.$file.', target directory is not writable');
195 195
 		}
196 196
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		$this->checkData();
210 210
 		$json = json_encode($this->data, $jsonOptions);
211 211
 
212
-		if($file !== null){
212
+		if ($file !== null) {
213 213
 			$this->saveToFile($json, $file);
214 214
 		}
215 215
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 		fputcsv($mh, array_column($this->cols, 'name'), $delimiter, $enclosure, $escapeChar);
233 233
 
234
-		foreach($this->data as $row){
234
+		foreach ($this->data as $row) {
235 235
 			fputcsv($mh, array_values($row), $delimiter, $enclosure, $escapeChar);
236 236
 		}
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
 		fclose($mh);
243 243
 
244
-		if($file !== null){
244
+		if ($file !== null) {
245 245
 			$this->saveToFile($csv, $file);
246 246
 		}
247 247
 
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
 		$sxe   = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><root></root>', LIBXML_BIGLINES);
262 262
 		$types = [3 => 'uint32', 4 => 'float', 11 => 'bool', 20 => 'uint64', 130 => 'string'];
263 263
 
264
-		foreach($this->data as $row){
264
+		foreach ($this->data as $row) {
265 265
 			$item = $sxe->addChild('item');
266 266
 
267
-			foreach(array_values($row) as $i => $value){
267
+			foreach (array_values($row) as $i => $value) {
268 268
 				$item
269 269
 					->addChild($this->cols[$i]['name'], $value)
270 270
 					->addAttribute('dataType', $types[$this->cols[$i]['header']['DataType']])
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 
275 275
 		$xml = $sxe->asXML();
276 276
 
277
-		if($file !== null){
277
+		if ($file !== null) {
278 278
 			$this->saveToFile($xml, $file);
279 279
 		}
280 280
 
@@ -294,9 +294,9 @@  discard block
 block discarded – undo
294 294
 			->ifNotExists()
295 295
 		;
296 296
 
297
-		foreach($this->cols as $i => $col){
297
+		foreach ($this->cols as $i => $col) {
298 298
 
299
-			switch($col['header']['DataType']){
299
+			switch ($col['header']['DataType']) {
300 300
 				case 3:   $createTable->int($col['name'], 10, null, null, 'UNSIGNED'); break;
301 301
 				case 4:   $createTable->decimal($col['name'], '7,3', 0); break;
302 302
 				case 11:  $createTable->field($col['name'], 'BOOLEAN'); break;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 
311 311
 		$createTable->query();
312 312
 
313
-		if(count($this->data) < 1){
313
+		if (count($this->data) < 1) {
314 314
 			$this->logger->notice('no records available for table '.$this->name);
315 315
 
316 316
 			return $this;
Please login to merge, or discard this patch.
src/Archive/ItemAbstract.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\Archive;
14 14
 
15
-abstract class ItemAbstract{
15
+abstract class ItemAbstract {
16 16
 
17 17
 	/** @var string */
18 18
 	public $Parent;
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 	 * @param array  $data
28 28
 	 * @param string $parent
29 29
 	 */
30
-	public function __construct(array $data, string $parent){
30
+	public function __construct(array $data, string $parent) {
31 31
 
32
-		foreach($data as $property => $value){
32
+		foreach ($data as $property => $value) {
33 33
 			$this->{$property} = $value;
34 34
 		}
35 35
 
Please login to merge, or discard this patch.