Completed
Push — master ( 886dc0...353d0e )
by Ron
02:09
created
src/Databases/MySQL.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 * @param PDO $pdo
35 35
 	 */
36 36
 	public function __construct(PDO $pdo) {
37
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
37
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
38 38
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
39 39
 		}
40 40
 		$this->pdo = $pdo;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 * @return QueryStatement
64 64
 	 */
65 65
 	public function query($query) {
66
-		return $this->buildQueryStatement($query, function ($query) {
66
+		return $this->buildQueryStatement($query, function($query) {
67 67
 			$stmt = $this->pdo->query($query);
68 68
 			return $stmt;
69 69
 		});
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @return QueryStatement
76 76
 	 */
77 77
 	public function prepare($query) {
78
-		return $this->buildQueryStatement((string) $query, function ($query) {
78
+		return $this->buildQueryStatement((string) $query, function($query) {
79 79
 			$stmt = $this->pdo->prepare($query);
80 80
 			return $stmt;
81 81
 		});
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 	 * @return int
88 88
 	 */
89 89
 	public function exec($query, array $params = array()) {
90
-		return $this->exceptionHandler(function () use ($query, $params) {
90
+		return $this->exceptionHandler(function() use ($query, $params) {
91 91
 			$stmt = $this->pdo->prepare($query);
92 92
 			$timer = microtime(true);
93 93
 			$stmt->execute($params);
94
-			$this->queryLoggers->log($query, microtime(true) - $timer);
94
+			$this->queryLoggers->log($query, microtime(true)-$timer);
95 95
 			$result = $stmt->rowCount();
96 96
 			$stmt->closeCursor();
97 97
 			return $result;
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	 */
112 112
 	public function getTableFields($table) {
113 113
 		$table = $this->select()->aliasReplacer()->replace($table);
114
-		if(array_key_exists($table, self::$tableFields)) {
114
+		if (array_key_exists($table, self::$tableFields)) {
115 115
 			return self::$tableFields[$table];
116 116
 		}
117 117
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
118 118
 		$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
119
-		self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows);
119
+		self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows);
120 120
 		$stmt->closeCursor();
121 121
 		return self::$tableFields[$table];
122 122
 	}
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 	 * @return string
128 128
 	 */
129 129
 	public function quoteExpression($expression, array $arguments = array()) {
130
-		$func = function () use ($arguments) {
130
+		$func = function() use ($arguments) {
131 131
 			static $idx = -1;
132 132
 			$idx++;
133 133
 			$index = $idx;
134
-			if(array_key_exists($index, $arguments)) {
134
+			if (array_key_exists($index, $arguments)) {
135 135
 				$argument = $arguments[$index];
136 136
 				$value = $this->quote($argument);
137 137
 			} else {
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 	 * @return string
149 149
 	 */
150 150
 	public function quote($value) {
151
-		if(is_null($value)) {
151
+		if (is_null($value)) {
152 152
 			$result = 'NULL';
153
-		} elseif($value instanceof Builder\DBExpr) {
153
+		} elseif ($value instanceof Builder\DBExpr) {
154 154
 			$result = $value->getExpression();
155
-		} elseif($value instanceof Builder\Select) {
155
+		} elseif ($value instanceof Builder\Select) {
156 156
 			$result = sprintf('(%s)', (string) $value);
157
-		} elseif(is_array($value)) {
158
-			$result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value));
157
+		} elseif (is_array($value)) {
158
+			$result = join(', ', array_map(function($value) { return $this->quote($value); }, $value));
159 159
 		} else {
160 160
 			$result = $this->pdo->quote($value);
161 161
 		}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		if (is_numeric($field) || !is_string($field)) {
171 171
 			throw new UnexpectedValueException('Field name is invalid');
172 172
 		}
173
-		if(strpos($field, '`') !== false) {
173
+		if (strpos($field, '`') !== false) {
174 174
 			return (string) $field;
175 175
 		}
176 176
 		$parts = explode('.', $field);
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	public function select(array $fields = null) {
185 185
 		$select = new Builder\RunnableSelect($this);
186
-		if($fields !== null) {
186
+		if ($fields !== null) {
187 187
 			$select->fields($fields);
188 188
 		}
189 189
 		return $select;
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 */
196 196
 	public function insert(array $fields = null) {
197 197
 		$insert = new Builder\RunnableInsert($this);
198
-		if($fields !== null) {
198
+		if ($fields !== null) {
199 199
 			$insert->addAll($fields);
200 200
 		}
201 201
 		return $insert;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 */
208 208
 	public function update(array $fields = null) {
209 209
 		$update = new Builder\RunnableUpdate($this);
210
-		if($fields !== null) {
210
+		if ($fields !== null) {
211 211
 			$update->setAll($fields);
212 212
 		}
213 213
 		return $update;
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
 	 * @return $this
225 225
 	 */
226 226
 	public function transactionStart() {
227
-		if((int) $this->transactionLevel === 0) {
228
-			if($this->pdo->inTransaction()) {
227
+		if ((int) $this->transactionLevel === 0) {
228
+			if ($this->pdo->inTransaction()) {
229 229
 				$this->outerTransaction = true;
230 230
 			} else {
231 231
 				$this->pdo->beginTransaction();
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 * @throws \Exception
241 241
 	 */
242 242
 	public function transactionCommit() {
243
-		return $this->transactionEnd(function () {
243
+		return $this->transactionEnd(function() {
244 244
 			$this->pdo->commit();
245 245
 		});
246 246
 	}
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * @throws \Exception
251 251
 	 */
252 252
 	public function transactionRollback() {
253
-		return $this->transactionEnd(function () {
253
+		return $this->transactionEnd(function() {
254 254
 			$this->pdo->rollBack();
255 255
 		});
256 256
 	}
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
 	public function dryRun($callback = null) {
265 265
 		$result = null;
266 266
 		$exception = null;
267
-		if(!$this->pdo->inTransaction()) {
267
+		if (!$this->pdo->inTransaction()) {
268 268
 			$this->transactionStart();
269 269
 			try {
270 270
 				$result = call_user_func($callback, $this);
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 				$exception = $e;
273 273
 			}
274 274
 			$this->transactionRollback();
275
-			if($exception !== null) {
275
+			if ($exception !== null) {
276 276
 				throw $exception;
277 277
 			}
278 278
 		} else {
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 				$exception = $e;
285 285
 			}
286 286
 			$this->exec("ROLLBACK TO {$uniqueId}");
287
-			if($exception !== null) {
287
+			if ($exception !== null) {
288 288
 				throw $exception;
289 289
 			}
290 290
 		}
@@ -299,15 +299,15 @@  discard block
 block discarded – undo
299 299
 	 * @throws null
300 300
 	 */
301 301
 	public function transaction($tries = 1, $callback = null) {
302
-		if(is_callable($tries)) {
302
+		if (is_callable($tries)) {
303 303
 			$callback = $tries;
304 304
 			$tries = 1;
305
-		} elseif(!is_callable($callback)) {
305
+		} elseif (!is_callable($callback)) {
306 306
 			throw new \Exception('$callback must be a callable');
307 307
 		}
308 308
 		$e = null;
309
-		if(!$this->pdo->inTransaction()) {
310
-			for(; $tries--;) {
309
+		if (!$this->pdo->inTransaction()) {
310
+			for (; $tries--;) {
311 311
 				try {
312 312
 					$this->transactionStart();
313 313
 					$result = call_user_func($callback, $this);
@@ -338,11 +338,11 @@  discard block
 block discarded – undo
338 338
 	 */
339 339
 	private function transactionEnd($fn) {
340 340
 		$this->transactionLevel--;
341
-		if($this->transactionLevel < 0) {
341
+		if ($this->transactionLevel < 0) {
342 342
 			throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
343 343
 		}
344
-		if((int) $this->transactionLevel === 0) {
345
-			if($this->outerTransaction) {
344
+		if ((int) $this->transactionLevel === 0) {
345
+			if ($this->outerTransaction) {
346 346
 				$this->outerTransaction = false;
347 347
 			} else {
348 348
 				call_user_func($fn);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	private function buildQueryStatement($query, $fn) {
361 361
 		$stmt = call_user_func($fn, $query);
362
-		if(!$stmt) {
362
+		if (!$stmt) {
363 363
 			throw new Exception("Could not execute statement:\n{$query}");
364 364
 		}
365 365
 		$stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.