@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param array<string, mixed> $options |
43 | 43 | */ |
44 | 44 | public function __construct(PDO $pdo, array $options = []) { |
45 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
45 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
46 | 46 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
47 | 47 | } |
48 | 48 | $this->pdo = $pdo; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @return VirtualTables |
77 | 77 | */ |
78 | 78 | public function getVirtualTables(): VirtualTables { |
79 | - if($this->virtualTables === null) { |
|
79 | + if ($this->virtualTables === null) { |
|
80 | 80 | $this->virtualTables = new VirtualTables(); |
81 | 81 | } |
82 | 82 | return $this->virtualTables; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @return QueryStatement |
88 | 88 | */ |
89 | 89 | public function query(string $query) { |
90 | - return $this->buildQueryStatement($query, function ($query) { |
|
90 | + return $this->buildQueryStatement($query, function($query) { |
|
91 | 91 | return $this->pdo->query($query); |
92 | 92 | }); |
93 | 93 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return QueryStatement |
98 | 98 | */ |
99 | 99 | public function prepare(string $query) { |
100 | - return $this->buildQueryStatement($query, function ($query) { |
|
100 | + return $this->buildQueryStatement($query, function($query) { |
|
101 | 101 | return $this->pdo->prepare($query); |
102 | 102 | }); |
103 | 103 | } |
@@ -108,11 +108,11 @@ discard block |
||
108 | 108 | * @return int |
109 | 109 | */ |
110 | 110 | public function exec(string $query, array $params = []): int { |
111 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
111 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
112 | 112 | $stmt = $this->pdo->prepare($query); |
113 | 113 | $timer = microtime(true); |
114 | 114 | $stmt->execute($params); |
115 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
115 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
116 | 116 | $result = $stmt->rowCount(); |
117 | 117 | $stmt->closeCursor(); |
118 | 118 | return $result; |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function getTableFields(string $table): array { |
135 | 135 | $table = $this->select()->aliasReplacer()->replace($table); |
136 | - if(array_key_exists($table, $this->tableFields)) { |
|
136 | + if (array_key_exists($table, $this->tableFields)) { |
|
137 | 137 | return $this->tableFields[$table]; |
138 | 138 | } |
139 | 139 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
140 | - if($stmt === false) { |
|
140 | + if ($stmt === false) { |
|
141 | 141 | throw new RuntimeException('Invalid return type'); |
142 | 142 | } |
143 | 143 | $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); |
144 | - $this->tableFields[$table] = array_map(static function ($row) { return $row['Field']; }, $rows ?: []); |
|
144 | + $this->tableFields[$table] = array_map(static function($row) { return $row['Field']; }, $rows ?: []); |
|
145 | 145 | $stmt->closeCursor(); |
146 | 146 | return $this->tableFields[$table]; |
147 | 147 | } |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function quoteExpression(string $expression, array $arguments = []): string { |
155 | 155 | $index = -1; |
156 | - $func = function () use ($arguments, &$index) { |
|
156 | + $func = function() use ($arguments, &$index) { |
|
157 | 157 | $index++; |
158 | - if(array_key_exists($index, $arguments)) { |
|
158 | + if (array_key_exists($index, $arguments)) { |
|
159 | 159 | $argument = $arguments[$index]; |
160 | 160 | $value = $this->quote($argument); |
161 | - } elseif(count($arguments) > 0) { |
|
161 | + } elseif (count($arguments) > 0) { |
|
162 | 162 | $args = $arguments; |
163 | 163 | $value = array_pop($args); |
164 | 164 | $value = $this->quote($value); |
@@ -176,15 +176,15 @@ discard block |
||
176 | 176 | * @return string |
177 | 177 | */ |
178 | 178 | public function quote($value): string { |
179 | - if(is_null($value)) { |
|
179 | + if (is_null($value)) { |
|
180 | 180 | $result = 'NULL'; |
181 | - } elseif($value instanceof Builder\DBExpr) { |
|
181 | + } elseif ($value instanceof Builder\DBExpr) { |
|
182 | 182 | $result = $value->getExpression(); |
183 | - } elseif($value instanceof Builder\Select) { |
|
183 | + } elseif ($value instanceof Builder\Select) { |
|
184 | 184 | $result = sprintf('(%s)', (string) $value); |
185 | - } elseif(is_array($value)) { |
|
186 | - $result = implode(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
187 | - } elseif(is_int($value) || is_float($value)) { |
|
185 | + } elseif (is_array($value)) { |
|
186 | + $result = implode(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
187 | + } elseif (is_int($value) || is_float($value)) { |
|
188 | 188 | $result = (string) $value; |
189 | 189 | } else { |
190 | 190 | $result = $this->pdo->quote($value); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if (is_numeric($field) || !is_string($field)) { |
201 | 201 | throw new UnexpectedValueException('Field name is invalid'); |
202 | 202 | } |
203 | - if(strpos($field, '`') !== false) { |
|
203 | + if (strpos($field, '`') !== false) { |
|
204 | 204 | return $field; |
205 | 205 | } |
206 | 206 | $parts = explode('.', $field); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $select = array_key_exists('select-factory', $this->options) |
216 | 216 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
217 | 217 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
218 | - if($fields !== null) { |
|
218 | + if ($fields !== null) { |
|
219 | 219 | $select->fields($fields); |
220 | 220 | } |
221 | 221 | return $select; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $insert = array_key_exists('insert-factory', $this->options) |
230 | 230 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
231 | 231 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
232 | - if($fields !== null) { |
|
232 | + if ($fields !== null) { |
|
233 | 233 | $insert->addAll($fields); |
234 | 234 | } |
235 | 235 | return $insert; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $update = array_key_exists('update-factory', $this->options) |
244 | 244 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
245 | 245 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
246 | - if($fields !== null) { |
|
246 | + if ($fields !== null) { |
|
247 | 247 | $update->setAll($fields); |
248 | 248 | } |
249 | 249 | return $update; |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * @return $this |
263 | 263 | */ |
264 | 264 | public function transactionStart() { |
265 | - if($this->transactionLevel === 0) { |
|
266 | - if($this->pdo->inTransaction()) { |
|
265 | + if ($this->transactionLevel === 0) { |
|
266 | + if ($this->pdo->inTransaction()) { |
|
267 | 267 | $this->outerTransaction = true; |
268 | 268 | } else { |
269 | 269 | $this->pdo->beginTransaction(); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | * @return $this |
278 | 278 | */ |
279 | 279 | public function transactionCommit() { |
280 | - return $this->transactionEnd(function () { |
|
280 | + return $this->transactionEnd(function() { |
|
281 | 281 | $this->pdo->commit(); |
282 | 282 | }); |
283 | 283 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @return $this |
287 | 287 | */ |
288 | 288 | public function transactionRollback() { |
289 | - return $this->transactionEnd(function () { |
|
289 | + return $this->transactionEnd(function() { |
|
290 | 290 | $this->pdo->rollBack(); |
291 | 291 | }); |
292 | 292 | } |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | * @return T |
298 | 298 | */ |
299 | 299 | public function dryRun(callable $callback) { |
300 | - if(!$this->pdo->inTransaction()) { |
|
300 | + if (!$this->pdo->inTransaction()) { |
|
301 | 301 | $this->transactionStart(); |
302 | 302 | try { |
303 | 303 | return $callback($this); |
@@ -322,14 +322,14 @@ discard block |
||
322 | 322 | * @throws Throwable |
323 | 323 | */ |
324 | 324 | public function transaction(callable $callback) { |
325 | - if(!$this->pdo->inTransaction()) { |
|
325 | + if (!$this->pdo->inTransaction()) { |
|
326 | 326 | $this->transactionStart(); |
327 | 327 | try { |
328 | 328 | $result = $callback($this); |
329 | 329 | $this->transactionCommit(); |
330 | 330 | return $result; |
331 | 331 | } catch (Throwable $e) { |
332 | - if($this->pdo->inTransaction()) { |
|
332 | + if ($this->pdo->inTransaction()) { |
|
333 | 333 | $this->transactionRollback(); |
334 | 334 | } |
335 | 335 | throw $e; |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | */ |
354 | 354 | private function transactionEnd(callable $fn): self { |
355 | 355 | $this->transactionLevel--; |
356 | - if($this->transactionLevel < 0) { |
|
356 | + if ($this->transactionLevel < 0) { |
|
357 | 357 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
358 | 358 | } |
359 | - if($this->transactionLevel < 1) { |
|
360 | - if($this->outerTransaction) { |
|
359 | + if ($this->transactionLevel < 1) { |
|
360 | + if ($this->outerTransaction) { |
|
361 | 361 | $this->outerTransaction = false; |
362 | 362 | } else { |
363 | 363 | $fn(); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | private function buildQueryStatement(string $query, callable $fn): QueryStatement { |
376 | 376 | $stmt = $fn($query); |
377 | - if(!$stmt) { |
|
377 | + if (!$stmt) { |
|
378 | 378 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
379 | 379 | } |
380 | 380 | return new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |