Completed
Push — master ( 45ed41...8eb0a3 )
by Ron
02:32
created
src/Databases/MySQL.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @param array $options
42 42
 	 */
43 43
 	public function __construct(PDO $pdo, array $options = []) {
44
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
44
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
45 45
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
46 46
 		}
47 47
 		$this->pdo = $pdo;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @return VirtualTables
76 76
 	 */
77 77
 	public function getVirtualTables() {
78
-		if($this->virtualTables === null) {
78
+		if ($this->virtualTables === null) {
79 79
 			$this->virtualTables = new VirtualTables();
80 80
 		}
81 81
 		return $this->virtualTables;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @return QueryStatement
88 88
 	 */
89 89
 	public function query($query) {
90
-		return $this->buildQueryStatement($query, function ($query) {
90
+		return $this->buildQueryStatement($query, function($query) {
91 91
 			$stmt = $this->pdo->query($query);
92 92
 			return $stmt;
93 93
 		});
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @return QueryStatement
100 100
 	 */
101 101
 	public function prepare($query) {
102
-		return $this->buildQueryStatement((string) $query, function ($query) {
102
+		return $this->buildQueryStatement((string) $query, function($query) {
103 103
 			$stmt = $this->pdo->prepare($query);
104 104
 			return $stmt;
105 105
 		});
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 	 * @return int
112 112
 	 */
113 113
 	public function exec($query, array $params = array()) {
114
-		return $this->exceptionHandler(function () use ($query, $params) {
114
+		return $this->exceptionHandler(function() use ($query, $params) {
115 115
 			$stmt = $this->pdo->prepare($query);
116 116
 			$timer = microtime(true);
117 117
 			$stmt->execute($params);
118
-			$this->queryLoggers->log($query, microtime(true) - $timer);
118
+			$this->queryLoggers->log($query, microtime(true)-$timer);
119 119
 			$result = $stmt->rowCount();
120 120
 			$stmt->closeCursor();
121 121
 			return $result;
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public function getTableFields($table) {
137 137
 		$table = $this->select()->aliasReplacer()->replace($table);
138
-		if(array_key_exists($table, self::$tableFields)) {
138
+		if (array_key_exists($table, self::$tableFields)) {
139 139
 			return self::$tableFields[$table];
140 140
 		}
141 141
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
142 142
 		$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
143
-		self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows);
143
+		self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows);
144 144
 		$stmt->closeCursor();
145 145
 		return self::$tableFields[$table];
146 146
 	}
@@ -152,12 +152,12 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function quoteExpression($expression, array $arguments = array()) {
154 154
 		$index = -1;
155
-		$func = function () use ($arguments, &$index) {
155
+		$func = function() use ($arguments, &$index) {
156 156
 			$index++;
157
-			if(array_key_exists($index, $arguments)) {
157
+			if (array_key_exists($index, $arguments)) {
158 158
 				$argument = $arguments[$index];
159 159
 				$value = $this->quote($argument);
160
-			} elseif(count($arguments) > 0) {
160
+			} elseif (count($arguments) > 0) {
161 161
 				$args = $arguments;
162 162
 				$value = array_pop($args);
163 163
 				$value = $this->quote($value);
@@ -175,14 +175,14 @@  discard block
 block discarded – undo
175 175
 	 * @return string
176 176
 	 */
177 177
 	public function quote($value) {
178
-		if(is_null($value)) {
178
+		if (is_null($value)) {
179 179
 			$result = 'NULL';
180
-		} elseif($value instanceof Builder\DBExpr) {
180
+		} elseif ($value instanceof Builder\DBExpr) {
181 181
 			$result = $value->getExpression();
182
-		} elseif($value instanceof Builder\Select) {
182
+		} elseif ($value instanceof Builder\Select) {
183 183
 			$result = sprintf('(%s)', (string) $value);
184
-		} elseif(is_array($value)) {
185
-			$result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value));
184
+		} elseif (is_array($value)) {
185
+			$result = join(', ', array_map(function($value) { return $this->quote($value); }, $value));
186 186
 		} else {
187 187
 			$result = $this->pdo->quote($value);
188 188
 		}
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 		if (is_numeric($field) || !is_string($field)) {
198 198
 			throw new UnexpectedValueException('Field name is invalid');
199 199
 		}
200
-		if(strpos($field, '`') !== false) {
200
+		if (strpos($field, '`') !== false) {
201 201
 			return (string) $field;
202 202
 		}
203 203
 		$parts = explode('.', $field);
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 		$select = array_key_exists('select-factory', $this->options)
213 213
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
214 214
 			: new Builder\RunnableSelect($this, $this->options['select-options']);
215
-		if($fields !== null) {
215
+		if ($fields !== null) {
216 216
 			$select->fields($fields);
217 217
 		}
218 218
 		return $select;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		$insert = array_key_exists('insert-factory', $this->options)
227 227
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
228 228
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
229
-		if($fields !== null) {
229
+		if ($fields !== null) {
230 230
 			$insert->addAll($fields);
231 231
 		}
232 232
 		return $insert;
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 		$update = array_key_exists('update-factory', $this->options)
241 241
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
242 242
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
243
-		if($fields !== null) {
243
+		if ($fields !== null) {
244 244
 			$update->setAll($fields);
245 245
 		}
246 246
 		return $update;
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @return $this
260 260
 	 */
261 261
 	public function transactionStart() {
262
-		if((int) $this->transactionLevel === 0) {
263
-			if($this->pdo->inTransaction()) {
262
+		if ((int) $this->transactionLevel === 0) {
263
+			if ($this->pdo->inTransaction()) {
264 264
 				$this->outerTransaction = true;
265 265
 			} else {
266 266
 				$this->pdo->beginTransaction();
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 	 * @return $this
275 275
 	 */
276 276
 	public function transactionCommit() {
277
-		return $this->transactionEnd(function () {
277
+		return $this->transactionEnd(function() {
278 278
 			$this->pdo->commit();
279 279
 		});
280 280
 	}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	 * @return $this
284 284
 	 */
285 285
 	public function transactionRollback() {
286
-		return $this->transactionEnd(function () {
286
+		return $this->transactionEnd(function() {
287 287
 			$this->pdo->rollBack();
288 288
 		});
289 289
 	}
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	 */
295 295
 	public function dryRun($callback = null) {
296 296
 		$result = null;
297
-		if(!$this->pdo->inTransaction()) {
297
+		if (!$this->pdo->inTransaction()) {
298 298
 			$this->transactionStart();
299 299
 			try {
300 300
 				$result = call_user_func($callback, $this);
@@ -329,16 +329,16 @@  discard block
 block discarded – undo
329 329
 	 * @return mixed
330 330
 	 */
331 331
 	public function transaction($tries = 1, $callback = null) {
332
-		if(is_callable($tries)) {
332
+		if (is_callable($tries)) {
333 333
 			$callback = $tries;
334 334
 			$tries = 1;
335
-		} elseif(!is_callable($callback)) {
335
+		} elseif (!is_callable($callback)) {
336 336
 			throw new RuntimeException('$callback must be a callable');
337 337
 		}
338 338
 		$result = null;
339 339
 		$exception = null;
340
-		for(; $tries--;) {
341
-			if(!$this->pdo->inTransaction()) {
340
+		for (; $tries--;) {
341
+			if (!$this->pdo->inTransaction()) {
342 342
 				$this->transactionStart();
343 343
 				try {
344 344
 					$result = call_user_func($callback, $this);
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 				}
368 368
 			}
369 369
 		}
370
-		if($exception !== null) {
370
+		if ($exception !== null) {
371 371
 			throw new RuntimeException($exception->getMessage(), (int) $exception->getCode(), $exception);
372 372
 		}
373 373
 		return $result;
@@ -380,11 +380,11 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	private function transactionEnd($fn) {
382 382
 		$this->transactionLevel--;
383
-		if($this->transactionLevel < 0) {
383
+		if ($this->transactionLevel < 0) {
384 384
 			throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
385 385
 		}
386
-		if((int) $this->transactionLevel === 0) {
387
-			if($this->outerTransaction) {
386
+		if ((int) $this->transactionLevel === 0) {
387
+			if ($this->outerTransaction) {
388 388
 				$this->outerTransaction = false;
389 389
 			} else {
390 390
 				call_user_func($fn);
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 	 */
402 402
 	private function buildQueryStatement($query, $fn) {
403 403
 		$stmt = call_user_func($fn, $query);
404
-		if(!$stmt) {
404
+		if (!$stmt) {
405 405
 			throw new RuntimeException("Could not execute statement:\n{$query}");
406 406
 		}
407 407
 		$stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.