Completed
Push — master ( 353d0e...6c7828 )
by Ron
01:57
created
src/Databases/MySQL.php 1 patch
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	 * @param array $options
38 38
 	 */
39 39
 	public function __construct(PDO $pdo, array $options = []) {
40
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
40
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
41 41
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
42 42
 		}
43 43
 		$this->pdo = $pdo;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return QueryStatement
74 74
 	 */
75 75
 	public function query($query) {
76
-		return $this->buildQueryStatement($query, function ($query) {
76
+		return $this->buildQueryStatement($query, function($query) {
77 77
 			$stmt = $this->pdo->query($query);
78 78
 			return $stmt;
79 79
 		});
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 	 * @return QueryStatement
86 86
 	 */
87 87
 	public function prepare($query) {
88
-		return $this->buildQueryStatement((string) $query, function ($query) {
88
+		return $this->buildQueryStatement((string) $query, function($query) {
89 89
 			$stmt = $this->pdo->prepare($query);
90 90
 			return $stmt;
91 91
 		});
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 	 * @return int
98 98
 	 */
99 99
 	public function exec($query, array $params = array()) {
100
-		return $this->exceptionHandler(function () use ($query, $params) {
100
+		return $this->exceptionHandler(function() use ($query, $params) {
101 101
 			$stmt = $this->pdo->prepare($query);
102 102
 			$timer = microtime(true);
103 103
 			$stmt->execute($params);
104
-			$this->queryLoggers->log($query, microtime(true) - $timer);
104
+			$this->queryLoggers->log($query, microtime(true)-$timer);
105 105
 			$result = $stmt->rowCount();
106 106
 			$stmt->closeCursor();
107 107
 			return $result;
@@ -121,12 +121,12 @@  discard block
 block discarded – undo
121 121
 	 */
122 122
 	public function getTableFields($table) {
123 123
 		$table = $this->select()->aliasReplacer()->replace($table);
124
-		if(array_key_exists($table, self::$tableFields)) {
124
+		if (array_key_exists($table, self::$tableFields)) {
125 125
 			return self::$tableFields[$table];
126 126
 		}
127 127
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
128 128
 		$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
129
-		self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows);
129
+		self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows);
130 130
 		$stmt->closeCursor();
131 131
 		return self::$tableFields[$table];
132 132
 	}
@@ -137,11 +137,11 @@  discard block
 block discarded – undo
137 137
 	 * @return string
138 138
 	 */
139 139
 	public function quoteExpression($expression, array $arguments = array()) {
140
-		$func = function () use ($arguments) {
140
+		$func = function() use ($arguments) {
141 141
 			static $idx = -1;
142 142
 			$idx++;
143 143
 			$index = $idx;
144
-			if(array_key_exists($index, $arguments)) {
144
+			if (array_key_exists($index, $arguments)) {
145 145
 				$argument = $arguments[$index];
146 146
 				$value = $this->quote($argument);
147 147
 			} else {
@@ -158,14 +158,14 @@  discard block
 block discarded – undo
158 158
 	 * @return string
159 159
 	 */
160 160
 	public function quote($value) {
161
-		if(is_null($value)) {
161
+		if (is_null($value)) {
162 162
 			$result = 'NULL';
163
-		} elseif($value instanceof Builder\DBExpr) {
163
+		} elseif ($value instanceof Builder\DBExpr) {
164 164
 			$result = $value->getExpression();
165
-		} elseif($value instanceof Builder\Select) {
165
+		} elseif ($value instanceof Builder\Select) {
166 166
 			$result = sprintf('(%s)', (string) $value);
167
-		} elseif(is_array($value)) {
168
-			$result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value));
167
+		} elseif (is_array($value)) {
168
+			$result = join(', ', array_map(function($value) { return $this->quote($value); }, $value));
169 169
 		} else {
170 170
 			$result = $this->pdo->quote($value);
171 171
 		}
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 		if (is_numeric($field) || !is_string($field)) {
181 181
 			throw new UnexpectedValueException('Field name is invalid');
182 182
 		}
183
-		if(strpos($field, '`') !== false) {
183
+		if (strpos($field, '`') !== false) {
184 184
 			return (string) $field;
185 185
 		}
186 186
 		$parts = explode('.', $field);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 		$select = array_key_exists('select-factory', $this->options)
196 196
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
197 197
 			: new Builder\RunnableSelect($this, $this->options['select-options']);
198
-		if($fields !== null) {
198
+		if ($fields !== null) {
199 199
 			$select->fields($fields);
200 200
 		}
201 201
 		return $select;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		$insert = array_key_exists('insert-factory', $this->options)
210 210
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
211 211
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
212
-		if($fields !== null) {
212
+		if ($fields !== null) {
213 213
 			$insert->addAll($fields);
214 214
 		}
215 215
 		return $insert;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 		$update = array_key_exists('update-factory', $this->options)
224 224
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
225 225
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
226
-		if($fields !== null) {
226
+		if ($fields !== null) {
227 227
 			$update->setAll($fields);
228 228
 		}
229 229
 		return $update;
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
 	 * @return $this
243 243
 	 */
244 244
 	public function transactionStart() {
245
-		if((int) $this->transactionLevel === 0) {
246
-			if($this->pdo->inTransaction()) {
245
+		if ((int) $this->transactionLevel === 0) {
246
+			if ($this->pdo->inTransaction()) {
247 247
 				$this->outerTransaction = true;
248 248
 			} else {
249 249
 				$this->pdo->beginTransaction();
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 	 * @throws \Exception
259 259
 	 */
260 260
 	public function transactionCommit() {
261
-		return $this->transactionEnd(function () {
261
+		return $this->transactionEnd(function() {
262 262
 			$this->pdo->commit();
263 263
 		});
264 264
 	}
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 	 * @throws \Exception
269 269
 	 */
270 270
 	public function transactionRollback() {
271
-		return $this->transactionEnd(function () {
271
+		return $this->transactionEnd(function() {
272 272
 			$this->pdo->rollBack();
273 273
 		});
274 274
 	}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	public function dryRun($callback = null) {
283 283
 		$result = null;
284 284
 		$exception = null;
285
-		if(!$this->pdo->inTransaction()) {
285
+		if (!$this->pdo->inTransaction()) {
286 286
 			$this->transactionStart();
287 287
 			try {
288 288
 				$result = call_user_func($callback, $this);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 				$exception = $e;
291 291
 			}
292 292
 			$this->transactionRollback();
293
-			if($exception !== null) {
293
+			if ($exception !== null) {
294 294
 				throw $exception;
295 295
 			}
296 296
 		} else {
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 				$exception = $e;
303 303
 			}
304 304
 			$this->exec("ROLLBACK TO {$uniqueId}");
305
-			if($exception !== null) {
305
+			if ($exception !== null) {
306 306
 				throw $exception;
307 307
 			}
308 308
 		}
@@ -317,15 +317,15 @@  discard block
 block discarded – undo
317 317
 	 * @throws null
318 318
 	 */
319 319
 	public function transaction($tries = 1, $callback = null) {
320
-		if(is_callable($tries)) {
320
+		if (is_callable($tries)) {
321 321
 			$callback = $tries;
322 322
 			$tries = 1;
323
-		} elseif(!is_callable($callback)) {
323
+		} elseif (!is_callable($callback)) {
324 324
 			throw new \Exception('$callback must be a callable');
325 325
 		}
326 326
 		$e = null;
327
-		if(!$this->pdo->inTransaction()) {
328
-			for(; $tries--;) {
327
+		if (!$this->pdo->inTransaction()) {
328
+			for (; $tries--;) {
329 329
 				try {
330 330
 					$this->transactionStart();
331 331
 					$result = call_user_func($callback, $this);
@@ -356,11 +356,11 @@  discard block
 block discarded – undo
356 356
 	 */
357 357
 	private function transactionEnd($fn) {
358 358
 		$this->transactionLevel--;
359
-		if($this->transactionLevel < 0) {
359
+		if ($this->transactionLevel < 0) {
360 360
 			throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
361 361
 		}
362
-		if((int) $this->transactionLevel === 0) {
363
-			if($this->outerTransaction) {
362
+		if ((int) $this->transactionLevel === 0) {
363
+			if ($this->outerTransaction) {
364 364
 				$this->outerTransaction = false;
365 365
 			} else {
366 366
 				call_user_func($fn);
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	 */
378 378
 	private function buildQueryStatement($query, $fn) {
379 379
 		$stmt = call_user_func($fn, $query);
380
-		if(!$stmt) {
380
+		if (!$stmt) {
381 381
 			throw new Exception("Could not execute statement:\n{$query}");
382 382
 		}
383 383
 		$stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.
src/Builder/RunnableSelect.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @throws \Exception
94 94
 	 */
95 95
 	public function fetchRow(Closure $callback = null) {
96
-		return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) {
96
+		return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) {
97 97
 			return ['valid' => is_array($row), 'default' => []];
98 98
 		});
99 99
 	}
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @throws \Exception
125 125
 	 */
126 126
 	public function fetchObject($className = null, Closure $callback = null) {
127
-		return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function ($row) {
127
+		return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function($row) {
128 128
 			return ['valid' => is_object($row), 'default' => null];
129 129
 		});
130 130
 	}
@@ -134,11 +134,11 @@  discard block
 block discarded – undo
134 134
 	 * @return mixed[]
135 135
 	 */
136 136
 	public function fetchKeyValue($treatValueAsArray = false) {
137
-		return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) {
138
-			if($treatValueAsArray) {
137
+		return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) {
138
+			if ($treatValueAsArray) {
139 139
 				$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);
140 140
 				$result = array();
141
-				foreach($rows as $row) {
141
+				foreach ($rows as $row) {
142 142
 					list($key) = array_values($row);
143 143
 					$result[$key] = $row;
144 144
 				}
@@ -155,11 +155,11 @@  discard block
 block discarded – undo
155 155
 	public function fetchGroups(array $fields) {
156 156
 		$rows = $this->fetchRows();
157 157
 		$result = array();
158
-		foreach($rows as $row) {
158
+		foreach ($rows as $row) {
159 159
 			$tmp = &$result;
160
-			foreach($fields as $field) {
160
+			foreach ($fields as $field) {
161 161
 				$value = $row[$field];
162
-				if(!array_key_exists($value, $tmp)) {
162
+				if (!array_key_exists($value, $tmp)) {
163 163
 					$tmp[$value] = [];
164 164
 				}
165 165
 				$tmp = &$tmp[$value];
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	 * @return string[]
174 174
 	 */
175 175
 	public function fetchArray() {
176
-		return $this->createTempStatement(function (QueryStatement $stmt) {
176
+		return $this->createTempStatement(function(QueryStatement $stmt) {
177 177
 			return $stmt->fetchAll(\PDO::FETCH_COLUMN);
178 178
 		});
179 179
 	}
@@ -183,9 +183,9 @@  discard block
 block discarded – undo
183 183
 	 * @return null|bool|string|int|float
184 184
 	 */
185 185
 	public function fetchValue($default = null) {
186
-		return $this->createTempStatement(function (QueryStatement $stmt) use ($default) {
186
+		return $this->createTempStatement(function(QueryStatement $stmt) use ($default) {
187 187
 			$result = $stmt->fetch(\PDO::FETCH_NUM);
188
-			if($result !== false) {
188
+			if ($result !== false) {
189 189
 				return $result[0];
190 190
 			}
191 191
 			return $default;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		$query = $this->__toString();
226 226
 		$statement = $db->prepare($query);
227 227
 		$statement->execute($this->values);
228
-		if($this->getCalcFoundRows()) {
228
+		if ($this->getCalcFoundRows()) {
229 229
 			$this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn();
230 230
 		}
231 231
 		return $statement;
@@ -246,20 +246,20 @@  discard block
 block discarded – undo
246 246
 	 * @throws \Exception
247 247
 	 */
248 248
 	private function fetchAll(Closure $callback = null, $mode, $arg0 = null) {
249
-		return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) {
249
+		return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) {
250 250
 			$statement->setFetchMode($mode, $arg0);
251 251
 			$data = $statement->fetchAll();
252
-			if($this->preserveTypes) {
252
+			if ($this->preserveTypes) {
253 253
 				$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
254
-				foreach($data as &$row) {
254
+				foreach ($data as &$row) {
255 255
 					$row = FieldValueConverter::convertValues($row, $columnDefinitions);
256 256
 				}
257 257
 			}
258
-			if($callback !== null) {
259
-				return call_user_func(function ($resultData = []) use ($data, $callback) {
260
-					foreach($data as $row) {
258
+			if ($callback !== null) {
259
+				return call_user_func(function($resultData = []) use ($data, $callback) {
260
+					foreach ($data as $row) {
261 261
 						$result = $callback($row);
262
-						if($result !== null && !($result instanceof DBIgnoreRow)) {
262
+						if ($result !== null && !($result instanceof DBIgnoreRow)) {
263 263
 							$resultData[] = $result;
264 264
 						} else {
265 265
 							$resultData[] = $row;
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 	 * @return Generator|YieldPolyfillIterator|mixed[]
280 280
 	 */
281 281
 	private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) {
282
-		if(version_compare(PHP_VERSION, '5.5', '<')) {
283
-			return new YieldPolyfillIterator($callback, $this->preserveTypes, function () use ($mode, $arg0) {
282
+		if (version_compare(PHP_VERSION, '5.5', '<')) {
283
+			return new YieldPolyfillIterator($callback, $this->preserveTypes, function() use ($mode, $arg0) {
284 284
 				$statement = $this->createStatement();
285 285
 				$statement->setFetchMode($mode, $arg0);
286 286
 				return $statement;
@@ -301,20 +301,20 @@  discard block
 block discarded – undo
301 301
 	 * @throws \Exception
302 302
 	 */
303 303
 	private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) {
304
-		return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
304
+		return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
305 305
 			$statement->setFetchMode($mode, $arg0);
306 306
 			$row = $statement->fetch();
307 307
 			$result = $resultValidator($row);
308
-			if(!$result['valid']) {
308
+			if (!$result['valid']) {
309 309
 				return $result['default'];
310 310
 			}
311
-			if($this->preserveTypes) {
311
+			if ($this->preserveTypes) {
312 312
 				$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
313 313
 				$row = FieldValueConverter::convertValues($row, $columnDefinitions);
314 314
 			}
315
-			if($callback !== null) {
315
+			if ($callback !== null) {
316 316
 				$result = $callback($row);
317
-				if($result !== null) {
317
+				if ($result !== null) {
318 318
 					$row = $result;
319 319
 				}
320 320
 			}
Please login to merge, or discard this patch.