@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | /** |
236 | 236 | * @param Closure $callback |
237 | 237 | * @param int $mode |
238 | - * @param mixed $arg0 |
|
238 | + * @param string $arg0 |
|
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | 241 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | /** |
269 | 269 | * @param Closure $callback |
270 | 270 | * @param int $mode |
271 | - * @param mixed $arg0 |
|
271 | + * @param string $arg0 |
|
272 | 272 | * @return Traversable|mixed[] |
273 | 273 | */ |
274 | 274 | private function fetchLazy(Closure $callback = null, $mode, $arg0 = null) { |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | /** |
282 | 282 | * @param Closure $callback |
283 | 283 | * @param int $mode |
284 | - * @param mixed $arg0 |
|
284 | + * @param null|string $arg0 |
|
285 | 285 | * @param Closure $resultValidator |
286 | 286 | * @return mixed |
287 | 287 | */ |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @return mixed[] |
92 | 92 | */ |
93 | 93 | public function fetchRow(Closure $callback = null) { |
94 | - return $this->fetch($callback, PDO::FETCH_ASSOC, null, function ($row) { |
|
94 | + return $this->fetch($callback, PDO::FETCH_ASSOC, null, function($row) { |
|
95 | 95 | return ['valid' => is_array($row), 'default' => []]; |
96 | 96 | }); |
97 | 97 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * @return object[] |
121 | 121 | */ |
122 | 122 | public function fetchObject($className = null, Closure $callback = null) { |
123 | - return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function ($row) { |
|
123 | + return $this->fetch($callback, PDO::FETCH_CLASS, $className ?: $this->defaultClassName, function($row) { |
|
124 | 124 | return ['valid' => is_object($row), 'default' => null]; |
125 | 125 | }); |
126 | 126 | } |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | * @return mixed[] |
131 | 131 | */ |
132 | 132 | public function fetchKeyValue($treatValueAsArray = false) { |
133 | - return $this->createTempStatement(function (QueryStatement $statement) use ($treatValueAsArray) { |
|
134 | - if($treatValueAsArray) { |
|
133 | + return $this->createTempStatement(function(QueryStatement $statement) use ($treatValueAsArray) { |
|
134 | + if ($treatValueAsArray) { |
|
135 | 135 | $rows = $statement->fetchAll(\PDO::FETCH_ASSOC); |
136 | 136 | $result = []; |
137 | - foreach($rows as $row) { |
|
137 | + foreach ($rows as $row) { |
|
138 | 138 | list($key) = array_values($row); |
139 | 139 | $result[$key] = $row; |
140 | 140 | } |
@@ -151,11 +151,11 @@ discard block |
||
151 | 151 | public function fetchGroups(array $fields) { |
152 | 152 | $rows = $this->fetchRows(); |
153 | 153 | $result = []; |
154 | - foreach($rows as $row) { |
|
154 | + foreach ($rows as $row) { |
|
155 | 155 | $tmp = &$result; |
156 | - foreach($fields as $field) { |
|
156 | + foreach ($fields as $field) { |
|
157 | 157 | $value = $row[$field]; |
158 | - if(!array_key_exists($value, $tmp)) { |
|
158 | + if (!array_key_exists($value, $tmp)) { |
|
159 | 159 | $tmp[$value] = []; |
160 | 160 | } |
161 | 161 | $tmp = &$tmp[$value]; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @return string[] |
170 | 170 | */ |
171 | 171 | public function fetchArray() { |
172 | - return $this->createTempStatement(function (QueryStatement $stmt) { |
|
172 | + return $this->createTempStatement(function(QueryStatement $stmt) { |
|
173 | 173 | return $stmt->fetchAll(\PDO::FETCH_COLUMN); |
174 | 174 | }); |
175 | 175 | } |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * @return null|bool|string|int|float |
180 | 180 | */ |
181 | 181 | public function fetchValue($default = null) { |
182 | - return $this->createTempStatement(function (QueryStatement $stmt) use ($default) { |
|
182 | + return $this->createTempStatement(function(QueryStatement $stmt) use ($default) { |
|
183 | 183 | $result = $stmt->fetch(\PDO::FETCH_NUM); |
184 | - if($result !== false) { |
|
184 | + if ($result !== false) { |
|
185 | 185 | return $result[0]; |
186 | 186 | } |
187 | 187 | return $default; |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $query = $this->__toString(); |
220 | 220 | $statement = $db->prepare($query); |
221 | 221 | $statement->execute($this->values); |
222 | - if($this->getCalcFoundRows()) { |
|
222 | + if ($this->getCalcFoundRows()) { |
|
223 | 223 | $this->foundRows = (int) $db->query('SELECT FOUND_ROWS()')->fetchColumn(); |
224 | 224 | } |
225 | 225 | return $statement; |
@@ -239,20 +239,20 @@ discard block |
||
239 | 239 | * @return mixed |
240 | 240 | */ |
241 | 241 | private function fetchAll(Closure $callback = null, $mode, $arg0 = null) { |
242 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
242 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0) { |
|
243 | 243 | $statement->setFetchMode($mode, $arg0); |
244 | 244 | $data = $statement->fetchAll(); |
245 | - if($this->preserveTypes) { |
|
245 | + if ($this->preserveTypes) { |
|
246 | 246 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
247 | - foreach($data as &$row) { |
|
247 | + foreach ($data as &$row) { |
|
248 | 248 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
249 | 249 | } |
250 | 250 | } |
251 | - if($callback !== null) { |
|
252 | - return call_user_func(function ($resultData = []) use ($data, $callback) { |
|
253 | - foreach($data as $row) { |
|
251 | + if ($callback !== null) { |
|
252 | + return call_user_func(function($resultData = []) use ($data, $callback) { |
|
253 | + foreach ($data as $row) { |
|
254 | 254 | $result = $callback($row); |
255 | - if($result !== null && !($result instanceof DBIgnoreRow)) { |
|
255 | + if ($result !== null && !($result instanceof DBIgnoreRow)) { |
|
256 | 256 | $resultData[] = $result; |
257 | 257 | } else { |
258 | 258 | $resultData[] = $row; |
@@ -286,20 +286,20 @@ discard block |
||
286 | 286 | * @return mixed |
287 | 287 | */ |
288 | 288 | private function fetch(Closure $callback = null, $mode, $arg0 = null, Closure $resultValidator = null) { |
289 | - return $this->createTempStatement(function (QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
289 | + return $this->createTempStatement(function(QueryStatement $statement) use ($callback, $mode, $arg0, $resultValidator) { |
|
290 | 290 | $statement->setFetchMode($mode, $arg0); |
291 | 291 | $row = $statement->fetch(); |
292 | 292 | $result = $resultValidator($row); |
293 | - if(!$result['valid']) { |
|
293 | + if (!$result['valid']) { |
|
294 | 294 | return $result['default']; |
295 | 295 | } |
296 | - if($this->preserveTypes) { |
|
296 | + if ($this->preserveTypes) { |
|
297 | 297 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
298 | 298 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
299 | 299 | } |
300 | - if($callback !== null) { |
|
300 | + if ($callback !== null) { |
|
301 | 301 | $result = $callback($row); |
302 | - if($result !== null) { |
|
302 | + if ($result !== null) { |
|
303 | 303 | $row = $result; |
304 | 304 | } |
305 | 305 | } |
@@ -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 = []) { |
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 | } |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function quoteExpression($expression, array $arguments = array()) { |
154 | 154 | $index = -1; |
155 | - $func = function () use ($arguments, &$index) { |
|
155 | + $func = function() use ($arguments, &$index) { |
|
156 | 156 | $index++; |
157 | - if(array_key_exists($index, $arguments)) { |
|
157 | + if (array_key_exists($index, $arguments)) { |
|
158 | 158 | $argument = $arguments[$index]; |
159 | 159 | $value = $this->quote($argument); |
160 | - } elseif(count($arguments) > 0) { |
|
160 | + } elseif (count($arguments) > 0) { |
|
161 | 161 | $args = $arguments; |
162 | 162 | $value = array_pop($args); |
163 | 163 | $value = $this->quote($value); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | * @return string |
176 | 176 | */ |
177 | 177 | public function quote($value) { |
178 | - if(is_null($value)) { |
|
178 | + if (is_null($value)) { |
|
179 | 179 | $result = 'NULL'; |
180 | - } elseif($value instanceof Builder\DBExpr) { |
|
180 | + } elseif ($value instanceof Builder\DBExpr) { |
|
181 | 181 | $result = $value->getExpression(); |
182 | - } elseif($value instanceof Builder\Select) { |
|
182 | + } elseif ($value instanceof Builder\Select) { |
|
183 | 183 | $result = sprintf('(%s)', (string) $value); |
184 | - } elseif(is_array($value)) { |
|
185 | - $result = join(', ', array_map(function ($value) { return $this->quote($value); }, $value)); |
|
184 | + } elseif (is_array($value)) { |
|
185 | + $result = join(', ', array_map(function($value) { return $this->quote($value); }, $value)); |
|
186 | 186 | } else { |
187 | 187 | $result = $this->pdo->quote($value); |
188 | 188 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if (is_numeric($field) || !is_string($field)) { |
198 | 198 | throw new UnexpectedValueException('Field name is invalid'); |
199 | 199 | } |
200 | - if(strpos($field, '`') !== false) { |
|
200 | + if (strpos($field, '`') !== false) { |
|
201 | 201 | return (string) $field; |
202 | 202 | } |
203 | 203 | $parts = explode('.', $field); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $select = array_key_exists('select-factory', $this->options) |
213 | 213 | ? call_user_func($this->options['select-factory'], $this, $this->options['select-options']) |
214 | 214 | : new Builder\RunnableSelect($this, $this->options['select-options']); |
215 | - if($fields !== null) { |
|
215 | + if ($fields !== null) { |
|
216 | 216 | $select->fields($fields); |
217 | 217 | } |
218 | 218 | return $select; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | $insert = array_key_exists('insert-factory', $this->options) |
227 | 227 | ? call_user_func($this->options['insert-factory'], $this, $this->options['insert-options']) |
228 | 228 | : new Builder\RunnableInsert($this, $this->options['insert-options']); |
229 | - if($fields !== null) { |
|
229 | + if ($fields !== null) { |
|
230 | 230 | $insert->addAll($fields); |
231 | 231 | } |
232 | 232 | return $insert; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | $update = array_key_exists('update-factory', $this->options) |
241 | 241 | ? call_user_func($this->options['update-factory'], $this, $this->options['update-options']) |
242 | 242 | : new Builder\RunnableUpdate($this, $this->options['update-options']); |
243 | - if($fields !== null) { |
|
243 | + if ($fields !== null) { |
|
244 | 244 | $update->setAll($fields); |
245 | 245 | } |
246 | 246 | return $update; |
@@ -259,8 +259,8 @@ discard block |
||
259 | 259 | * @return $this |
260 | 260 | */ |
261 | 261 | public function transactionStart() { |
262 | - if((int) $this->transactionLevel === 0) { |
|
263 | - if($this->pdo->inTransaction()) { |
|
262 | + if ((int) $this->transactionLevel === 0) { |
|
263 | + if ($this->pdo->inTransaction()) { |
|
264 | 264 | $this->outerTransaction = true; |
265 | 265 | } else { |
266 | 266 | $this->pdo->beginTransaction(); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @return $this |
275 | 275 | */ |
276 | 276 | public function transactionCommit() { |
277 | - return $this->transactionEnd(function () { |
|
277 | + return $this->transactionEnd(function() { |
|
278 | 278 | $this->pdo->commit(); |
279 | 279 | }); |
280 | 280 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return $this |
284 | 284 | */ |
285 | 285 | public function transactionRollback() { |
286 | - return $this->transactionEnd(function () { |
|
286 | + return $this->transactionEnd(function() { |
|
287 | 287 | $this->pdo->rollBack(); |
288 | 288 | }); |
289 | 289 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @return mixed |
294 | 294 | */ |
295 | 295 | public function dryRun($callback = null) { |
296 | - if(!$this->pdo->inTransaction()) { |
|
296 | + if (!$this->pdo->inTransaction()) { |
|
297 | 297 | $this->transactionStart(); |
298 | 298 | try { |
299 | 299 | return call_user_func($callback, $this); |
@@ -317,26 +317,26 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function transaction(callable $callback = null) { |
319 | 319 | $result = null; |
320 | - if(!$this->pdo->inTransaction()) { |
|
320 | + if (!$this->pdo->inTransaction()) { |
|
321 | 321 | $this->transactionStart(); |
322 | 322 | try { |
323 | 323 | $result = call_user_func($callback, $this); |
324 | 324 | $exception = null; |
325 | 325 | $this->transactionCommit(); |
326 | 326 | } finally { |
327 | - if($this->pdo->inTransaction()) { |
|
327 | + if ($this->pdo->inTransaction()) { |
|
328 | 328 | $this->transactionRollback(); |
329 | 329 | } |
330 | 330 | } |
331 | 331 | } else { |
332 | 332 | $uniqueId = $this->genUniqueId(); |
333 | 333 | $this->exec("SAVEPOINT {$uniqueId}"); |
334 | - $finally = function () use ($uniqueId) { |
|
334 | + $finally = function() use ($uniqueId) { |
|
335 | 335 | $this->exec("ROLLBACK TO {$uniqueId}"); |
336 | 336 | }; |
337 | 337 | try { |
338 | 338 | $result = call_user_func($callback, $this); |
339 | - $finally = function () use ($uniqueId) { |
|
339 | + $finally = function() use ($uniqueId) { |
|
340 | 340 | $this->exec("RELEASE SAVEPOINT {$uniqueId}"); |
341 | 341 | }; |
342 | 342 | } finally { |
@@ -353,11 +353,11 @@ discard block |
||
353 | 353 | */ |
354 | 354 | private function transactionEnd($fn) { |
355 | 355 | $this->transactionLevel--; |
356 | - if($this->transactionLevel < 0) { |
|
356 | + if ($this->transactionLevel < 0) { |
|
357 | 357 | throw new RuntimeException("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction"); |
358 | 358 | } |
359 | - if((int) $this->transactionLevel === 0) { |
|
360 | - if($this->outerTransaction) { |
|
359 | + if ((int) $this->transactionLevel === 0) { |
|
360 | + if ($this->outerTransaction) { |
|
361 | 361 | $this->outerTransaction = false; |
362 | 362 | } else { |
363 | 363 | call_user_func($fn); |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | */ |
375 | 375 | private function buildQueryStatement($query, $fn) { |
376 | 376 | $stmt = call_user_func($fn, $query); |
377 | - if(!$stmt) { |
|
377 | + if (!$stmt) { |
|
378 | 378 | throw new RuntimeException("Could not execute statement:\n{$query}"); |
379 | 379 | } |
380 | 380 | $stmtWrapper = new QueryStatement($stmt, $query, $this->exceptionInterpreter, $this->queryLoggers); |
@@ -15,8 +15,8 @@ discard block |
||
15 | 15 | * @return $this |
16 | 16 | */ |
17 | 17 | public function orderBy($expression, $direction = 'asc') { |
18 | - if($expression instanceof OrderBySpecification) { |
|
19 | - foreach($expression->getFields() as $field) { |
|
18 | + if ($expression instanceof OrderBySpecification) { |
|
19 | + foreach ($expression->getFields() as $field) { |
|
20 | 20 | $this->addOrder($field[0], $field[1]); |
21 | 21 | } |
22 | 22 | return $this; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function orderByValues($fieldName, array $values) { |
34 | 34 | $expr = []; |
35 | - foreach(array_values($values) as $idx => $value) { |
|
35 | + foreach (array_values($values) as $idx => $value) { |
|
36 | 36 | $expr[] = $this->db()->quoteExpression("WHEN ? THEN ?", [$value, $idx]); |
37 | 37 | } |
38 | 38 | $this->orderBy[] = [sprintf("CASE %s\n\t\t%s\n\tEND", $this->db()->quoteField($fieldName), join("\n\t\t", $expr)), 'ASC']; |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return string |
45 | 45 | */ |
46 | 46 | protected function buildOrder($query) { |
47 | - if(!count($this->orderBy)) { |
|
47 | + if (!count($this->orderBy)) { |
|
48 | 48 | return $query; |
49 | 49 | } |
50 | 50 | $query .= "ORDER BY\n"; |
51 | 51 | $arr = []; |
52 | - foreach($this->orderBy as $order) { |
|
52 | + foreach ($this->orderBy as $order) { |
|
53 | 53 | list($expression, $direction) = $order; |
54 | 54 | $arr[] = sprintf("\t%s %s", $expression, strtoupper($direction)); |
55 | 55 | } |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | private function addOrder($expression, $direction) { |
64 | 64 | $direction = $this->fixDirection($direction); |
65 | - if(is_array($expression)) { |
|
66 | - if(!count($expression)) { |
|
65 | + if (is_array($expression)) { |
|
66 | + if (!count($expression)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | $arguments = [ |
@@ -47,15 +47,15 @@ |
||
47 | 47 | */ |
48 | 48 | protected function buildJoins($query) { |
49 | 49 | $arr = []; |
50 | - foreach($this->joinTables as $table) { |
|
50 | + foreach ($this->joinTables as $table) { |
|
51 | 51 | $join = $table['type']." JOIN\n"; |
52 | - $join .= "\t" . $this->buildTableName($table['alias'], $table['name']); |
|
53 | - if($table['expression']) { |
|
54 | - $join .= " ON " . $this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
52 | + $join .= "\t".$this->buildTableName($table['alias'], $table['name']); |
|
53 | + if ($table['expression']) { |
|
54 | + $join .= " ON ".$this->db()->quoteExpression($table['expression'], $table['arguments']); |
|
55 | 55 | } |
56 | 56 | $arr[] = $join; |
57 | 57 | } |
58 | - if(count($arr)) { |
|
58 | + if (count($arr)) { |
|
59 | 59 | $query .= join("\n", $arr)."\n"; |
60 | 60 | } |
61 | 61 | return $query; |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @return $this |
14 | 14 | */ |
15 | 15 | protected function addTable($alias, $table = null) { |
16 | - if($table === null) { |
|
16 | + if ($table === null) { |
|
17 | 17 | list($alias, $table) = [$table, $alias]; |
18 | 18 | } |
19 | 19 | $this->tables[] = ['alias' => $alias, 'name' => $table]; |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | */ |
27 | 27 | protected function buildTables($query) { |
28 | 28 | $arr = []; |
29 | - foreach($this->tables as $table) { |
|
29 | + foreach ($this->tables as $table) { |
|
30 | 30 | $arr[] = "\t".$this->buildTableName($table['alias'], $table['name']); |
31 | 31 | } |
32 | - if(count($arr)) { |
|
32 | + if (count($arr)) { |
|
33 | 33 | $query .= join(",\n", $arr)."\n"; |
34 | 34 | } |
35 | 35 | return $query; |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * @return $this |
12 | 12 | */ |
13 | 13 | public function groupBy() { |
14 | - foreach(func_get_args() as $expression) { |
|
15 | - if(is_array($expression)) { |
|
16 | - if(!count($expression)) { |
|
14 | + foreach (func_get_args() as $expression) { |
|
15 | + if (is_array($expression)) { |
|
16 | + if (!count($expression)) { |
|
17 | 17 | continue; |
18 | 18 | } |
19 | 19 | $arguments = [ |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * @return string |
33 | 33 | */ |
34 | 34 | protected function buildGroups($query) { |
35 | - if(!count($this->groupBy)) { |
|
35 | + if (!count($this->groupBy)) { |
|
36 | 36 | return $query; |
37 | 37 | } |
38 | 38 | $query .= "GROUP BY\n"; |
39 | 39 | $arr = []; |
40 | - foreach($this->groupBy as $expression) { |
|
40 | + foreach ($this->groupBy as $expression) { |
|
41 | 41 | $arr[] = "\t{$expression}"; |
42 | 42 | } |
43 | 43 | return $query.join(",\n", $arr)."\n"; |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | public static function getFieldTypes(QueryStatement $statement) { |
12 | 12 | $fieldTypes = []; |
13 | - for($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
13 | + for ($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
14 | 14 | $fieldTypes[$column['name']] = self::getTypeFromNativeType($column['native_type']); |
15 | 15 | } |
16 | 16 | return $fieldTypes; |
@@ -25,7 +25,7 @@ |
||
25 | 25 | public function run(array $params = []) { |
26 | 26 | $this->query->execute($params); |
27 | 27 | $response = $this->query->getStatement()->rowCount(); |
28 | - if($this->callbackFn !== null) { |
|
28 | + if ($this->callbackFn !== null) { |
|
29 | 29 | $response = call_user_func($this->callbackFn, $response); |
30 | 30 | } |
31 | 31 | return $response; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return $this |
90 | 90 | */ |
91 | 91 | public function addExpr($str, $_ = null) { |
92 | - if(count(func_get_args()) > 1) { |
|
92 | + if (count(func_get_args()) > 1) { |
|
93 | 93 | $this->fields[] = func_get_args(); |
94 | 94 | } else { |
95 | 95 | $this->fields[] = $str; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @return $this |
104 | 104 | */ |
105 | 105 | public function updateExpr($str, $_ = null) { |
106 | - if(count(func_get_args()) > 1) { |
|
106 | + if (count(func_get_args()) > 1) { |
|
107 | 107 | $this->update[] = func_get_args(); |
108 | 108 | } else { |
109 | 109 | $this->update[] = $str; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @return $this |
117 | 117 | */ |
118 | 118 | public function addOrUpdateExpr($str) { |
119 | - if(count(func_get_args()) > 1) { |
|
119 | + if (count(func_get_args()) > 1) { |
|
120 | 120 | $this->fields[] = func_get_args(); |
121 | 121 | $this->update[] = func_get_args(); |
122 | 122 | } else { |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @return $this |
134 | 134 | */ |
135 | 135 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
136 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
136 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
137 | 137 | $this->add($field, $value); |
138 | 138 | }); |
139 | 139 | return $this; |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @return $this |
147 | 147 | */ |
148 | 148 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
149 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
149 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
150 | 150 | if ($field !== $this->keyField) { |
151 | 151 | $this->update($field, $value); |
152 | 152 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
191 | 191 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
192 | 192 | |
193 | - if($this->from !== null) { |
|
193 | + if ($this->from !== null) { |
|
194 | 194 | $fields = $this->from->getFields(); |
195 | 195 | $queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields))); |
196 | 196 | $queryArr[] = $this->from; |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | } |
205 | 205 | |
206 | 206 | $updateData = $this->buildUpdate(); |
207 | - if($updateData) { |
|
207 | + if ($updateData) { |
|
208 | 208 | $queryArr[] = "{$updateData}\n"; |
209 | 209 | } |
210 | 210 | |
@@ -237,12 +237,12 @@ discard block |
||
237 | 237 | * @return $this |
238 | 238 | */ |
239 | 239 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
240 | - if($mask !== null) { |
|
240 | + if ($mask !== null) { |
|
241 | 241 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
242 | 242 | } |
243 | - if($excludeFields !== null) { |
|
244 | - foreach($excludeFields as $excludeField) { |
|
245 | - if(array_key_exists($excludeField, $data)) { |
|
243 | + if ($excludeFields !== null) { |
|
244 | + foreach ($excludeFields as $excludeField) { |
|
245 | + if (array_key_exists($excludeField, $data)) { |
|
246 | 246 | unset($data[$excludeField]); |
247 | 247 | } |
248 | 248 | } |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | */ |
260 | 260 | private function buildUpdate() { |
261 | 261 | $queryArr = []; |
262 | - if(!empty($this->update)) { |
|
262 | + if (!empty($this->update)) { |
|
263 | 263 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
264 | 264 | $updateArr = []; |
265 | - if($this->keyField !== null) { |
|
265 | + if ($this->keyField !== null) { |
|
266 | 266 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
267 | 267 | } |
268 | 268 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @return array |
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 = []; |
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 | } |