@@ -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 | }); |
@@ -92,7 +92,7 @@ discard block |
||
| 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; |
@@ -115,12 +115,12 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function getTableFields($table) { |
| 117 | 117 | $table = $this->select()->aliasReplacer()->replace($table); |
| 118 | - if(array_key_exists($table, self::$tableFields)) { |
|
| 118 | + if (array_key_exists($table, self::$tableFields)) { |
|
| 119 | 119 | return self::$tableFields[$table]; |
| 120 | 120 | } |
| 121 | 121 | $stmt = $this->pdo->query("DESCRIBE {$table}"); |
| 122 | 122 | $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 123 | - self::$tableFields[$table] = array_map(function ($row) { return $row['Field']; }, $rows); |
|
| 123 | + self::$tableFields[$table] = array_map(function($row) { return $row['Field']; }, $rows); |
|
| 124 | 124 | $stmt->closeCursor(); |
| 125 | 125 | return self::$tableFields[$table]; |
| 126 | 126 | } |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | * @return string |
| 132 | 132 | */ |
| 133 | 133 | public function quoteExpression($expression, array $arguments = array()) { |
| 134 | - $func = function () use ($arguments) { |
|
| 134 | + $func = function() use ($arguments) { |
|
| 135 | 135 | static $idx = -1; |
| 136 | 136 | $idx++; |
| 137 | 137 | $index = $idx; |
| 138 | - if(array_key_exists($index, $arguments)) { |
|
| 138 | + if (array_key_exists($index, $arguments)) { |
|
| 139 | 139 | $argument = $arguments[$index]; |
| 140 | 140 | $value = $this->quote($argument); |
| 141 | 141 | } else { |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | * @return string |
| 153 | 153 | */ |
| 154 | 154 | public function quote($value) { |
| 155 | - if(is_null($value)) { |
|
| 155 | + if (is_null($value)) { |
|
| 156 | 156 | $result = 'NULL'; |
| 157 | - } elseif($value instanceof Builder\Select) { |
|
| 157 | + } elseif ($value instanceof Builder\Select) { |
|
| 158 | 158 | $result = sprintf('(%s)', (string) $value); |
| 159 | - } elseif(is_array($value)) { |
|
| 160 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
| 159 | + } elseif (is_array($value)) { |
|
| 160 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
| 161 | 161 | /*} elseif(is_int(trim($value)) && strpos('123456789', substr(0, 1, trim($value))) !== null) { |
| 162 | 162 | $result = $value;*/ |
| 163 | 163 | } else { |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | if (is_numeric($field) || !is_string($field)) { |
| 175 | 175 | throw new UnexpectedValueException('Field name is invalid'); |
| 176 | 176 | } |
| 177 | - if(strpos($field, '`') !== false) { |
|
| 177 | + if (strpos($field, '`') !== false) { |
|
| 178 | 178 | return (string) $field; |
| 179 | 179 | } |
| 180 | 180 | $parts = explode('.', $field); |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function select(array $fields = null) { |
| 189 | 189 | $select = new RunnableSelect($this); |
| 190 | - if($fields !== null) { |
|
| 190 | + if ($fields !== null) { |
|
| 191 | 191 | $select->fields($fields); |
| 192 | 192 | } |
| 193 | 193 | return $select; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function insert(array $fields = null) { |
| 201 | 201 | $insert = new Builder\RunnableInsert($this); |
| 202 | - if($fields !== null) { |
|
| 202 | + if ($fields !== null) { |
|
| 203 | 203 | $insert->addAll($fields); |
| 204 | 204 | } |
| 205 | 205 | return $insert; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | public function update(array $fields = null) { |
| 213 | 213 | $update = new Builder\RunnableUpdate($this); |
| 214 | - if($fields !== null) { |
|
| 214 | + if ($fields !== null) { |
|
| 215 | 215 | $update->setAll($fields); |
| 216 | 216 | } |
| 217 | 217 | return $update; |
@@ -228,8 +228,8 @@ discard block |
||
| 228 | 228 | * @return $this |
| 229 | 229 | */ |
| 230 | 230 | public function transactionStart() { |
| 231 | - if((int) $this->transactionLevel === 0) { |
|
| 232 | - if($this->pdo->inTransaction()) { |
|
| 231 | + if ((int) $this->transactionLevel === 0) { |
|
| 232 | + if ($this->pdo->inTransaction()) { |
|
| 233 | 233 | $this->outerTransaction = true; |
| 234 | 234 | } else { |
| 235 | 235 | $this->pdo->beginTransaction(); |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | * @throws \Exception |
| 245 | 245 | */ |
| 246 | 246 | public function transactionCommit() { |
| 247 | - return $this->transactionEnd(function () { |
|
| 247 | + return $this->transactionEnd(function() { |
|
| 248 | 248 | $this->pdo->commit(); |
| 249 | 249 | }); |
| 250 | 250 | } |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | * @throws \Exception |
| 255 | 255 | */ |
| 256 | 256 | public function transactionRollback() { |
| 257 | - return $this->transactionEnd(function () { |
|
| 257 | + return $this->transactionEnd(function() { |
|
| 258 | 258 | $this->pdo->rollBack(); |
| 259 | 259 | }); |
| 260 | 260 | } |
@@ -267,14 +267,14 @@ discard block |
||
| 267 | 267 | * @throws null |
| 268 | 268 | */ |
| 269 | 269 | public function transaction($tries = 1, $callback = null) { |
| 270 | - if(is_callable($tries)) { |
|
| 270 | + if (is_callable($tries)) { |
|
| 271 | 271 | $callback = $tries; |
| 272 | 272 | $tries = 1; |
| 273 | - } elseif(!is_callable($callback)) { |
|
| 273 | + } elseif (!is_callable($callback)) { |
|
| 274 | 274 | throw new \Exception('$callback must be a callable'); |
| 275 | 275 | } |
| 276 | 276 | $e = null; |
| 277 | - for(; $tries--;) { |
|
| 277 | + for (; $tries--;) { |
|
| 278 | 278 | try { |
| 279 | 279 | $this->transactionStart(); |
| 280 | 280 | $result = call_user_func($callback, $this); |
@@ -294,11 +294,11 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | private function transactionEnd($fn) { |
| 296 | 296 | $this->transactionLevel--; |
| 297 | - if($this->transactionLevel < 0) { |
|
| 297 | + if ($this->transactionLevel < 0) { |
|
| 298 | 298 | throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
| 299 | 299 | } |
| 300 | - if((int) $this->transactionLevel === 0) { |
|
| 301 | - if($this->outerTransaction) { |
|
| 300 | + if ((int) $this->transactionLevel === 0) { |
|
| 301 | + if ($this->outerTransaction) { |
|
| 302 | 302 | $this->outerTransaction = false; |
| 303 | 303 | } else { |
| 304 | 304 | call_user_func($fn); |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | private function buildQueryStatement($query, $fn) { |
| 317 | 317 | $stmt = call_user_func($fn, $query); |
| 318 | - if(!$stmt) { |
|
| 318 | + if (!$stmt) { |
|
| 319 | 319 | throw new Exception("Could not execute statement:\n{$query}"); |
| 320 | 320 | } |
| 321 | 321 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |