Completed
Push — master ( 353d0e...6c7828 )
by Ron
01:57
created
src/Builder/Traits/HavingBuilder.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@
 block discarded – undo
16 16
 	 * @return $this
17 17
 	 */
18 18
 	public function having($expression) {
19
-		if($expression instanceof OptionalExpression) {
20
-			if($expression->isValid()) {
19
+		if ($expression instanceof OptionalExpression) {
20
+			if ($expression->isValid()) {
21 21
 				$this->having[] = [$expression->getExpression(), $expression->getValue()];
22 22
 			}
23 23
 		} else {
Please login to merge, or discard this patch.
src/Builder/Traits/OrderByBuilder.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
 	 * @return $this
16 16
 	 */
17 17
 	public function orderBy($expression, $direction = 'asc') {
18
-		if($expression instanceof OrderBySpecification) {
19
-			foreach($expression->getFields() as $field) {
18
+		if ($expression instanceof OrderBySpecification) {
19
+			foreach ($expression->getFields() as $field) {
20 20
 				$this->addOrder($field[0], $field[1]);
21 21
 			}
22 22
 			return $this;
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 */
33 33
 	public function orderByValues($fieldName, array $values) {
34 34
 		$expr = [];
35
-		foreach(array_values($values) as $idx => $value) {
35
+		foreach (array_values($values) as $idx => $value) {
36 36
 			$expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", array($value, $idx));
37 37
 		}
38 38
 		$this->orderBy[] = array(sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC');
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 	 * @return string
45 45
 	 */
46 46
 	protected function buildOrder($query) {
47
-		if(!count($this->orderBy)) {
47
+		if (!count($this->orderBy)) {
48 48
 			return $query;
49 49
 		}
50 50
 		$query .= "ORDER BY\n";
51 51
 		$arr = array();
52
-		foreach($this->orderBy as $order) {
52
+		foreach ($this->orderBy as $order) {
53 53
 			list($expression, $direction) = $order;
54 54
 			$arr[] = sprintf("\t%s %s", $expression, strtoupper($direction));
55 55
 		}
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	private function addOrder($expression, $direction) {
64 64
 		$direction = $this->fixDirection($direction);
65
-		if(is_array($expression)) {
66
-			if(!count($expression)) {
65
+		if (is_array($expression)) {
66
+			if (!count($expression)) {
67 67
 				return;
68 68
 			}
69 69
 			$arguments = array(
Please login to merge, or discard this patch.
src/Builder/Traits/WhereBuilder.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,8 +16,8 @@
 block discarded – undo
16 16
 	 * @return $this
17 17
 	 */
18 18
 	public function where($expression) {
19
-		if($expression instanceof OptionalExpression) {
20
-			if($expression->isValid()) {
19
+		if ($expression instanceof OptionalExpression) {
20
+			if ($expression->isValid()) {
21 21
 				$this->where[] = [$expression->getExpression(), $expression->getValue()];
22 22
 			}
23 23
 		} else {
Please login to merge, or discard this patch.
src/Builder/Expr/DBExprOrderBySpec.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,16 +11,16 @@
 block discarded – undo
11 11
 	 */
12 12
 	public function __construct($spec, $sortFieldsSpec) {
13 13
 		$expressions = [];
14
-		foreach($spec as $specReference => $dbExpr) {
15
-			if(is_int($specReference)) {
14
+		foreach ($spec as $specReference => $dbExpr) {
15
+			if (is_int($specReference)) {
16 16
 				$specReference = $dbExpr;
17 17
 			}
18 18
 			$expressions[$specReference] = $dbExpr;
19 19
 		}
20
-		foreach($sortFieldsSpec as $sortFieldSpec) {
21
-			if(array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) {
20
+		foreach ($sortFieldsSpec as $sortFieldSpec) {
21
+			if (array_key_exists(0, $sortFieldSpec) && array_key_exists($sortFieldSpec[0], $expressions)) {
22 22
 				$direction = 'ASC';
23
-				if(array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') {
23
+				if (array_key_exists(1, $sortFieldSpec) && strtoupper($sortFieldSpec[1]) !== 'ASC') {
24 24
 					$direction = 'DESC';
25 25
 				}
26 26
 				$this->fields[] = [
Please login to merge, or discard this patch.
src/Databases/MySQL/MySQLExceptionInterpreter.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
 	public function throwMoreConcreteException(PDOException $exception) {
17 17
 		$code = $exception->getCode();
18 18
 		$message = (string) $exception->getMessage();
19
-		switch($code) {
19
+		switch ($code) {
20 20
 			case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception);
21 21
 			case 1213: throw new SqlDeadLockException($message, $code, $exception);
22 22
 			case 1205: throw new LockWaitTimeoutExceededException($message, $code, $exception);
23 23
 			case 1062: throw new DuplicateUniqueKeyException($message, $code, $exception);
24 24
 		}
25 25
 		/** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */
26
-		if(!is_string($message) || !is_int($code)) {
26
+		if (!is_string($message) || !is_int($code)) {
27 27
 			throw new SqlException((string) $message, (int) $code, $exception);
28 28
 		}
29 29
 		throw $exception;
Please login to merge, or discard this patch.
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.