@@ -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,12 +149,12 @@ 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\Select) { |
|
154 | + } elseif ($value instanceof Builder\Select) { |
|
155 | 155 | $result = sprintf('(%s)', (string) $value); |
156 | - } elseif(is_array($value)) { |
|
157 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
156 | + } elseif (is_array($value)) { |
|
157 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
158 | 158 | } else { |
159 | 159 | $result = $this->pdo->quote($value); |
160 | 160 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | if (is_numeric($field) || !is_string($field)) { |
170 | 170 | throw new UnexpectedValueException('Field name is invalid'); |
171 | 171 | } |
172 | - if(strpos($field, '`') !== false) { |
|
172 | + if (strpos($field, '`') !== false) { |
|
173 | 173 | return (string) $field; |
174 | 174 | } |
175 | 175 | $parts = explode('.', $field); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | public function select(array $fields = null) { |
184 | 184 | $select = new RunnableSelect($this); |
185 | - if($fields !== null) { |
|
185 | + if ($fields !== null) { |
|
186 | 186 | $select->fields($fields); |
187 | 187 | } |
188 | 188 | return $select; |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function insert(array $fields = null) { |
196 | 196 | $insert = new Builder\RunnableInsert($this); |
197 | - if($fields !== null) { |
|
197 | + if ($fields !== null) { |
|
198 | 198 | $insert->addAll($fields); |
199 | 199 | } |
200 | 200 | return $insert; |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function update(array $fields = null) { |
208 | 208 | $update = new Builder\RunnableUpdate($this); |
209 | - if($fields !== null) { |
|
209 | + if ($fields !== null) { |
|
210 | 210 | $update->setAll($fields); |
211 | 211 | } |
212 | 212 | return $update; |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @return $this |
224 | 224 | */ |
225 | 225 | public function transactionStart() { |
226 | - if((int) $this->transactionLevel === 0) { |
|
227 | - if($this->pdo->inTransaction()) { |
|
226 | + if ((int) $this->transactionLevel === 0) { |
|
227 | + if ($this->pdo->inTransaction()) { |
|
228 | 228 | $this->outerTransaction = true; |
229 | 229 | } else { |
230 | 230 | $this->pdo->beginTransaction(); |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * @throws \Exception |
240 | 240 | */ |
241 | 241 | public function transactionCommit() { |
242 | - return $this->transactionEnd(function () { |
|
242 | + return $this->transactionEnd(function() { |
|
243 | 243 | $this->pdo->commit(); |
244 | 244 | }); |
245 | 245 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | * @throws \Exception |
250 | 250 | */ |
251 | 251 | public function transactionRollback() { |
252 | - return $this->transactionEnd(function () { |
|
252 | + return $this->transactionEnd(function() { |
|
253 | 253 | $this->pdo->rollBack(); |
254 | 254 | }); |
255 | 255 | } |
@@ -262,14 +262,14 @@ discard block |
||
262 | 262 | * @throws null |
263 | 263 | */ |
264 | 264 | public function transaction($tries = 1, $callback = null) { |
265 | - if(is_callable($tries)) { |
|
265 | + if (is_callable($tries)) { |
|
266 | 266 | $callback = $tries; |
267 | 267 | $tries = 1; |
268 | - } elseif(!is_callable($callback)) { |
|
268 | + } elseif (!is_callable($callback)) { |
|
269 | 269 | throw new \Exception('$callback must be a callable'); |
270 | 270 | } |
271 | 271 | $e = null; |
272 | - for(; $tries--;) { |
|
272 | + for (; $tries--;) { |
|
273 | 273 | try { |
274 | 274 | $this->transactionStart(); |
275 | 275 | $result = call_user_func($callback, $this); |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | */ |
290 | 290 | private function transactionEnd($fn) { |
291 | 291 | $this->transactionLevel--; |
292 | - if($this->transactionLevel < 0) { |
|
292 | + if ($this->transactionLevel < 0) { |
|
293 | 293 | throw new \Exception("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
294 | 294 | } |
295 | - if((int) $this->transactionLevel === 0) { |
|
296 | - if($this->outerTransaction) { |
|
295 | + if ((int) $this->transactionLevel === 0) { |
|
296 | + if ($this->outerTransaction) { |
|
297 | 297 | $this->outerTransaction = false; |
298 | 298 | } else { |
299 | 299 | call_user_func($fn); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | private function buildQueryStatement($query, $fn) { |
312 | 312 | $stmt = call_user_func($fn, $query); |
313 | - if(!$stmt) { |
|
313 | + if (!$stmt) { |
|
314 | 314 | throw new Exception("Could not execute statement:\n{$query}"); |
315 | 315 | } |
316 | 316 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |