@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param PDO $pdo |
| 36 | 36 | */ |
| 37 | 37 | public function __construct(PDO $pdo) { |
| 38 | - if($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 38 | + if ($pdo->getAttribute(PDO::ATTR_ERRMODE) === PDO::ERRMODE_SILENT) { |
|
| 39 | 39 | $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 40 | 40 | } |
| 41 | 41 | $this->pdo = $pdo; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return QueryStatement |
| 65 | 65 | */ |
| 66 | 66 | public function query($query) { |
| 67 | - return $this->buildQueryStatement($query, function ($query) { |
|
| 67 | + return $this->buildQueryStatement($query, function($query) { |
|
| 68 | 68 | $stmt = $this->pdo->query($query); |
| 69 | 69 | return $stmt; |
| 70 | 70 | }); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | * @return QueryStatement |
| 77 | 77 | */ |
| 78 | 78 | public function prepare($query) { |
| 79 | - return $this->buildQueryStatement((string) $query, function ($query) { |
|
| 79 | + return $this->buildQueryStatement((string) $query, function($query) { |
|
| 80 | 80 | $stmt = $this->pdo->prepare($query); |
| 81 | 81 | return $stmt; |
| 82 | 82 | }); |
@@ -88,11 +88,11 @@ discard block |
||
| 88 | 88 | * @return int |
| 89 | 89 | */ |
| 90 | 90 | public function exec($query, array $params = array()) { |
| 91 | - return $this->exceptionHandler(function () use ($query, $params) { |
|
| 91 | + return $this->exceptionHandler(function() use ($query, $params) { |
|
| 92 | 92 | $stmt = $this->pdo->prepare($query); |
| 93 | 93 | $timer = microtime(true); |
| 94 | 94 | $stmt->execute($params); |
| 95 | - $this->queryLoggers->log($query, microtime(true) - $timer); |
|
| 95 | + $this->queryLoggers->log($query, microtime(true)-$timer); |
|
| 96 | 96 | $result = $stmt->rowCount(); |
| 97 | 97 | $stmt->closeCursor(); |
| 98 | 98 | return $result; |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function getTableFields($table) { |
| 114 | 114 | $table = $this->select()->aliasReplacer()->replace($table); |
| 115 | - if(array_key_exists($table, self::$tableFields)) { |
|
| 115 | + if (array_key_exists($table, self::$tableFields)) { |
|
| 116 | 116 | return self::$tableFields[$table]; |
| 117 | 117 | } |
| 118 | 118 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 119 | 119 | $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 120 | - self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows); |
|
| 120 | + self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows); |
|
| 121 | 121 | $stmt->closeCursor(); |
| 122 | 122 | return self::$tableFields[$table]; |
| 123 | 123 | } |
@@ -128,11 +128,11 @@ discard block |
||
| 128 | 128 | * @return string |
| 129 | 129 | */ |
| 130 | 130 | public function quoteExpression($expression, array $arguments = array()) { |
| 131 | - $func = function () use ($arguments) { |
|
| 131 | + $func = function() use ($arguments) { |
|
| 132 | 132 | static $idx = -1; |
| 133 | 133 | $idx++; |
| 134 | 134 | $index = $idx; |
| 135 | - if(array_key_exists($index, $arguments)) { |
|
| 135 | + if (array_key_exists($index, $arguments)) { |
|
| 136 | 136 | $argument = $arguments[$index]; |
| 137 | 137 | $value = $this->quote($argument); |
| 138 | 138 | } else { |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | 151 | public function quote($value) { |
| 152 | - if(is_null($value)) { |
|
| 152 | + if (is_null($value)) { |
|
| 153 | 153 | $result = 'NULL'; |
| 154 | - } elseif($value instanceof Builder\DBExpr) { |
|
| 154 | + } elseif ($value instanceof Builder\DBExpr) { |
|
| 155 | 155 | $result = $value->getExpression(); |
| 156 | - } elseif($value instanceof Builder\Select) { |
|
| 156 | + } elseif ($value instanceof Builder\Select) { |
|
| 157 | 157 | $result = sprintf('(%s)', (string) $value); |
| 158 | - } elseif(is_array($value)) { |
|
| 159 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 158 | + } elseif (is_array($value)) { |
|
| 159 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 160 | 160 | } else { |
| 161 | 161 | $result = $this->pdo->quote($value); |
| 162 | 162 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | if (is_numeric($field) || !is_string($field)) { |
| 172 | 172 | throw new UnexpectedValueException('Field name is invalid'); |
| 173 | 173 | } |
| 174 | - if(strpos($field, '`') !== false) { |
|
| 174 | + if (strpos($field, '`') !== false) { |
|
| 175 | 175 | return (string) $field; |
| 176 | 176 | } |
| 177 | 177 | $parts = explode('.', $field); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function select(array $fields = null) { |
| 186 | 186 | $select = new RunnableSelect($this); |
| 187 | - if($fields !== null) { |
|
| 187 | + if ($fields !== null) { |
|
| 188 | 188 | $select->fields($fields); |
| 189 | 189 | } |
| 190 | 190 | return $select; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function insert(array $fields = null) { |
| 198 | 198 | $insert = new Builder\RunnableInsert($this); |
| 199 | - if($fields !== null) { |
|
| 199 | + if ($fields !== null) { |
|
| 200 | 200 | $insert->addAll($fields); |
| 201 | 201 | } |
| 202 | 202 | return $insert; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | public function update(array $fields = null) { |
| 210 | 210 | $update = new Builder\RunnableUpdate($this); |
| 211 | - if($fields !== null) { |
|
| 211 | + if ($fields !== null) { |
|
| 212 | 212 | $update->setAll($fields); |
| 213 | 213 | } |
| 214 | 214 | return $update; |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | * @return $this |
| 226 | 226 | */ |
| 227 | 227 | public function transactionStart() { |
| 228 | - if((int) $this->transactionLevel === 0) { |
|
| 229 | - if($this->pdo->inTransaction()) { |
|
| 228 | + if ((int) $this->transactionLevel === 0) { |
|
| 229 | + if ($this->pdo->inTransaction()) { |
|
| 230 | 230 | $this->outerTransaction = true; |
| 231 | 231 | } else { |
| 232 | 232 | $this->pdo->beginTransaction(); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @throws \Exception |
| 242 | 242 | */ |
| 243 | 243 | public function transactionCommit() { |
| 244 | - return $this->transactionEnd(function () { |
|
| 244 | + return $this->transactionEnd(function() { |
|
| 245 | 245 | $this->pdo->commit(); |
| 246 | 246 | }); |
| 247 | 247 | } |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @throws \Exception |
| 252 | 252 | */ |
| 253 | 253 | public function transactionRollback() { |
| 254 | - return $this->transactionEnd(function () { |
|
| 254 | + return $this->transactionEnd(function() { |
|
| 255 | 255 | $this->pdo->rollBack(); |
| 256 | 256 | }); |
| 257 | 257 | } |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | * @throws null |
| 265 | 265 | */ |
| 266 | 266 | public function transaction($tries = 1, $callback = null) { |
| 267 | - if(is_callable($tries)) { |
|
| 267 | + if (is_callable($tries)) { |
|
| 268 | 268 | $callback = $tries; |
| 269 | 269 | $tries = 1; |
| 270 | - } elseif(!is_callable($callback)) { |
|
| 270 | + } elseif (!is_callable($callback)) { |
|
| 271 | 271 | throw new \Exception('$callback must be a callable'); |
| 272 | 272 | } |
| 273 | 273 | $e = null; |
| 274 | - for(; $tries--;) { |
|
| 274 | + for (; $tries--;) { |
|
| 275 | 275 | try { |
| 276 | 276 | $this->transactionStart(); |
| 277 | 277 | $result = call_user_func($callback, $this); |
@@ -291,11 +291,11 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | private function transactionEnd($fn) { |
| 293 | 293 | $this->transactionLevel--; |
| 294 | - if($this->transactionLevel < 0) { |
|
| 294 | + if ($this->transactionLevel < 0) { |
|
| 295 | 295 | throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 296 | 296 | } |
| 297 | - if((int) $this->transactionLevel === 0) { |
|
| 298 | - if($this->outerTransaction) { |
|
| 297 | + if ((int) $this->transactionLevel === 0) { |
|
| 298 | + if ($this->outerTransaction) { |
|
| 299 | 299 | $this->outerTransaction = false; |
| 300 | 300 | } else { |
| 301 | 301 | call_user_func($fn); |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | */ |
| 313 | 313 | private function buildQueryStatement($query, $fn) { |
| 314 | 314 | $stmt = call_user_func($fn, $query); |
| 315 | - if(!$stmt) { |
|
| 315 | + if (!$stmt) { |
|
| 316 | 316 | throw new Exception("Could not execute statement:\n{$query}"); |
| 317 | 317 | } |
| 318 | 318 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |