Completed
Push — master ( 24b612...1ea10a )
by Ron
16:01 queued 01:32
created
src/Databases/MySQL.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @param PDO $pdo
36 36
 	 */
37 37
 	public function __construct(PDO $pdo) {
38
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
38
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
39 39
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
40 40
 		}
41 41
 		$this->pdo = $pdo;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return QueryStatement
65 65
 	 */
66 66
 	public function query($query) {
67
-		return $this->buildQueryStatement($query, function ($query) {
67
+		return $this->buildQueryStatement($query, function($query) {
68 68
 			$stmt = $this->pdo->query($query);
69 69
 			return $stmt;
70 70
 		});
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @return QueryStatement
77 77
 	 */
78 78
 	public function prepare($query) {
79
-		return $this->buildQueryStatement((string) $query, function ($query) {
79
+		return $this->buildQueryStatement((string) $query, function($query) {
80 80
 			$stmt = $this->pdo->prepare($query);
81 81
 			return $stmt;
82 82
 		});
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 			$stmt = $this->pdo->prepare($query);
93 93
 			$timer = microtime(true);
94 94
 			$stmt->execute($params);
95
-			$this->queryLoggers->log($query, microtime(true) - $timer);
95
+			$this->queryLoggers->log($query, microtime(true)-$timer);
96 96
 			$result = $stmt->rowCount();
97 97
 			$stmt->closeCursor();
98 98
 			return $result;
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 	 */
116 116
 	public function getTableFields($table) {
117 117
 		$table = $this->select()->aliasReplacer()->replace($table);
118
-		if(array_key_exists($table, self::$tableFields)) {
118
+		if (array_key_exists($table, self::$tableFields)) {
119 119
 			return self::$tableFields[$table];
120 120
 		}
121 121
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
122 122
 		$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
123
-		self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows);
123
+		self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows);
124 124
 		$stmt->closeCursor();
125 125
 		return self::$tableFields[$table];
126 126
 	}
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	 * @return string
132 132
 	 */
133 133
 	public function quoteExpression($expression, array $arguments = array()) {
134
-		$func = function ($oldValue) use ($arguments) {
134
+		$func = function($oldValue) use ($arguments) {
135 135
 			static $idx = -1;
136 136
 			$idx++;
137 137
 			$index = $idx;
138 138
 
139
-			if(array_key_exists($index, $arguments)) {
139
+			if (array_key_exists($index, $arguments)) {
140 140
 				$argument = $arguments[$index];
141 141
 				$value = $this->quote($argument);
142 142
 			} else {
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 	 * @return string
154 154
 	 */
155 155
 	public function quote($value) {
156
-		if(is_null($value)) {
156
+		if (is_null($value)) {
157 157
 			$result = 'NULL';
158
-		} elseif($value instanceof Builder\Select) {
158
+		} elseif ($value instanceof Builder\Select) {
159 159
 			$result = sprintf('(%s)', (string) $value);
160
-		} elseif(is_array($value)) {
161
-			$result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value));
160
+		} elseif (is_array($value)) {
161
+			$result = join(', ', array_map(function($value) { return $this->quote($value); }, $value));
162 162
 		/*} elseif(is_int(trim($value)) && strpos('123456789', substr(0, 1, trim($value))) !== null) {
163 163
 			$result = $value;*/
164 164
 		} else {
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		if (is_numeric($field) || !is_string($field)) {
176 176
 			throw new UnexpectedValueException('Field name is invalid');
177 177
 		}
178
-		if(strpos($field, '`') !== false) {
178
+		if (strpos($field, '`') !== false) {
179 179
 			return (string) $field;
180 180
 		}
181 181
 		$parts = explode('.', $field);
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	public function select(array $fields = null) {
190 190
 		$select = new RunnableSelect($this);
191
-		if($fields !== null) {
191
+		if ($fields !== null) {
192 192
 			$select->fields($fields);
193 193
 		}
194 194
 		return $select;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 */
201 201
 	public function insert(array $fields = null) {
202 202
 		$insert = new Builder\RunnableInsert($this);
203
-		if($fields !== null) {
203
+		if ($fields !== null) {
204 204
 			$insert->addAll($fields);
205 205
 		}
206 206
 		return $insert;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 	 */
213 213
 	public function update(array $fields = null) {
214 214
 		$update = new Builder\RunnableUpdate($this);
215
-		if($fields !== null) {
215
+		if ($fields !== null) {
216 216
 			$update->setAll($fields);
217 217
 		}
218 218
 		return $update;
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 	 * @return $this
230 230
 	 */
231 231
 	public function transactionStart() {
232
-		if((int) $this->transactionLevel === 0) {
233
-			if($this->pdo->inTransaction()) {
232
+		if ((int) $this->transactionLevel === 0) {
233
+			if ($this->pdo->inTransaction()) {
234 234
 				$this->outerTransaction = true;
235 235
 			} else {
236 236
 				$this->pdo->beginTransaction();
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @throws \Exception
246 246
 	 */
247 247
 	public function transactionCommit() {
248
-		return $this->transactionEnd(function () {
248
+		return $this->transactionEnd(function() {
249 249
 			$this->pdo->commit();
250 250
 		});
251 251
 	}
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
 	 * @throws \Exception
256 256
 	 */
257 257
 	public function transactionRollback() {
258
-		return $this->transactionEnd(function () {
258
+		return $this->transactionEnd(function() {
259 259
 			$this->pdo->rollBack();
260 260
 		});
261 261
 	}
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
 	 * @throws null
269 269
 	 */
270 270
 	public function transaction($tries = 1, $callback = null) {
271
-		if(is_callable($tries)) {
271
+		if (is_callable($tries)) {
272 272
 			$callback = $tries;
273 273
 			$tries = 1;
274
-		} elseif(!is_callable($callback)) {
274
+		} elseif (!is_callable($callback)) {
275 275
 			throw new \Exception('$callback must be a callable');
276 276
 		}
277 277
 		$e = null;
278
-		for(; $tries--;) {
278
+		for (; $tries--;) {
279 279
 			try {
280 280
 				$this->transactionStart();
281 281
 				$result = call_user_func($callback, $this);
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	private function transactionEnd($fn) {
297 297
 		$this->transactionLevel--;
298
-		if($this->transactionLevel < 0) {
298
+		if ($this->transactionLevel < 0) {
299 299
 			throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
300 300
 		}
301
-		if((int) $this->transactionLevel === 0) {
302
-			if($this->outerTransaction) {
301
+		if ((int) $this->transactionLevel === 0) {
302
+			if ($this->outerTransaction) {
303 303
 				$this->outerTransaction = false;
304 304
 			} else {
305 305
 				call_user_func($fn);
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 	 */
317 317
 	private function buildQueryStatement($query, $fn) {
318 318
 		$stmt = call_user_func($fn, $query);
319
-		if(!$stmt) {
319
+		if (!$stmt) {
320 320
 			throw new Exception("Could not execute statement:\n{$query}");
321 321
 		}
322 322
 		$stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.