@@ -261,7 +261,7 @@ |
||
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | - * @param int|callable $tries |
|
| 264 | + * @param integer $tries |
|
| 265 | 265 | * @param callable|null $callback |
| 266 | 266 | * @return mixed |
| 267 | 267 | * @throws \Exception |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * @param array $options |
| 39 | 39 | */ |
| 40 | 40 | public function __construct(PDO $pdo, array $options = []) { |
| 41 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 41 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 42 | 42 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 43 | 43 | } |
| 44 | 44 | $this->pdo = $pdo; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @return QueryStatement |
| 75 | 75 | */ |
| 76 | 76 | public function query($query) { |
| 77 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 77 | + return $this->buildQueryStatement($query, function($query) { |
|
| 78 | 78 | $stmt = $this->pdo->query($query); |
| 79 | 79 | return $stmt; |
| 80 | 80 | }); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return QueryStatement |
| 87 | 87 | */ |
| 88 | 88 | public function prepare($query) { |
| 89 | - return $this->buildQueryStatement((string) $query, function ($query) { |
|
| 89 | + return $this->buildQueryStatement((string) $query, function($query) { |
|
| 90 | 90 | $stmt = $this->pdo->prepare($query); |
| 91 | 91 | return $stmt; |
| 92 | 92 | }); |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | * @return int |
| 99 | 99 | */ |
| 100 | 100 | public function exec($query, array $params = array()) { |
| 101 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
| 101 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
| 102 | 102 | $stmt = $this->pdo->prepare($query); |
| 103 | 103 | $timer = microtime(true); |
| 104 | 104 | $stmt->execute($params); |
| 105 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 105 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 106 | 106 | $result = $stmt->rowCount(); |
| 107 | 107 | $stmt->closeCursor(); |
| 108 | 108 | return $result; |
@@ -122,12 +122,12 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function getTableFields($table) { |
| 124 | 124 | $table = $this->select()->aliasReplacer()->replace($table); |
| 125 | - if(array_key_exists($table, self::$tableFields)) { |
|
| 125 | + if (array_key_exists($table, self::$tableFields)) { |
|
| 126 | 126 | return self::$tableFields[$table]; |
| 127 | 127 | } |
| 128 | 128 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 129 | 129 | $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 130 | - self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows); |
|
| 130 | + self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows); |
|
| 131 | 131 | $stmt->closeCursor(); |
| 132 | 132 | return self::$tableFields[$table]; |
| 133 | 133 | } |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | * @return string |
| 139 | 139 | */ |
| 140 | 140 | public function quoteExpression($expression, array $arguments = array()) { |
| 141 | - $func = function () use ($arguments) { |
|
| 141 | + $func = function() use ($arguments) { |
|
| 142 | 142 | static $idx = -1; |
| 143 | 143 | $idx++; |
| 144 | 144 | $index = $idx; |
| 145 | - if(array_key_exists($index, $arguments)) { |
|
| 145 | + if (array_key_exists($index, $arguments)) { |
|
| 146 | 146 | $argument = $arguments[$index]; |
| 147 | 147 | $value = $this->quote($argument); |
| 148 | 148 | } else { |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | 161 | public function quote($value) { |
| 162 | - if(is_null($value)) { |
|
| 162 | + if (is_null($value)) { |
|
| 163 | 163 | $result = 'NULL'; |
| 164 | - } elseif($value instanceof Builder\DBExpr) { |
|
| 164 | + } elseif ($value instanceof Builder\DBExpr) { |
|
| 165 | 165 | $result = $value->getExpression(); |
| 166 | - } elseif($value instanceof Builder\Select) { |
|
| 166 | + } elseif ($value instanceof Builder\Select) { |
|
| 167 | 167 | $result = sprintf('(%s)', (string) $value); |
| 168 | - } elseif(is_array($value)) { |
|
| 169 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 168 | + } elseif (is_array($value)) { |
|
| 169 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 170 | 170 | } else { |
| 171 | 171 | $result = $this->pdo->quote($value); |
| 172 | 172 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | if (is_numeric($field) || !is_string($field)) { |
| 182 | 182 | throw new UnexpectedValueException('Field name is invalid'); |
| 183 | 183 | } |
| 184 | - if(strpos($field, '`') !== false) { |
|
| 184 | + if (strpos($field, '`') !== false) { |
|
| 185 | 185 | return (string) $field; |
| 186 | 186 | } |
| 187 | 187 | $parts = explode('.', $field); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $select = array_key_exists('select-factory', $this->options) |
| 197 | 197 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
| 198 | 198 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
| 199 | - if($fields !== null) { |
|
| 199 | + if ($fields !== null) { |
|
| 200 | 200 | $select->fields($fields); |
| 201 | 201 | } |
| 202 | 202 | return $select; |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $insert = array_key_exists('insert-factory', $this->options) |
| 211 | 211 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
| 212 | 212 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
| 213 | - if($fields !== null) { |
|
| 213 | + if ($fields !== null) { |
|
| 214 | 214 | $insert->addAll($fields); |
| 215 | 215 | } |
| 216 | 216 | return $insert; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $update = array_key_exists('update-factory', $this->options) |
| 225 | 225 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
| 226 | 226 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
| 227 | - if($fields !== null) { |
|
| 227 | + if ($fields !== null) { |
|
| 228 | 228 | $update->setAll($fields); |
| 229 | 229 | } |
| 230 | 230 | return $update; |
@@ -243,8 +243,8 @@ discard block |
||
| 243 | 243 | * @return $this |
| 244 | 244 | */ |
| 245 | 245 | public function transactionStart() { |
| 246 | - if((int) $this->transactionLevel === 0) { |
|
| 247 | - if($this->pdo->inTransaction()) { |
|
| 246 | + if ((int) $this->transactionLevel === 0) { |
|
| 247 | + if ($this->pdo->inTransaction()) { |
|
| 248 | 248 | $this->outerTransaction = true; |
| 249 | 249 | } else { |
| 250 | 250 | $this->pdo->beginTransaction(); |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @throws \Exception |
| 260 | 260 | */ |
| 261 | 261 | public function transactionCommit() { |
| 262 | - return $this->transactionEnd(function () { |
|
| 262 | + return $this->transactionEnd(function() { |
|
| 263 | 263 | $this->pdo->commit(); |
| 264 | 264 | }); |
| 265 | 265 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @throws \Exception |
| 270 | 270 | */ |
| 271 | 271 | public function transactionRollback() { |
| 272 | - return $this->transactionEnd(function () { |
|
| 272 | + return $this->transactionEnd(function() { |
|
| 273 | 273 | $this->pdo->rollBack(); |
| 274 | 274 | }); |
| 275 | 275 | } |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | public function dryRun($callback = null) { |
| 285 | 285 | $result = null; |
| 286 | 286 | $exception = null; |
| 287 | - if(!$this->pdo->inTransaction()) { |
|
| 287 | + if (!$this->pdo->inTransaction()) { |
|
| 288 | 288 | $this->transactionStart(); |
| 289 | 289 | try { |
| 290 | 290 | $result = call_user_func($callback, $this); |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | * @throws \Error |
| 322 | 322 | */ |
| 323 | 323 | public function transaction($tries = 1, $callback = null) { |
| 324 | - if(is_callable($tries)) { |
|
| 324 | + if (is_callable($tries)) { |
|
| 325 | 325 | $callback = $tries; |
| 326 | 326 | $tries = 1; |
| 327 | - } elseif(!is_callable($callback)) { |
|
| 327 | + } elseif (!is_callable($callback)) { |
|
| 328 | 328 | throw new RuntimeException('$callback must be a callable'); |
| 329 | 329 | } |
| 330 | 330 | $result = null; |
| 331 | 331 | $exception = null; |
| 332 | - for(; $tries--;) { |
|
| 333 | - if(!$this->pdo->inTransaction()) { |
|
| 332 | + for (; $tries--;) { |
|
| 333 | + if (!$this->pdo->inTransaction()) { |
|
| 334 | 334 | $this->transactionStart(); |
| 335 | 335 | try { |
| 336 | 336 | $result = call_user_func($callback, $this); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | - if($exception !== null) { |
|
| 362 | + if ($exception !== null) { |
|
| 363 | 363 | throw $exception; |
| 364 | 364 | } |
| 365 | 365 | return $result; |
@@ -372,11 +372,11 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | private function transactionEnd($fn) { |
| 374 | 374 | $this->transactionLevel--; |
| 375 | - if($this->transactionLevel < 0) { |
|
| 375 | + if ($this->transactionLevel < 0) { |
|
| 376 | 376 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 377 | 377 | } |
| 378 | - if((int) $this->transactionLevel === 0) { |
|
| 379 | - if($this->outerTransaction) { |
|
| 378 | + if ((int) $this->transactionLevel === 0) { |
|
| 379 | + if ($this->outerTransaction) { |
|
| 380 | 380 | $this->outerTransaction = false; |
| 381 | 381 | } else { |
| 382 | 382 | call_user_func($fn); |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | private function buildQueryStatement($query, $fn) { |
| 395 | 395 | $stmt = call_user_func($fn, $query); |
| 396 | - if(!$stmt) { |
|
| 396 | + if (!$stmt) { |
|
| 397 | 397 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
| 398 | 398 | } |
| 399 | 399 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -88,7 +88,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -16,8 +16,8 @@ |
||
| 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 { |
@@ -16,8 +16,8 @@ |
||
| 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 { |