Passed
Push — master ( b953c9...de8e3d )
by Ron
02:53
created
src/Databases/MySQL/MySQLExceptionInterpreter.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 		/** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */
20 20
 		$code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode());
21 21
 		$message = $exception->getMessage();
22
-		switch($code) {
22
+		switch ($code) {
23 23
 			case 2006: return new DatabaseHasGoneAwayException($message, $code, $exception);
24 24
 			case 1213: return new SqlDeadLockException($message, $code, $exception);
25 25
 			case 1205: return new LockWaitTimeoutExceededException($message, $code, $exception);
Please login to merge, or discard this patch.
src/Databases/MySQL.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param array<string, mixed> $options
49 49
 	 */
50 50
 	public function __construct(PDO $pdo, array $options = []) {
51
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
51
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
52 52
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
53 53
 		}
54 54
 		$this->pdo = $pdo;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 * @return VirtualTables
83 83
 	 */
84 84
 	public function getVirtualTables(): VirtualTables {
85
-		if($this->virtualTables === null) {
85
+		if ($this->virtualTables === null) {
86 86
 			$this->virtualTables = new VirtualTables();
87 87
 		}
88 88
 		return $this->virtualTables;
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 */
95 95
 	public function query(string $query) {
96 96
 		return $this->getQueryLoggers()->logRegion($query, function() use ($query) {
97
-			return $this->buildQueryStatement($query, function ($query) {
97
+			return $this->buildQueryStatement($query, function($query) {
98 98
 				return $this->pdo->query($query);
99 99
 			});
100 100
 		});
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * @return QueryStatement
106 106
 	 */
107 107
 	public function prepare(string $query) {
108
-		return $this->buildQueryStatement((string) $query, function ($query) {
108
+		return $this->buildQueryStatement((string) $query, function($query) {
109 109
 			return $this->pdo->prepare($query);
110 110
 		});
111 111
 	}
@@ -117,11 +117,11 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function exec(string $query, array $params = []): int {
119 119
 		return $this->getQueryLoggers()->logRegion($query, function() use ($query, $params) {
120
-			return $this->exceptionHandler(function () use ($query, $params) {
120
+			return $this->exceptionHandler(function() use ($query, $params) {
121 121
 				$stmt = $this->pdo->prepare($query);
122 122
 				$timer = microtime(true);
123 123
 				$stmt->execute($params);
124
-				$this->queryLoggers->log($query, microtime(true) - $timer);
124
+				$this->queryLoggers->log($query, microtime(true)-$timer);
125 125
 				$result = $stmt->rowCount();
126 126
 				$stmt->closeCursor();
127 127
 				return $result;
@@ -143,19 +143,19 @@  discard block
 block discarded – undo
143 143
 	 */
144 144
 	public function getTableFields(string $table): array {
145 145
 		$fqTable = $this->select()->aliasReplacer()->replace($table);
146
-		if(array_key_exists($fqTable, $this->tableFields)) {
146
+		if (array_key_exists($fqTable, $this->tableFields)) {
147 147
 			return $this->tableFields[$fqTable];
148 148
 		}
149 149
 		$query = "DESCRIBE {$fqTable}";
150 150
 		return $this->getQueryLoggers()->logRegion($query, function() use ($query, $fqTable) {
151
-			return $this->exceptionHandler(function () use ($query, $fqTable) {
151
+			return $this->exceptionHandler(function() use ($query, $fqTable) {
152 152
 				$stmt = $this->pdo->query($query);
153 153
 				try {
154
-					if($stmt === false) {
154
+					if ($stmt === false) {
155 155
 						throw new RuntimeException('Invalid return type');
156 156
 					}
157 157
 					$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
158
-					$this->tableFields[$fqTable] = array_map(static function ($row) { return $row['Field']; }, $rows ?: []);
158
+					$this->tableFields[$fqTable] = array_map(static function($row) { return $row['Field']; }, $rows ?: []);
159 159
 					return $this->tableFields[$fqTable];
160 160
 				} finally {
161 161
 					try {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		$select = array_key_exists('select-factory', $this->options)
200 200
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
201 201
 			: new MySQL\MySQLRunnableSelect($this, $this->options['select-options']);
202
-		if($fields !== null) {
202
+		if ($fields !== null) {
203 203
 			$select->fields($fields);
204 204
 		}
205 205
 		return $select;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		$insert = array_key_exists('insert-factory', $this->options)
214 214
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
215 215
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
216
-		if($fields !== null) {
216
+		if ($fields !== null) {
217 217
 			$insert->addAll($fields);
218 218
 		}
219 219
 		return $insert;
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 		$update = array_key_exists('update-factory', $this->options)
228 228
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
229 229
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
230
-		if($fields !== null) {
230
+		if ($fields !== null) {
231 231
 			$update->setAll($fields);
232 232
 		}
233 233
 		return $update;
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @return $this
247 247
 	 */
248 248
 	public function transactionStart() {
249
-		if($this->transactionLevel === 0) {
250
-			if($this->pdo->inTransaction()) {
249
+		if ($this->transactionLevel === 0) {
250
+			if ($this->pdo->inTransaction()) {
251 251
 				$this->outerTransaction = true;
252 252
 			} else {
253 253
 				$this->pdo->beginTransaction();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 * @return $this
262 262
 	 */
263 263
 	public function transactionCommit() {
264
-		return $this->transactionEnd(function () {
264
+		return $this->transactionEnd(function() {
265 265
 			$this->pdo->commit();
266 266
 		});
267 267
 	}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 	 * @return $this
271 271
 	 */
272 272
 	public function transactionRollback() {
273
-		return $this->transactionEnd(function () {
273
+		return $this->transactionEnd(function() {
274 274
 			$this->pdo->rollBack();
275 275
 		});
276 276
 	}
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @return T
282 282
 	 */
283 283
 	public function dryRun(callable $callback) {
284
-		if(!$this->pdo->inTransaction()) {
284
+		if (!$this->pdo->inTransaction()) {
285 285
 			$this->transactionStart();
286 286
 			try {
287 287
 				return $callback($this);
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 	 * @throws Throwable
307 307
 	 */
308 308
 	public function transaction(callable $callback) {
309
-		if(!$this->pdo->inTransaction()) {
309
+		if (!$this->pdo->inTransaction()) {
310 310
 			$this->transactionStart();
311 311
 			try {
312 312
 				$result = $callback($this);
313 313
 				$this->transactionCommit();
314 314
 				return $result;
315 315
 			} catch (Throwable $e) {
316
-				if($this->pdo->inTransaction()) {
316
+				if ($this->pdo->inTransaction()) {
317 317
 					$this->transactionRollback();
318 318
 				}
319 319
 				throw $e;
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
 	 */
338 338
 	private function transactionEnd($fn): self {
339 339
 		$this->transactionLevel--;
340
-		if($this->transactionLevel < 0) {
340
+		if ($this->transactionLevel < 0) {
341 341
 			throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
342 342
 		}
343
-		if($this->transactionLevel < 1) {
344
-			if($this->outerTransaction) {
343
+		if ($this->transactionLevel < 1) {
344
+			if ($this->outerTransaction) {
345 345
 				$this->outerTransaction = false;
346 346
 			} else {
347 347
 				$fn();
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
 	 */
359 359
 	private function buildQueryStatement(string $query, callable $fn): QueryStatement {
360 360
 		$stmt = $fn($query);
361
-		if(!$stmt) {
361
+		if (!$stmt) {
362 362
 			throw new RuntimeException("Could not execute statement:\n{$query}");
363 363
 		}
364 364
 		return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.
src/QueryLogger/QueryLoggers.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -25,12 +25,12 @@
 block discarded – undo
25 25
 		$timer = microtime(true);
26 26
 		try {
27 27
 			return $fn();
28
-		} catch(Throwable $e) {
28
+		} catch (Throwable $e) {
29 29
 			$exception = $e;
30 30
 			throw $e;
31 31
 		} finally {
32
-			$finalTimer = microtime(true) - $timer;
33
-			if($exception === null) {
32
+			$finalTimer = microtime(true)-$timer;
33
+			if ($exception === null) {
34 34
 				$this->log($query, $finalTimer);
35 35
 			} else {
36 36
 				$this->logError($query, $exception, $finalTimer);
Please login to merge, or discard this patch.
src/Builder/QueryStatement.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 */
48 48
 	public function setFetchMode(int $mode = PDO::FETCH_ASSOC, $arg0 = null, ?array $arg1 = null) {
49 49
 		$args = [$mode];
50
-		if($arg0 !== null) {
50
+		if ($arg0 !== null) {
51 51
 			$args[] = $arg0;
52 52
 		}
53
-		if($arg1 !== null) {
53
+		if ($arg1 !== null) {
54 54
 			$args[] = $arg1;
55 55
 		}
56 56
 		$this->statement->setFetchMode(...$args);
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	public function execute(array $params = []) {
66 66
 		$this->exceptionHandler($this->query, function() use ($params) {
67 67
 			$response = $this->statement->execute($params);
68
-			if(!$response) {
68
+			if (!$response) {
69 69
 				throw new SqlException('Execution returned with "false".');
70 70
 			}
71 71
 		});
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array {
82 82
 		return $this->exceptionHandler($this->query, function() use ($fetchStyle, $fetchArgument, $ctorArgs) {
83
-			if($fetchArgument !== null) {
83
+			if ($fetchArgument !== null) {
84 84
 				return $this->statement->fetchAll($fetchStyle, $fetchArgument, ...$ctorArgs);
85 85
 			}
86 86
 			return $this->statement->fetchAll($fetchStyle);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	public function getColumnMeta(int $columnNo): ?array {
135 135
 		return $this->exceptionHandler($this->query, function() use ($columnNo) {
136 136
 			$columnMeta = $this->statement->getColumnMeta($columnNo);
137
-			if($columnMeta === false) {
137
+			if ($columnMeta === false) {
138 138
 				return null;
139 139
 			}
140 140
 			return $columnMeta;
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 * @return T
148 148
 	 */
149 149
 	private function exceptionHandler(string $query, callable $fn) {
150
-		return $this->queryLoggers->logRegion($query, function () use ($fn) {
150
+		return $this->queryLoggers->logRegion($query, function() use ($fn) {
151 151
 			try {
152 152
 				return $fn();
153 153
 			} catch (PDOException $exception) {
Please login to merge, or discard this patch.
src/Builder/Helpers/FieldTypeProvider.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,10 +10,10 @@
 block discarded – undo
10 10
 	 */
11 11
 	public static function getFieldTypes(QueryStatement $statement): array {
12 12
 		$fieldTypes = [];
13
-		for($i = 0; $column = $statement->getColumnMeta($i); $i++) {
13
+		for ($i = 0; $column = $statement->getColumnMeta($i); $i++) {
14 14
 			$name = $column['name'] ?? null;
15 15
 			$nativeType = $column['native_type'] ?? null;
16
-			if(is_string($name) && is_string($nativeType)) {
16
+			if (is_string($name) && is_string($nativeType)) {
17 17
 				$fieldTypes[$name] = self::getTypeFromNativeType($nativeType);
18 18
 			}
19 19
 		}
Please login to merge, or discard this patch.