Completed
Push — master ( eae540...f081e5 )
by Ron
02:06
created
src/Builder/Insert.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 * @return $this
89 89
 	 */
90 90
 	public function addExpr($str, $_ = null) {
91
-		if(count(func_get_args()) > 1) {
91
+		if (count(func_get_args()) > 1) {
92 92
 			$this->fields[] = func_get_args();
93 93
 		} else {
94 94
 			$this->fields[] = $str;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @return $this
103 103
 	 */
104 104
 	public function updateExpr($str, $_ = null) {
105
-		if(count(func_get_args()) > 1) {
105
+		if (count(func_get_args()) > 1) {
106 106
 			$this->update[] = func_get_args();
107 107
 		} else {
108 108
 			$this->update[] = $str;
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @return $this
116 116
 	 */
117 117
 	public function addOrUpdateExpr($str) {
118
-		if(count(func_get_args()) > 1) {
118
+		if (count(func_get_args()) > 1) {
119 119
 			$this->fields[] = func_get_args();
120 120
 			$this->update[] = func_get_args();
121 121
 		} else {
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @return $this
133 133
 	 */
134 134
 	public function addAll(array $data, array $mask = null, array $excludeFields = null) {
135
-		$this->addAllTo($data, $mask, $excludeFields, function ($field, $value) {
135
+		$this->addAllTo($data, $mask, $excludeFields, function($field, $value) {
136 136
 			$this->add($field, $value);
137 137
 		});
138 138
 		return $this;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 * @return $this
146 146
 	 */
147 147
 	public function updateAll(array $data, array $mask = null, array $excludeFields = null) {
148
-		$this->addAllTo($data, $mask, $excludeFields, function ($field, $value) {
148
+		$this->addAllTo($data, $mask, $excludeFields, function($field, $value) {
149 149
 			if ($field !== $this->keyField) {
150 150
 				$this->update($field, $value);
151 151
 			}
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 		$ignoreStr = $this->ignore ? ' IGNORE' : '';
190 190
 		$queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n";
191 191
 
192
-		if($this->from !== null) {
192
+		if ($this->from !== null) {
193 193
 			$fields = $this->from->getFields();
194 194
 			$queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields)));
195 195
 			$queryArr[] = $this->from;
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		}
204 204
 
205 205
 		$updateData = $this->buildUpdate();
206
-		if($updateData) {
206
+		if ($updateData) {
207 207
 			$queryArr[] = "{$updateData}\n";
208 208
 		}
209 209
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 	 * @return $this
237 237
 	 */
238 238
 	private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) {
239
-		if($mask !== null) {
239
+		if ($mask !== null) {
240 240
 			$data = array_intersect_key($data, array_combine($mask, $mask));
241 241
 		}
242
-		if($excludeFields !== null) {
243
-			foreach($excludeFields as $excludeField) {
244
-				if(array_key_exists($excludeField, $data)) {
242
+		if ($excludeFields !== null) {
243
+			foreach ($excludeFields as $excludeField) {
244
+				if (array_key_exists($excludeField, $data)) {
245 245
 					unset($data[$excludeField]);
246 246
 				}
247 247
 			}
@@ -258,10 +258,10 @@  discard block
 block discarded – undo
258 258
 	 */
259 259
 	private function buildUpdate() {
260 260
 		$queryArr = array();
261
-		if(!empty($this->update)) {
261
+		if (!empty($this->update)) {
262 262
 			$queryArr[] = "ON DUPLICATE KEY UPDATE\n";
263 263
 			$updateArr = array();
264
-			if($this->keyField !== null) {
264
+			if ($this->keyField !== null) {
265 265
 				$updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})";
266 266
 			}
267 267
 			$updateArr = $this->buildFieldList($this->update, $updateArr);
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 	 * @throws Exception
286 286
 	 */
287 287
 	private function clearValues(array $values) {
288
-		if(!count($values)) {
288
+		if (!count($values)) {
289 289
 			return [];
290 290
 		}
291 291
 
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 		$result = array();
295 295
 
296 296
 		foreach ($values as $fieldName => $fieldValue) {
297
-			if(in_array($fieldName, $fields)) {
297
+			if (in_array($fieldName, $fields)) {
298 298
 				$result[$fieldName] = $fieldValue;
299 299
 			}
300 300
 		}
Please login to merge, or discard this patch.
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, $_ = null) {
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/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, $_ = null) {
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/Traits/TableNameBuilder.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,32 +12,32 @@
 block discarded – undo
12 12
 	 * @return string
13 13
 	 */
14 14
 	protected function buildTableName($alias, $name) {
15
-		if(is_object($name)) {
15
+		if (is_object($name)) {
16 16
 			$name = (string) $name;
17 17
 			$lines = explode("\n", $name);
18
-			foreach($lines as &$line) {
18
+			foreach ($lines as &$line) {
19 19
 				$line = "\t{$line}";
20 20
 			}
21 21
 			$name = join("\n", $lines);
22
-			$name = '(' . trim(rtrim(trim($name), ';')) . ')';
22
+			$name = '('.trim(rtrim(trim($name), ';')).')';
23 23
 		}
24
-		if(is_array($name)) {
24
+		if (is_array($name)) {
25 25
 			$parts = [];
26
-			foreach($name as $bucket) {
26
+			foreach ($name as $bucket) {
27 27
 				$values = [];
28
-				foreach($bucket as $field => $value) {
28
+				foreach ($bucket as $field => $value) {
29 29
 					$values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field));
30 30
 				}
31 31
 				$parts[] = sprintf("SELECT %s", join(', ', $values));
32 32
 			}
33
-			$name = '(' . join("\n\tUNION\n\t", $parts) . ')';
33
+			$name = '('.join("\n\tUNION\n\t", $parts).')';
34 34
 		}
35
-		if($this->db()->getVirtualTables()->has($name)) {
36
-			$select = (string )$this->db()->getVirtualTables()->get($name);
35
+		if ($this->db()->getVirtualTables()->has($name)) {
36
+			$select = (string) $this->db()->getVirtualTables()->get($name);
37 37
 			$name = sprintf('(%s)', join("\n\t", explode("\n", trim($select))));
38 38
 		}
39 39
 		$name = $this->aliasReplacer()->replace($name);
40
-		if($alias !== null) {
40
+		if ($alias !== null) {
41 41
 			return sprintf("%s %s", $name, $alias);
42 42
 		}
43 43
 		return $name;
Please login to merge, or discard this patch.
src/Tools/VirtualTables.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 	 * @return Select|null
31 31
 	 */
32 32
 	public function get($tableName) {
33
-		if($this->has($tableName)) {
33
+		if ($this->has($tableName)) {
34 34
 			return $this->virtualTables[$tableName];
35 35
 		}
36 36
 		return null;
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
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	 * @param array $options
42 42
 	 */
43 43
 	public function __construct(PDO $pdo, array $options = []) {
44
-		if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
44
+		if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) {
45 45
 			$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
46 46
 		}
47 47
 		$this->pdo = $pdo;
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 * @return VirtualTables
76 76
 	 */
77 77
 	public function getVirtualTables() {
78
-		if($this->virtualTables === null) {
78
+		if ($this->virtualTables === null) {
79 79
 			$this->virtualTables = new VirtualTables();
80 80
 		}
81 81
 		return $this->virtualTables;
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @return QueryStatement
88 88
 	 */
89 89
 	public function query($query) {
90
-		return $this->buildQueryStatement($query, function ($query) {
90
+		return $this->buildQueryStatement($query, function($query) {
91 91
 			$stmt = $this->pdo->query($query);
92 92
 			return $stmt;
93 93
 		});
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 * @return QueryStatement
100 100
 	 */
101 101
 	public function prepare($query) {
102
-		return $this->buildQueryStatement((string) $query, function ($query) {
102
+		return $this->buildQueryStatement((string) $query, function($query) {
103 103
 			$stmt = $this->pdo->prepare($query);
104 104
 			return $stmt;
105 105
 		});
@@ -111,11 +111,11 @@  discard block
 block discarded – undo
111 111
 	 * @return int
112 112
 	 */
113 113
 	public function exec($query, array $params = array()) {
114
-		return $this->exceptionHandler(function () use ($query, $params) {
114
+		return $this->exceptionHandler(function() use ($query, $params) {
115 115
 			$stmt = $this->pdo->prepare($query);
116 116
 			$timer = microtime(true);
117 117
 			$stmt->execute($params);
118
-			$this->queryLoggers->log($query, microtime(true) - $timer);
118
+			$this->queryLoggers->log($query, microtime(true)-$timer);
119 119
 			$result = $stmt->rowCount();
120 120
 			$stmt->closeCursor();
121 121
 			return $result;
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 	 */
136 136
 	public function getTableFields($table) {
137 137
 		$table = $this->select()->aliasReplacer()->replace($table);
138
-		if(array_key_exists($table, self::$tableFields)) {
138
+		if (array_key_exists($table, self::$tableFields)) {
139 139
 			return self::$tableFields[$table];
140 140
 		}
141 141
 		$stmt = $this->pdo->query("DESCRIBE {$table}");
142 142
 		$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
143
-		self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows);
143
+		self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows);
144 144
 		$stmt->closeCursor();
145 145
 		return self::$tableFields[$table];
146 146
 	}
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 	 * @return string
152 152
 	 */
153 153
 	public function quoteExpression($expression, array $arguments = array()) {
154
-		$func = function () use ($arguments) {
154
+		$func = function() use ($arguments) {
155 155
 			static $idx = -1;
156 156
 			$idx++;
157 157
 			$index = $idx;
158
-			if(array_key_exists($index, $arguments)) {
158
+			if (array_key_exists($index, $arguments)) {
159 159
 				$argument = $arguments[$index];
160 160
 				$value = $this->quote($argument);
161 161
 			} else {
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 	 * @return string
173 173
 	 */
174 174
 	public function quote($value) {
175
-		if(is_null($value)) {
175
+		if (is_null($value)) {
176 176
 			$result = 'NULL';
177
-		} elseif($value instanceof Builder\DBExpr) {
177
+		} elseif ($value instanceof Builder\DBExpr) {
178 178
 			$result = $value->getExpression();
179
-		} elseif($value instanceof Builder\Select) {
179
+		} elseif ($value instanceof Builder\Select) {
180 180
 			$result = sprintf('(%s)', (string) $value);
181
-		} elseif(is_array($value)) {
182
-			$result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value));
181
+		} elseif (is_array($value)) {
182
+			$result = join(', ', array_map(function($value) { return $this->quote($value); }, $value));
183 183
 		} else {
184 184
 			$result = $this->pdo->quote($value);
185 185
 		}
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 		if (is_numeric($field) || !is_string($field)) {
195 195
 			throw new UnexpectedValueException('Field name is invalid');
196 196
 		}
197
-		if(strpos($field, '`') !== false) {
197
+		if (strpos($field, '`') !== false) {
198 198
 			return (string) $field;
199 199
 		}
200 200
 		$parts = explode('.', $field);
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		$select = array_key_exists('select-factory', $this->options)
210 210
 			? call_user_func($this->options['select-factory'], $this, $this->options['select-options'])
211 211
 			: new Builder\RunnableSelect($this, $this->options['select-options']);
212
-		if($fields !== null) {
212
+		if ($fields !== null) {
213 213
 			$select->fields($fields);
214 214
 		}
215 215
 		return $select;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 		$insert = array_key_exists('insert-factory', $this->options)
224 224
 			? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options'])
225 225
 			: new Builder\RunnableInsert($this, $this->options['insert-options']);
226
-		if($fields !== null) {
226
+		if ($fields !== null) {
227 227
 			$insert->addAll($fields);
228 228
 		}
229 229
 		return $insert;
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
 		$update = array_key_exists('update-factory', $this->options)
238 238
 			? call_user_func($this->options['update-factory'], $this, $this->options['update-options'])
239 239
 			: new Builder\RunnableUpdate($this, $this->options['update-options']);
240
-		if($fields !== null) {
240
+		if ($fields !== null) {
241 241
 			$update->setAll($fields);
242 242
 		}
243 243
 		return $update;
@@ -256,8 +256,8 @@  discard block
 block discarded – undo
256 256
 	 * @return $this
257 257
 	 */
258 258
 	public function transactionStart() {
259
-		if((int) $this->transactionLevel === 0) {
260
-			if($this->pdo->inTransaction()) {
259
+		if ((int) $this->transactionLevel === 0) {
260
+			if ($this->pdo->inTransaction()) {
261 261
 				$this->outerTransaction = true;
262 262
 			} else {
263 263
 				$this->pdo->beginTransaction();
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @throws \Exception
273 273
 	 */
274 274
 	public function transactionCommit() {
275
-		return $this->transactionEnd(function () {
275
+		return $this->transactionEnd(function() {
276 276
 			$this->pdo->commit();
277 277
 		});
278 278
 	}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @throws \Exception
283 283
 	 */
284 284
 	public function transactionRollback() {
285
-		return $this->transactionEnd(function () {
285
+		return $this->transactionEnd(function() {
286 286
 			$this->pdo->rollBack();
287 287
 		});
288 288
 	}
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 	 */
296 296
 	public function dryRun($callback = null) {
297 297
 		$result = null;
298
-		if(!$this->pdo->inTransaction()) {
298
+		if (!$this->pdo->inTransaction()) {
299 299
 			$this->transactionStart();
300 300
 			try {
301 301
 				$result = call_user_func($callback, $this);
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 	 * @throws \Error
333 333
 	 */
334 334
 	public function transaction($tries = 1, $callback = null) {
335
-		if(is_callable($tries)) {
335
+		if (is_callable($tries)) {
336 336
 			$callback = $tries;
337 337
 			$tries = 1;
338
-		} elseif(!is_callable($callback)) {
338
+		} elseif (!is_callable($callback)) {
339 339
 			throw new RuntimeException('$callback must be a callable');
340 340
 		}
341 341
 		$result = null;
342 342
 		$exception = null;
343
-		for(; $tries--;) {
344
-			if(!$this->pdo->inTransaction()) {
343
+		for (; $tries--;) {
344
+			if (!$this->pdo->inTransaction()) {
345 345
 				$this->transactionStart();
346 346
 				try {
347 347
 					$result = call_user_func($callback, $this);
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 				}
371 371
 			}
372 372
 		}
373
-		if($exception !== null) {
373
+		if ($exception !== null) {
374 374
 			throw $exception;
375 375
 		}
376 376
 		return $result;
@@ -383,11 +383,11 @@  discard block
 block discarded – undo
383 383
 	 */
384 384
 	private function transactionEnd($fn) {
385 385
 		$this->transactionLevel--;
386
-		if($this->transactionLevel < 0) {
386
+		if ($this->transactionLevel < 0) {
387 387
 			throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction");
388 388
 		}
389
-		if((int) $this->transactionLevel === 0) {
390
-			if($this->outerTransaction) {
389
+		if ((int) $this->transactionLevel === 0) {
390
+			if ($this->outerTransaction) {
391 391
 				$this->outerTransaction = false;
392 392
 			} else {
393 393
 				call_user_func($fn);
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 	 */
405 405
 	private function buildQueryStatement($query, $fn) {
406 406
 		$stmt = call_user_func($fn, $query);
407
-		if(!$stmt) {
407
+		if (!$stmt) {
408 408
 			throw new RuntimeException("Could not execute statement:\n{$query}");
409 409
 		}
410 410
 		$stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers);
Please login to merge, or discard this patch.