@@ -321,7 +321,7 @@ |
||
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
324 | - * @param int|callable $tries |
|
324 | + * @param integer $tries |
|
325 | 325 | * @param callable|null $callback |
326 | 326 | * @return mixed |
327 | 327 | */ |
@@ -41,7 +41,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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(); |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * @return $this |
272 | 272 | */ |
273 | 273 | public function transactionCommit() { |
274 | - return $this->transactionEnd(function () { |
|
274 | + return $this->transactionEnd(function() { |
|
275 | 275 | $this->pdo->commit(); |
276 | 276 | }); |
277 | 277 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @return $this |
281 | 281 | */ |
282 | 282 | public function transactionRollback() { |
283 | - return $this->transactionEnd(function () { |
|
283 | + return $this->transactionEnd(function() { |
|
284 | 284 | $this->pdo->rollBack(); |
285 | 285 | }); |
286 | 286 | } |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function dryRun($callback = null) { |
293 | 293 | $result = null; |
294 | - if(!$this->pdo->inTransaction()) { |
|
294 | + if (!$this->pdo->inTransaction()) { |
|
295 | 295 | $this->transactionStart(); |
296 | 296 | try { |
297 | 297 | $result = call_user_func($callback, $this); |
@@ -326,16 +326,16 @@ discard block |
||
326 | 326 | * @return mixed |
327 | 327 | */ |
328 | 328 | public function transaction($tries = 1, $callback = null) { |
329 | - if(is_callable($tries)) { |
|
329 | + if (is_callable($tries)) { |
|
330 | 330 | $callback = $tries; |
331 | 331 | $tries = 1; |
332 | - } elseif(!is_callable($callback)) { |
|
332 | + } elseif (!is_callable($callback)) { |
|
333 | 333 | throw new RuntimeException('$callback must be a callable'); |
334 | 334 | } |
335 | 335 | $result = null; |
336 | 336 | $exception = null; |
337 | - for(; $tries--;) { |
|
338 | - if(!$this->pdo->inTransaction()) { |
|
337 | + for (; $tries--;) { |
|
338 | + if (!$this->pdo->inTransaction()) { |
|
339 | 339 | $this->transactionStart(); |
340 | 340 | try { |
341 | 341 | $result = call_user_func($callback, $this); |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | } |
365 | 365 | } |
366 | 366 | } |
367 | - if($exception !== null) { |
|
367 | + if ($exception !== null) { |
|
368 | 368 | throw new RuntimeException($exception->getMessage(), (int) $exception->getCode(), $exception); |
369 | 369 | } |
370 | 370 | return $result; |
@@ -377,11 +377,11 @@ discard block |
||
377 | 377 | */ |
378 | 378 | private function transactionEnd($fn) { |
379 | 379 | $this->transactionLevel--; |
380 | - if($this->transactionLevel < 0) { |
|
380 | + if ($this->transactionLevel < 0) { |
|
381 | 381 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
382 | 382 | } |
383 | - if((int) $this->transactionLevel === 0) { |
|
384 | - if($this->outerTransaction) { |
|
383 | + if ((int) $this->transactionLevel === 0) { |
|
384 | + if ($this->outerTransaction) { |
|
385 | 385 | $this->outerTransaction = false; |
386 | 386 | } else { |
387 | 387 | call_user_func($fn); |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | */ |
399 | 399 | private function buildQueryStatement($query, $fn) { |
400 | 400 | $stmt = call_user_func($fn, $query); |
401 | - if(!$stmt) { |
|
401 | + if (!$stmt) { |
|
402 | 402 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
403 | 403 | } |
404 | 404 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -27,16 +27,16 @@ discard block |
||
27 | 27 | $this->value = $data; |
28 | 28 | $this->keyPath = $this->buildKey($keyPath); |
29 | 29 | $this->value = $this->recursiveGet($data, $this->keyPath, null); |
30 | - if($validator === null) { |
|
31 | - $validator = function ($data) { |
|
32 | - if(is_array($data)) { |
|
30 | + if ($validator === null) { |
|
31 | + $validator = function($data) { |
|
32 | + if (is_array($data)) { |
|
33 | 33 | return $this->isValidArray($data); |
34 | 34 | } |
35 | 35 | return (string) $data !== ''; |
36 | 36 | }; |
37 | 37 | } |
38 | - if($validationResultHandler === null) { |
|
39 | - $validationResultHandler = function () {}; |
|
38 | + if ($validationResultHandler === null) { |
|
39 | + $validationResultHandler = function() {}; |
|
40 | 40 | } |
41 | 41 | $this->validator = $validator; |
42 | 42 | $this->validationResultHandler = $validationResultHandler; |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @return string |
74 | 74 | */ |
75 | 75 | private function buildKey($keyPath) { |
76 | - if(is_string($keyPath)) { |
|
76 | + if (is_string($keyPath)) { |
|
77 | 77 | $keyPath = explode('.', $keyPath); |
78 | 78 | } |
79 | - if(!is_array($keyPath)) { |
|
79 | + if (!is_array($keyPath)) { |
|
80 | 80 | throw new RuntimeException('Invalid key'); |
81 | 81 | } |
82 | 82 | return $keyPath; |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | * @return bool |
88 | 88 | */ |
89 | 89 | private function isValidArray(array $array) { |
90 | - $data = array_filter($array, function ($value) { |
|
91 | - if(is_array($value)) { |
|
90 | + $data = array_filter($array, function($value) { |
|
91 | + if (is_array($value)) { |
|
92 | 92 | return $this->isValidArray($value); |
93 | 93 | } |
94 | 94 | return (string) $value !== ''; |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | if (!$count) { |
108 | 108 | return $default; |
109 | 109 | } |
110 | - for($idx = 0; $idx < $count; $idx++) { |
|
110 | + for ($idx = 0; $idx < $count; $idx++) { |
|
111 | 111 | $part = $path[$idx]; |
112 | - if(!array_key_exists($part, $array)) { |
|
112 | + if (!array_key_exists($part, $array)) { |
|
113 | 113 | return $default; |
114 | 114 | } |
115 | 115 | $array = $array[$part]; |