Passed
Push — master ( bde7f9...b953c9 )
by Ron
01:51
created
src/Builder/Traits/OrderByBuilder.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 * @return $this
16 16
 	 */
17 17
 	public function orderBy($expression, string $direction = 'ASC') {
18
-		if($expression instanceof OrderBySpecification) {
19
-			foreach($expression->getFields() as $field) {
18
+		if ($expression instanceof OrderBySpecification) {
19
+			foreach ($expression->getFields() as $field) {
20 20
 				$this->addOrder($field[0], $field[1]);
21 21
 			}
22 22
 			return $this;
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function orderByValues(string $fieldName, array $values) {
34 34
 		$expr = [];
35
-		foreach(array_values($values) as $idx => $value) {
35
+		foreach (array_values($values) as $idx => $value) {
36 36
 			$expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", [$value, $idx]);
37 37
 		}
38 38
 		$this->orderBy[] = [sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), implode("\n\t\t", $expr)), 'ASC'];
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 * @return string
45 45
 	 */
46 46
 	protected function buildOrder(string $query): string {
47
-		if(!count($this->orderBy)) {
47
+		if (!count($this->orderBy)) {
48 48
 			return $query;
49 49
 		}
50 50
 		$query .= "ORDER BY\n";
51 51
 		$arr = [];
52
-		foreach($this->orderBy as [$expression, $direction]) {
52
+		foreach ($this->orderBy as [$expression, $direction]) {
53 53
 			$arr[] = sprintf("\t%s %s", $expression, strtoupper($direction));
54 54
 		}
55 55
 		return $query.implode(",\n", $arr)."\n";
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	private function addOrder($expression, string $direction): void {
63 63
 		$direction = $this->fixDirection($direction);
64
-		if(is_array($expression)) {
65
-			if(count($expression) < 1) {
64
+		if (is_array($expression)) {
65
+			if (count($expression) < 1) {
66 66
 				return;
67 67
 			}
68 68
 			$expr = (string) $expression[0];
Please login to merge, or discard this patch.
src/Builder/QueryStatement.php 1 patch
Spacing   +5 added lines, -5 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);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 			$timer = microtime(true);
68 68
 			$response = $this->statement->execute($params);
69 69
 			$this->queryLoggers->log($this->query, microtime(true)-$timer);
70
-			if(!$response) {
70
+			if (!$response) {
71 71
 				throw new SqlException('Execution returned with "false".');
72 72
 			}
73 73
 		});
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 */
83 83
 	public function fetchAll($fetchStyle = PDO::FETCH_ASSOC, $fetchArgument = null, array $ctorArgs = []): array {
84 84
 		return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) {
85
-			if($fetchArgument !== null) {
85
+			if ($fetchArgument !== null) {
86 86
 				return $this->statement->fetchAll($fetchStyle, $fetchArgument, ...$ctorArgs);
87 87
 			}
88 88
 			return $this->statement->fetchAll($fetchStyle);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	public function getColumnMeta(int $columnNo): ?array {
137 137
 		return $this->exceptionHandler(function() use ($columnNo) {
138 138
 			$columnMeta = $this->statement->getColumnMeta($columnNo);
139
-			if($columnMeta === false) {
139
+			if ($columnMeta === false) {
140 140
 				return null;
141 141
 			}
142 142
 			return $columnMeta;
Please login to merge, or discard this patch.
src/Databases/MySQL/MySQLValueQuoter.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@
 block discarded – undo
13 13
 	 * @return string
14 14
 	 */
15 15
 	public static function quote(PDO $pdo, $value): string {
16
-		if(is_null($value)) {
16
+		if (is_null($value)) {
17 17
 			return 'NULL';
18 18
 		}
19 19
 
20
-		if(is_bool($value)) {
20
+		if (is_bool($value)) {
21 21
 			return $value ? '1' : '0';
22 22
 		}
23 23
 
24
-		if(is_array($value)) {
25
-			$fn = static function ($value) use ($pdo) {
24
+		if (is_array($value)) {
25
+			$fn = static function($value) use ($pdo) {
26 26
 				return self::quote($pdo, $value);
27 27
 			};
28 28
 			return implode(', ', array_map($fn, $value));
29 29
 		}
30 30
 
31
-		if($value instanceof DBExpr) {
31
+		if ($value instanceof DBExpr) {
32 32
 			return $value->getExpression();
33 33
 		}
34 34
 
35
-		if($value instanceof Select) {
35
+		if ($value instanceof Select) {
36 36
 			return sprintf('(%s)', (string) $value);
37 37
 		}
38 38
 
39
-		if(is_int($value) || is_float($value)) {
39
+		if (is_int($value) || is_float($value)) {
40 40
 			return (string) $value;
41 41
 		}
42 42
 
Please login to merge, or discard this patch.
src/Databases/MySQL/MySQLExpressionQuoter.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 	 */
16 16
 	public static function quoteExpression(PDO $pdo, string $expression, array $arguments = []): string {
17 17
 		$index = -1;
18
-		$func = static function () use ($pdo, $arguments, &$index) {
18
+		$func = static function() use ($pdo, $arguments, &$index) {
19 19
 			$index++;
20
-			if(array_key_exists($index, $arguments)) {
20
+			if (array_key_exists($index, $arguments)) {
21 21
 				$argument = $arguments[$index];
22 22
 				$value = MySQLValueQuoter::quote($pdo, $argument);
23
-			} elseif(count($arguments) > 0) {
23
+			} elseif (count($arguments) > 0) {
24 24
 				$args = $arguments;
25 25
 				$value = array_pop($args);
26 26
 				$value = MySQLValueQuoter::quote($pdo, $value);
Please login to merge, or discard this patch.
src/Databases/MySQL/MySQLFieldQuoter.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@
 block discarded – undo
9 9
 	 * @return string
10 10
 	 */
11 11
 	public static function quoteField(string $field): string {
12
-		if(is_numeric($field) || !is_string($field)) {
12
+		if (is_numeric($field) || !is_string($field)) {
13 13
 			throw new UnexpectedValueException('Field name is invalid');
14 14
 		}
15
-		if(strpos($field, '`') !== false) {
15
+		if (strpos($field, '`') !== false) {
16 16
 			return $field;
17 17
 		}
18 18
 		$parts = explode('.', $field);
Please login to merge, or discard this patch.
src/Databases/MySQL.php 1 patch
Spacing   +23 added lines, -23 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;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @return QueryStatement
94 94
 	 */
95 95
 	public function query(string $query) {
96
-		return $this->buildQueryStatement($query, function ($query) {
96
+		return $this->buildQueryStatement($query, function($query) {
97 97
 			return $this->pdo->query($query);
98 98
 		});
99 99
 	}
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 	 * @return QueryStatement
104 104
 	 */
105 105
 	public function prepare(string $query) {
106
-		return $this->buildQueryStatement((string) $query, function ($query) {
106
+		return $this->buildQueryStatement((string) $query, function($query) {
107 107
 			return $this->pdo->prepare($query);
108 108
 		});
109 109
 	}
@@ -114,11 +114,11 @@  discard block
 block discarded – undo
114 114
 	 * @return int
115 115
 	 */
116 116
 	public function exec(string $query, array $params = []): int {
117
-		return $this->exceptionHandler(function () use ($query, $params) {
117
+		return $this->exceptionHandler(function() use ($query, $params) {
118 118
 			$stmt = $this->pdo->prepare($query);
119 119
 			$timer = microtime(true);
120 120
 			$stmt->execute($params);
121
-			$this->queryLoggers->log($query, microtime(true) - $timer);
121
+			$this->queryLoggers->log($query, microtime(true)-$timer);
122 122
 			$result = $stmt->rowCount();
123 123
 			$stmt->closeCursor();
124 124
 			return $result;
@@ -139,15 +139,15 @@  discard block
 block discarded – undo
139 139
 	 */
140 140
 	public function getTableFields(string $table): array {
141 141
 		$table = $this->select()->aliasReplacer()->replace($table);
142
-		if(array_key_exists($table, $this->tableFields)) {
142
+		if (array_key_exists($table, $this->tableFields)) {
143 143
 			return $this->tableFields[$table];
144 144
 		}
145 145
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
146
-		if($stmt === false) {
146
+		if ($stmt === false) {
147 147
 			throw new RuntimeException('Invalid return type');
148 148
 		}
149 149
 		$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
150
-		$this->tableFields[$table] = array_map(static function ($row) { return $row['Field']; }, $rows ?: []);
150
+		$this->tableFields[$table] = array_map(static function($row) { return $row['Field']; }, $rows ?: []);
151 151
 		$stmt->closeCursor();
152 152
 		return $this->tableFields[$table];
153 153
 	}
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		$select = array_key_exists('select-factory', $this->options)
186 186
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
187 187
 			: new MySQL\MySQLRunnableSelect($this, $this->options['select-options']);
188
-		if($fields !== null) {
188
+		if ($fields !== null) {
189 189
 			$select->fields($fields);
190 190
 		}
191 191
 		return $select;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 		$insert = array_key_exists('insert-factory', $this->options)
200 200
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
201 201
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
202
-		if($fields !== null) {
202
+		if ($fields !== null) {
203 203
 			$insert->addAll($fields);
204 204
 		}
205 205
 		return $insert;
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		$update = array_key_exists('update-factory', $this->options)
214 214
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
215 215
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
216
-		if($fields !== null) {
216
+		if ($fields !== null) {
217 217
 			$update->setAll($fields);
218 218
 		}
219 219
 		return $update;
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 	 * @return $this
233 233
 	 */
234 234
 	public function transactionStart() {
235
-		if($this->transactionLevel === 0) {
236
-			if($this->pdo->inTransaction()) {
235
+		if ($this->transactionLevel === 0) {
236
+			if ($this->pdo->inTransaction()) {
237 237
 				$this->outerTransaction = true;
238 238
 			} else {
239 239
 				$this->pdo->beginTransaction();
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 	 * @return $this
248 248
 	 */
249 249
 	public function transactionCommit() {
250
-		return $this->transactionEnd(function () {
250
+		return $this->transactionEnd(function() {
251 251
 			$this->pdo->commit();
252 252
 		});
253 253
 	}
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 * @return $this
257 257
 	 */
258 258
 	public function transactionRollback() {
259
-		return $this->transactionEnd(function () {
259
+		return $this->transactionEnd(function() {
260 260
 			$this->pdo->rollBack();
261 261
 		});
262 262
 	}
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return T
268 268
 	 */
269 269
 	public function dryRun(callable $callback) {
270
-		if(!$this->pdo->inTransaction()) {
270
+		if (!$this->pdo->inTransaction()) {
271 271
 			$this->transactionStart();
272 272
 			try {
273 273
 				return $callback($this);
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
 	 * @throws Throwable
293 293
 	 */
294 294
 	public function transaction(callable $callback) {
295
-		if(!$this->pdo->inTransaction()) {
295
+		if (!$this->pdo->inTransaction()) {
296 296
 			$this->transactionStart();
297 297
 			try {
298 298
 				$result = $callback($this);
299 299
 				$this->transactionCommit();
300 300
 				return $result;
301 301
 			} catch (Throwable $e) {
302
-				if($this->pdo->inTransaction()) {
302
+				if ($this->pdo->inTransaction()) {
303 303
 					$this->transactionRollback();
304 304
 				}
305 305
 				throw $e;
@@ -323,11 +323,11 @@  discard block
 block discarded – undo
323 323
 	 */
324 324
 	private function transactionEnd($fn): self {
325 325
 		$this->transactionLevel--;
326
-		if($this->transactionLevel < 0) {
326
+		if ($this->transactionLevel < 0) {
327 327
 			throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
328 328
 		}
329
-		if($this->transactionLevel < 1) {
330
-			if($this->outerTransaction) {
329
+		if ($this->transactionLevel < 1) {
330
+			if ($this->outerTransaction) {
331 331
 				$this->outerTransaction = false;
332 332
 			} else {
333 333
 				$fn();
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 	 */
345 345
 	private function buildQueryStatement(string $query, callable $fn): QueryStatement {
346 346
 		$stmt = $fn($query);
347
-		if(!$stmt) {
347
+		if (!$stmt) {
348 348
 			throw new RuntimeException("Could not execute statement:\n{$query}");
349 349
 		}
350 350
 		return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.
src/Builder/Expr/DBExprOrderBySpec.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@  discard block
 block discarded – undo
14 14
 	 */
15 15
 	public function __construct(array $spec, array $sortFieldsSpec) {
16 16
 		$expressions = [];
17
-		foreach($spec as $specReference => $dbExpr) {
18
-			if(is_int($specReference)) {
17
+		foreach ($spec as $specReference => $dbExpr) {
18
+			if (is_int($specReference)) {
19 19
 				$specReference = $dbExpr;
20 20
 			}
21 21
 			$expressions[$specReference] = $dbExpr;
22 22
 		}
23
-		foreach($sortFieldsSpec as $sortFieldSpec) {
24
-			if(array_key_exists(0, $sortFieldSpec)) {
25
-				if(array_key_exists($sortFieldSpec[0], $expressions)) {
23
+		foreach ($sortFieldsSpec as $sortFieldSpec) {
24
+			if (array_key_exists(0, $sortFieldSpec)) {
25
+				if (array_key_exists($sortFieldSpec[0], $expressions)) {
26 26
 					$direction = 'ASC';
27
-					if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') {
27
+					if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') {
28 28
 						$direction = 'DESC';
29 29
 					}
30 30
 					$this->fields[] = [
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
 					];
34 34
 				}
35 35
 			} else { // @phpstan-ignore-line
36
-				foreach($sortFieldSpec as $alias => $direction) {
36
+				foreach ($sortFieldSpec as $alias => $direction) {
37 37
 					$direction = strtoupper($direction) === 'DESC' ? 'DESC' : 'ASC';
38
-					if(array_key_exists($alias, $expressions)) {
38
+					if (array_key_exists($alias, $expressions)) {
39 39
 						$this->fields[] = [$expressions[$alias], $direction];
40 40
 					}
41 41
 				}
Please login to merge, or discard this patch.
src/Builder/Expr/RequiredDBFilterMap.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 	 * @return DBExprFilter
37 37
 	 */
38 38
 	public function __invoke(string $expression, $keyPath, $validator = null) {
39
-		if(!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) {
39
+		if (!RecursiveStructureAccess::recursiveHas($this->map, $keyPath)) {
40 40
 			throw new RequiredValueNotFoundException(sprintf("Required value %s not found", json_encode($keyPath, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)));
41 41
 		}
42 42
 		return new DBExprFilter($expression, $this->map, $keyPath, $validator);
Please login to merge, or discard this patch.
src/Builder/Expr/DBOrderSpec.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,13 +41,13 @@
 block discarded – undo
41 41
 	public function getFields(): array {
42 42
 		$fields = [];
43 43
 		$max = $this->options['max_sort_instructions'] ?? 16;
44
-		foreach($this->sortingInstruction as $alias => $direction) {
44
+		foreach ($this->sortingInstruction as $alias => $direction) {
45 45
 			$direction = strtolower($direction) === 'desc' ? 'DESC' : 'ASC';
46
-			if(!array_key_exists($alias, $this->sortSpecification)) {
46
+			if (!array_key_exists($alias, $this->sortSpecification)) {
47 47
 				throw new DBSortAliasNotFoundException('Sorting: Alias for DB-Expression not found');
48 48
 			}
49 49
 			$fields[] = [$this->sortSpecification[$alias], $direction];
50
-			if($max < 1) {
50
+			if ($max < 1) {
51 51
 				throw new DBSortTooManyInstructionsException();
52 52
 			}
53 53
 			$max--;
Please login to merge, or discard this patch.