Passed
Push — master ( 8ae334...8eeffd )
by Ron
02:38
created
src/Databases/MySQL.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param array<string, mixed> $options
53 53
 	 */
54 54
 	public function __construct(PDO $pdo, array $options = []) {
55
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
55
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
56 56
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
57 57
 		}
58 58
 		$this->pdo = $pdo;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		];
68 68
 		$this->options = array_merge($defaultOptions, $options);
69 69
 		$this->options['timezone'] ??= date_default_timezone_get();
70
-		if(!($this->options['timezone'] instanceof DateTimeZone)) {
70
+		if (!($this->options['timezone'] instanceof DateTimeZone)) {
71 71
 			$this->options['timezone'] = new DateTimeZone((string) $this->options['timezone']);
72 72
 		}
73 73
 		$this->quoter = new MySQLQuoter($pdo, $this->options['timezone']);
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 * @return VirtualTables
92 92
 	 */
93 93
 	public function getVirtualTables(): VirtualTables {
94
-		if($this->virtualTables === null) {
94
+		if ($this->virtualTables === null) {
95 95
 			$this->virtualTables = new VirtualTables();
96 96
 		}
97 97
 		return $this->virtualTables;
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
 		array $params = []
137 137
 	): int {
138 138
 		return $this->getQueryLoggers()->logRegion($query, fn() =>
139
-			$this->exceptionHandler(function () use ($query, $params) {
139
+			$this->exceptionHandler(function() use ($query, $params) {
140 140
 				$stmt = $this->pdo->prepare($query);
141 141
 				$timer = microtime(true);
142 142
 				$stmt->execute($params);
143
-				$this->queryLoggers->log($query, microtime(true) - $timer);
143
+				$this->queryLoggers->log($query, microtime(true)-$timer);
144 144
 				$result = $stmt->rowCount();
145 145
 				$stmt->closeCursor();
146 146
 				return $result;
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	public function getLastInsertId(?string $name = null): ?string {
156 156
 		$result = $this->pdo->lastInsertId();
157
-		if($result === false) {
157
+		if ($result === false) {
158 158
 			return null;
159 159
 		}
160 160
 		return $result;
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	public function getTableFields(string $table): array {
168 168
 		$fqTable = $this->select()->aliasReplacer()->replace($table);
169
-		if(array_key_exists($fqTable, $this->tableFields)) {
169
+		if (array_key_exists($fqTable, $this->tableFields)) {
170 170
 			return $this->tableFields[$fqTable];
171 171
 		}
172 172
 		$query = "DESCRIBE {$fqTable}";
173 173
 		return $this->getQueryLoggers()->logRegion($query, fn() =>
174
-			$this->exceptionHandler(function () use ($query, $fqTable) {
174
+			$this->exceptionHandler(function() use ($query, $fqTable) {
175 175
 				$stmt = $this->pdo->query($query);
176 176
 				try {
177
-					if($stmt === false) {
177
+					if ($stmt === false) {
178 178
 						throw new RuntimeException('Invalid return type');
179 179
 					}
180 180
 					$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 					return $this->tableFields[$fqTable];
183 183
 				} finally {
184 184
 					try {
185
-						if($stmt instanceof PDOStatement) {
185
+						if ($stmt instanceof PDOStatement) {
186 186
 							$stmt->closeCursor();
187 187
 						}
188 188
 					} catch (Throwable $e) {}
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 		$select = array_key_exists('select-factory', $this->options)
225 225
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
226 226
 			: new MySQL\MySQLRunnableSelect($this, $this->options['select-options']);
227
-		if($fields !== null) {
227
+		if ($fields !== null) {
228 228
 			$select->fields($fields);
229 229
 		}
230 230
 		return $select;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		$insert = array_key_exists('insert-factory', $this->options)
239 239
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
240 240
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
241
-		if($fields !== null) {
241
+		if ($fields !== null) {
242 242
 			$insert->addAll($fields);
243 243
 		}
244 244
 		return $insert;
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		$update = array_key_exists('update-factory', $this->options)
253 253
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
254 254
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
255
-		if($fields !== null) {
255
+		if ($fields !== null) {
256 256
 			$update->setAll($fields);
257 257
 		}
258 258
 		return $update;
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 	 * @return $this
272 272
 	 */
273 273
 	public function transactionStart() {
274
-		if($this->transactionLevel === 0) {
275
-			if($this->pdo->inTransaction()) {
274
+		if ($this->transactionLevel === 0) {
275
+			if ($this->pdo->inTransaction()) {
276 276
 				$this->outerTransaction = true;
277 277
 			} else {
278 278
 				$this->pdo->beginTransaction();
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 * @return $this
287 287
 	 */
288 288
 	public function transactionCommit() {
289
-		return $this->transactionEnd(function () {
289
+		return $this->transactionEnd(function() {
290 290
 			$this->pdo->commit();
291 291
 		});
292 292
 	}
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 * @return $this
296 296
 	 */
297 297
 	public function transactionRollback() {
298
-		return $this->transactionEnd(function () {
298
+		return $this->transactionEnd(function() {
299 299
 			$this->pdo->rollBack();
300 300
 		});
301 301
 	}
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * @return T
307 307
 	 */
308 308
 	public function dryRun(callable $callback) {
309
-		if(!$this->pdo->inTransaction()) {
309
+		if (!$this->pdo->inTransaction()) {
310 310
 			$this->transactionStart();
311 311
 			try {
312 312
 				return $callback($this);
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
 	 * @throws Throwable
332 332
 	 */
333 333
 	public function transaction(callable $callback) {
334
-		if(!$this->pdo->inTransaction()) {
334
+		if (!$this->pdo->inTransaction()) {
335 335
 			$this->transactionStart();
336 336
 			try {
337 337
 				$result = $callback($this);
338 338
 				$this->transactionCommit();
339 339
 				return $result;
340 340
 			} catch (Throwable $e) {
341
-				if($this->pdo->inTransaction()) {
341
+				if ($this->pdo->inTransaction()) {
342 342
 					$this->transactionRollback();
343 343
 				}
344 344
 				throw $e;
@@ -362,11 +362,11 @@  discard block
 block discarded – undo
362 362
 	 */
363 363
 	private function transactionEnd($fn): self {
364 364
 		$this->transactionLevel--;
365
-		if($this->transactionLevel < 0) {
365
+		if ($this->transactionLevel < 0) {
366 366
 			throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
367 367
 		}
368
-		if($this->transactionLevel < 1) {
369
-			if($this->outerTransaction) {
368
+		if ($this->transactionLevel < 1) {
369
+			if ($this->outerTransaction) {
370 370
 				$this->outerTransaction = false;
371 371
 			} else {
372 372
 				$fn();
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	 */
384 384
 	private function buildQueryStatement(string $query, callable $fn): QueryStatement {
385 385
 		$stmt = $fn($query);
386
-		if(!$stmt) {
386
+		if (!$stmt) {
387 387
 			throw new RuntimeException("Could not execute statement:\n{$query}");
388 388
 		}
389 389
 		return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.
src/Builder/Update.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @return $this
30 30
 	 */
31 31
 	public function table(string $alias, $table = null): self {
32
-		if($table === null) {
32
+		if ($table === null) {
33 33
 			[$alias, $table] = [$table, $alias];
34 34
 		}
35 35
 		$this->addTable($alias, $table);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return $this
65 65
 	 */
66 66
 	public function setExpr(string $expr, ...$args): self {
67
-		if(count($args) > 0) {
67
+		if (count($args) > 0) {
68 68
 			$this->fields[] = func_get_args();
69 69
 		} else {
70 70
 			$this->fields[] = $expr;
@@ -78,15 +78,15 @@  discard block
 block discarded – undo
78 78
 	 * @return $this
79 79
 	 */
80 80
 	public function setAll(array $data, ?array $allowedFields = null): self {
81
-		if($allowedFields !== null) {
82
-			foreach($data as $fieldName => $value) {
83
-				if(in_array($fieldName, $allowedFields)) {
81
+		if ($allowedFields !== null) {
82
+			foreach ($data as $fieldName => $value) {
83
+				if (in_array($fieldName, $allowedFields)) {
84 84
 					$this->set($fieldName, $value);
85 85
 				}
86 86
 			}
87 87
 		} else {
88 88
 			$values = $this->clearValues($data);
89
-			foreach($values as $fieldName => $value) {
89
+			foreach ($values as $fieldName => $value) {
90 90
 				$this->set($fieldName, $value);
91 91
 			}
92 92
 		}
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	private function buildAssignments(string $query): string {
123 123
 		$sqlFields = $this->buildFieldList($this->fields);
124
-		if(!count($sqlFields)) {
124
+		if (!count($sqlFields)) {
125 125
 			throw new RuntimeException('No field-data found');
126 126
 		}
127 127
 		return sprintf("%s%s\n", $query, implode(",\n", $sqlFields));
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 	 * @return array<string, mixed>
133 133
 	 */
134 134
 	private function clearValues(array $values): array {
135
-		if(!count($values)) {
135
+		if (!count($values)) {
136 136
 			return [];
137 137
 		}
138 138
 		$tables = $this->getTables();
139
-		if(!count($tables)) {
139
+		if (!count($tables)) {
140 140
 			throw new RuntimeException('Table name is missing');
141 141
 		}
142
-		if(count($tables) > 1) {
142
+		if (count($tables) > 1) {
143 143
 			throw new RuntimeException('Batch values only work with max. one table');
144 144
 		}
145 145
 
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 		$tableName = $table['name'];
148 148
 
149 149
 		$result = [];
150
-		if(is_string($tableName)) {
150
+		if (is_string($tableName)) {
151 151
 			$fields = $this->db()->getTableFields($tableName);
152 152
 
153
-			foreach($values as $fieldName => $fieldValue) {
154
-				if(in_array($fieldName, $fields, true)) {
153
+			foreach ($values as $fieldName => $fieldValue) {
154
+				if (in_array($fieldName, $fields, true)) {
155 155
 					$result[$fieldName] = $fieldValue;
156 156
 				}
157 157
 			}
Please login to merge, or discard this patch.
src/Builder/Insert.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 * @return $this
90 90
 	 */
91 91
 	public function addExpr(string $str, ...$args) {
92
-		if(count($args) > 0) {
92
+		if (count($args) > 0) {
93 93
 			$this->fields[] = func_get_args();
94 94
 		} else {
95 95
 			$this->fields[] = $str;
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @return $this
104 104
 	 */
105 105
 	public function updateExpr(string $str, ...$args) {
106
-		if(count($args) > 0) {
106
+		if (count($args) > 0) {
107 107
 			$this->update[] = func_get_args();
108 108
 		} else {
109 109
 			$this->update[] = $str;
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * @return $this
118 118
 	 */
119 119
 	public function addOrUpdateExpr(string $expr, ...$args) {
120
-		if(count($args) > 0) {
120
+		if (count($args) > 0) {
121 121
 			$this->fields[] = func_get_args();
122 122
 			$this->update[] = func_get_args();
123 123
 		} else {
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * @return $this
135 135
 	 */
136 136
 	public function addAll(array $data, ?array $mask = null, ?array $excludeFields = null) {
137
-		$this->addAllTo($data, $mask, $excludeFields, function ($field, $value) {
137
+		$this->addAllTo($data, $mask, $excludeFields, function($field, $value) {
138 138
 			$this->add($field, $value);
139 139
 		});
140 140
 		return $this;
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 	 * @return $this
148 148
 	 */
149 149
 	public function updateAll(array $data, ?array $mask = null, ?array $excludeFields = null) {
150
-		$this->addAllTo($data, $mask, $excludeFields, function ($field, $value) {
151
-			if($field !== $this->keyField) {
150
+		$this->addAllTo($data, $mask, $excludeFields, function($field, $value) {
151
+			if ($field !== $this->keyField) {
152 152
 				$this->update($field, $value);
153 153
 			}
154 154
 		});
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @return string
193 193
 	 */
194 194
 	public function __toString(): string {
195
-		if($this->table === null) {
195
+		if ($this->table === null) {
196 196
 			throw new RuntimeException('Specify a table-name');
197 197
 		}
198 198
 
@@ -202,21 +202,21 @@  discard block
 block discarded – undo
202 202
 		$ignoreStr = $this->ignore ? ' IGNORE' : '';
203 203
 		$queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n";
204 204
 
205
-		if($this->from !== null) {
205
+		if ($this->from !== null) {
206 206
 			$fields = $this->from->getFields();
207 207
 			$queryArr[] = sprintf("\t(%s)\n", implode(', ', array_keys($fields)));
208 208
 			$queryArr[] = $this->from;
209 209
 		} else {
210 210
 			$fields = $this->fields;
211 211
 			$insertData = $this->buildFieldList($fields);
212
-			if(!count($insertData)) {
212
+			if (!count($insertData)) {
213 213
 				throw new RuntimeException('No field-data found');
214 214
 			}
215 215
 			$queryArr[] = sprintf("SET\n%s\n", implode(",\n", $insertData));
216 216
 		}
217 217
 
218 218
 		$updateData = $this->buildUpdate();
219
-		if($updateData) {
219
+		if ($updateData) {
220 220
 			$queryArr[] = "{$updateData}\n";
221 221
 		}
222 222
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 	 * @return array<string|int, mixed>
231 231
 	 */
232 232
 	private function addTo(array $fields, string $field, $value): array {
233
-		if(!$this->isFieldNameValid($field)) {
233
+		if (!$this->isFieldNameValid($field)) {
234 234
 			throw new UnexpectedValueException('Field name is invalid');
235 235
 		}
236 236
 		$sqlField = $field;
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 	 * @param callable(string, mixed): void $fn
247 247
 	 */
248 248
 	private function addAllTo(array $data, ?array $mask, ?array $excludeFields, $fn): void {
249
-		if($mask !== null) {
249
+		if ($mask !== null) {
250 250
 			$data = array_intersect_key($data, array_combine($mask, $mask));
251 251
 		}
252
-		if($excludeFields !== null) {
253
-			foreach($excludeFields as $excludeField) {
254
-				if(array_key_exists($excludeField, $data)) {
252
+		if ($excludeFields !== null) {
253
+			foreach ($excludeFields as $excludeField) {
254
+				if (array_key_exists($excludeField, $data)) {
255 255
 					unset($data[$excludeField]);
256 256
 				}
257 257
 			}
258 258
 		}
259 259
 		$data = $this->clearValues($data);
260
-		foreach($data as $field => $value) {
260
+		foreach ($data as $field => $value) {
261 261
 			$fn($field, $value);
262 262
 		}
263 263
 	}
@@ -267,10 +267,10 @@  discard block
 block discarded – undo
267 267
 	 */
268 268
 	private function buildUpdate(): string {
269 269
 		$queryArr = [];
270
-		if(!empty($this->update)) {
270
+		if (!empty($this->update)) {
271 271
 			$queryArr[] = "ON DUPLICATE KEY UPDATE\n";
272 272
 			$updateArr = [];
273
-			if($this->keyField !== null) {
273
+			if ($this->keyField !== null) {
274 274
 				$updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})";
275 275
 			}
276 276
 			$updateArr = $this->buildFieldList($this->update, $updateArr);
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 	 * @return array<string, mixed>
294 294
 	 */
295 295
 	private function clearValues(array $values): array {
296
-		if(!count($values)) {
296
+		if (!count($values)) {
297 297
 			return [];
298 298
 		}
299 299
 
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 		$fields = $this->db()->getTableFields($tableName);
302 302
 		$result = [];
303 303
 
304
-		foreach($values as $fieldName => $fieldValue) {
305
-			if(in_array($fieldName, $fields)) {
304
+		foreach ($values as $fieldName => $fieldValue) {
305
+			if (in_array($fieldName, $fields)) {
306 306
 				$result[$fieldName] = $fieldValue;
307 307
 			}
308 308
 		}
Please login to merge, or discard this patch.
src/Builder/Helpers/RecursiveStructureAccess.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 		if (!$count) {
29 29
 			return $default;
30 30
 		}
31
-		foreach($arrayPath as $idxValue) {
31
+		foreach ($arrayPath as $idxValue) {
32 32
 			$part = $idxValue;
33
-			if(!array_key_exists($part, $data)) {
33
+			if (!array_key_exists($part, $data)) {
34 34
 				return $default;
35 35
 			}
36 36
 			$data = $data[$part];
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	private static function _recursiveHas($structure, array $path): bool {
47 47
 		$data = self::ensureArrayIsArray($structure);
48
-		if($data === null) {
48
+		if ($data === null) {
49 49
 			return false;
50 50
 		}
51
-		if(!count($path)) {
51
+		if (!count($path)) {
52 52
 			return false;
53 53
 		}
54 54
 		$key = array_shift($path);
55
-		if(count($path)) {
55
+		if (count($path)) {
56 56
 			return self::_recursiveHas($data[$key] ?? null, $path);
57 57
 		}
58 58
 		return array_key_exists($key, $data);
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 	 * @return string[]
64 64
 	 */
65 65
 	private static function getArrayPath($path): array {
66
-		if(is_array($path)) {
66
+		if (is_array($path)) {
67 67
 			return $path;
68 68
 		}
69 69
 		$parts = preg_split('{(?<!\\x5C)(?:\\x5C\\x5C)*\\.}', $path);
70
-		if($parts === false) {
70
+		if ($parts === false) {
71 71
 			return [$path];
72 72
 		}
73 73
 		return $parts;
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 	 * @return array<mixed, mixed>
79 79
 	 */
80 80
 	private static function ensureArrayIsArray($array): ?array {
81
-		if($array instanceof ArrayObject) {
81
+		if ($array instanceof ArrayObject) {
82 82
 			return $array->getArrayCopy();
83 83
 		}
84
-		if(is_object($array)) {
84
+		if (is_object($array)) {
85 85
 			return (array) $array;
86 86
 		}
87
-		if(is_array($array)) {
87
+		if (is_array($array)) {
88 88
 			return $array;
89 89
 		}
90 90
 		return null;
Please login to merge, or discard this patch.