Completed
Push — master ( 886dc0...353d0e )
by Ron
02:09
created
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/Builder/RunnableSelect.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @throws \Exception
81 81
 	 */
82 82
 	public function fetchRow(Closure $callback = null) {
83
-		return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) {
83
+		return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) {
84 84
 			return ['valid' => is_array($row), 'default' => []];
85 85
 		});
86 86
 	}
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @throws \Exception
112 112
 	 */
113 113
 	public function fetchObject($className = 'stdClass', Closure $callback = null) {
114
-		return $this->fetch($callback, PDO::FETCH_CLASS, $className, function ($row) {
114
+		return $this->fetch($callback, PDO::FETCH_CLASS, $className, function($row) {
115 115
 			return ['valid' => is_object($row), 'default' => null];
116 116
 		});
117 117
 	}
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
 	 * @return mixed[]
122 122
 	 */
123 123
 	public function fetchKeyValue($treatValueAsArray = false) {
124
-		return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) {
125
-			if($treatValueAsArray) {
124
+		return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) {
125
+			if ($treatValueAsArray) {
126 126
 				$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);
127 127
 				$result = array();
128
-				foreach($rows as $row) {
128
+				foreach ($rows as $row) {
129 129
 					list($key) = array_values($row);
130 130
 					$result[$key] = $row;
131 131
 				}
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	public function fetchGroups(array $fields) {
143 143
 		$rows = $this->fetchRows();
144 144
 		$result = array();
145
-		foreach($rows as $row) {
145
+		foreach ($rows as $row) {
146 146
 			$tmp = &$result;
147
-			foreach($fields as $field) {
147
+			foreach ($fields as $field) {
148 148
 				$value = $row[$field];
149
-				if(!array_key_exists($value, $tmp)) {
149
+				if (!array_key_exists($value, $tmp)) {
150 150
 					$tmp[$value] = [];
151 151
 				}
152 152
 				$tmp = &$tmp[$value];
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	 * @return string[]
161 161
 	 */
162 162
 	public function fetchArray() {
163
-		return $this->createTempStatement(function (QueryStatement $stmt) {
163
+		return $this->createTempStatement(function(QueryStatement $stmt) {
164 164
 			return $stmt->fetchAll(\PDO::FETCH_COLUMN);
165 165
 		});
166 166
 	}
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
 	 * @return null|bool|string|int|float
171 171
 	 */
172 172
 	public function fetchValue($default = null) {
173
-		return $this->createTempStatement(function (QueryStatement $stmt) use ($default) {
173
+		return $this->createTempStatement(function(QueryStatement $stmt) use ($default) {
174 174
 			$result = $stmt->fetch(\PDO::FETCH_NUM);
175
-			if($result !== false) {
175
+			if ($result !== false) {
176 176
 				return $result[0];
177 177
 			}
178 178
 			return $default;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 		$query = $this->__toString();
213 213
 		$statement = $db->prepare($query);
214 214
 		$statement->execute($this->values);
215
-		if($this->getCalcFoundRows()) {
215
+		if ($this->getCalcFoundRows()) {
216 216
 			$this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn();
217 217
 		}
218 218
 		return $statement;
@@ -233,20 +233,20 @@  discard block
 block discarded – undo
233 233
 	 * @throws \Exception
234 234
 	 */
235 235
 	private function fetchAll(Closure $callback = null, $mode, $arg0 = null) {
236
-		return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) {
236
+		return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) {
237 237
 			$statement->setFetchMode($mode, $arg0);
238 238
 			$data = $statement->fetchAll();
239
-			if($this->preserveTypes) {
239
+			if ($this->preserveTypes) {
240 240
 				$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
241
-				foreach($data as &$row) {
241
+				foreach ($data as &$row) {
242 242
 					$row = FieldValueConverter::convertValues($row, $columnDefinitions);
243 243
 				}
244 244
 			}
245
-			if($callback !== null) {
246
-				return call_user_func(function ($resultData = []) use ($data, $callback) {
247
-					foreach($data as $row) {
245
+			if ($callback !== null) {
246
+				return call_user_func(function($resultData = []) use ($data, $callback) {
247
+					foreach ($data as $row) {
248 248
 						$result = $callback($row);
249
-						if($result !== null && !($result instanceof DBIgnoreRow)) {
249
+						if ($result !== null && !($result instanceof DBIgnoreRow)) {
250 250
 							$resultData[] = $result;
251 251
 						} else {
252 252
 							$resultData[] = $row;
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @return Generator|YieldPolyfillIterator|mixed[]
267 267
 	 */
268 268
 	private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) {
269
-		if(version_compare(PHP_VERSION, '5.5', '<')) {
270
-			return new YieldPolyfillIterator($callback, $this->preserveTypes, function () use ($mode, $arg0) {
269
+		if (version_compare(PHP_VERSION, '5.5', '<')) {
270
+			return new YieldPolyfillIterator($callback, $this->preserveTypes, function() use ($mode, $arg0) {
271 271
 				$statement = $this->createStatement();
272 272
 				$statement->setFetchMode($mode, $arg0);
273 273
 				return $statement;
@@ -288,20 +288,20 @@  discard block
 block discarded – undo
288 288
 	 * @throws \Exception
289 289
 	 */
290 290
 	private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) {
291
-		return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
291
+		return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) {
292 292
 			$statement->setFetchMode($mode, $arg0);
293 293
 			$row = $statement->fetch();
294 294
 			$result = $resultValidator($row);
295
-			if(!$result['valid']) {
295
+			if (!$result['valid']) {
296 296
 				return $result['default'];
297 297
 			}
298
-			if($this->preserveTypes) {
298
+			if ($this->preserveTypes) {
299 299
 				$columnDefinitions = FieldTypeProvider::getFieldTypes($statement);
300 300
 				$row = FieldValueConverter::convertValues($row, $columnDefinitions);
301 301
 			}
302
-			if($callback !== null) {
302
+			if ($callback !== null) {
303 303
 				$result = $callback($row);
304
-				if($result !== null) {
304
+				if ($result !== null) {
305 305
 					$row = $result;
306 306
 				}
307 307
 			}
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
@@ -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.