@@ -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; |
@@ -22,16 +22,16 @@ |
||
22 | 22 | * @return Generator|mixed[] |
23 | 23 | */ |
24 | 24 | public function generate(QueryStatement $statement, Closure $callback = null) { |
25 | - while($row = $statement->fetch()) { |
|
26 | - if($this->preserveTypes) { |
|
25 | + while ($row = $statement->fetch()) { |
|
26 | + if ($this->preserveTypes) { |
|
27 | 27 | $columnDefinitions = FieldTypeProvider::getFieldTypes($statement); |
28 | 28 | $row = FieldValueConverter::convertValues($row, $columnDefinitions); |
29 | 29 | } |
30 | - if($callback !== null) { |
|
30 | + if ($callback !== null) { |
|
31 | 31 | $result = $callback($row); |
32 | - if($result instanceof DBIgnoreRow) { |
|
32 | + if ($result instanceof DBIgnoreRow) { |
|
33 | 33 | // Do nothing in this case |
34 | - } elseif($result !== null) { |
|
34 | + } elseif ($result !== null) { |
|
35 | 35 | yield $result; |
36 | 36 | } else { |
37 | 37 | yield $row; |
@@ -31,10 +31,10 @@ |
||
31 | 31 | * @return Select|null |
32 | 32 | */ |
33 | 33 | public function get($tableName) { |
34 | - if($this->has($tableName)) { |
|
34 | + if ($this->has($tableName)) { |
|
35 | 35 | $table = $this->virtualTables[(string) $tableName]; |
36 | - if($table instanceof Closure) { |
|
37 | - if($tableName instanceof VirtualTable) { |
|
36 | + if ($table instanceof Closure) { |
|
37 | + if ($tableName instanceof VirtualTable) { |
|
38 | 38 | $params = $tableName->getParams(); |
39 | 39 | return call_user_func($table, $params); |
40 | 40 | } |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function setFetchMode($mode, $arg0 = null, array $arg1 = null) { |
49 | 49 | $args = [$mode]; |
50 | - if($arg0 !== null) { |
|
50 | + if ($arg0 !== null) { |
|
51 | 51 | $args[] = $arg0; |
52 | 52 | } |
53 | - if($arg1 !== null) { |
|
53 | + if ($arg1 !== null) { |
|
54 | 54 | $args[] = $arg1; |
55 | 55 | } |
56 | 56 | $this->statement->setFetchMode(...$args); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $timer = microtime(true); |
68 | 68 | $response = $this->statement->execute($params); |
69 | 69 | $this->queryLoggers->log($this->query, microtime(true)-$timer); |
70 | - if(!$response) { |
|
70 | + if (!$response) { |
|
71 | 71 | throw new SqlException('Execution returned with "false".'); |
72 | 72 | } |
73 | 73 | }); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function fetchAll($fetchStyle = null, $fetchArgument = null, array $ctorArgs = []) { |
84 | 84 | return $this->exceptionHandler(function() use ($fetchStyle, $fetchArgument, $ctorArgs) { |
85 | - if($fetchArgument !== null) { |
|
85 | + if ($fetchArgument !== null) { |
|
86 | 86 | return $this->statement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); |
87 | 87 | } |
88 | 88 | return $this->statement->fetchAll($fetchStyle); |
@@ -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]; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @return $this |
62 | 62 | */ |
63 | 63 | public function setExpr($expr, ...$args) { |
64 | - if(count($args) > 0) { |
|
64 | + if (count($args) > 0) { |
|
65 | 65 | $this->fields[] = func_get_args(); |
66 | 66 | } else { |
67 | 67 | $this->fields[] = $expr; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return $this |
87 | 87 | */ |
88 | 88 | public function addExpr($str, ...$args) { |
89 | - if(count($args) > 0) { |
|
89 | + if (count($args) > 0) { |
|
90 | 90 | $this->fields[] = func_get_args(); |
91 | 91 | } else { |
92 | 92 | $this->fields[] = $str; |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @return $this |
101 | 101 | */ |
102 | 102 | public function updateExpr($str, ...$args) { |
103 | - if(count($args) > 0) { |
|
103 | + if (count($args) > 0) { |
|
104 | 104 | $this->update[] = func_get_args(); |
105 | 105 | } else { |
106 | 106 | $this->update[] = $str; |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * @return $this |
115 | 115 | */ |
116 | 116 | public function addOrUpdateExpr($expr, ...$args) { |
117 | - if(count($args) > 0) { |
|
117 | + if (count($args) > 0) { |
|
118 | 118 | $this->fields[] = func_get_args(); |
119 | 119 | $this->update[] = func_get_args(); |
120 | 120 | } else { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @return $this |
132 | 132 | */ |
133 | 133 | public function addAll(array $data, array $mask = null, array $excludeFields = null) { |
134 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
134 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
135 | 135 | $this->add($field, $value); |
136 | 136 | }); |
137 | 137 | return $this; |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return $this |
145 | 145 | */ |
146 | 146 | public function updateAll(array $data, array $mask = null, array $excludeFields = null) { |
147 | - $this->addAllTo($data, $mask, $excludeFields, function ($field, $value) { |
|
147 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
148 | 148 | if ($field !== $this->keyField) { |
149 | 149 | $this->update($field, $value); |
150 | 150 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
188 | 188 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
189 | 189 | |
190 | - if($this->from !== null) { |
|
190 | + if ($this->from !== null) { |
|
191 | 191 | $fields = $this->from->getFields(); |
192 | 192 | $queryArr[] = sprintf("\t(%s)\n", join(', ', array_keys($fields))); |
193 | 193 | $queryArr[] = $this->from; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | } |
202 | 202 | |
203 | 203 | $updateData = $this->buildUpdate(); |
204 | - if($updateData) { |
|
204 | + if ($updateData) { |
|
205 | 205 | $queryArr[] = "{$updateData}\n"; |
206 | 206 | } |
207 | 207 | |
@@ -234,12 +234,12 @@ discard block |
||
234 | 234 | * @return $this |
235 | 235 | */ |
236 | 236 | private function addAllTo(array $data, array $mask = null, array $excludeFields = null, $fn) { |
237 | - if($mask !== null) { |
|
237 | + if ($mask !== null) { |
|
238 | 238 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
239 | 239 | } |
240 | - if($excludeFields !== null) { |
|
241 | - foreach($excludeFields as $excludeField) { |
|
242 | - if(array_key_exists($excludeField, $data)) { |
|
240 | + if ($excludeFields !== null) { |
|
241 | + foreach ($excludeFields as $excludeField) { |
|
242 | + if (array_key_exists($excludeField, $data)) { |
|
243 | 243 | unset($data[$excludeField]); |
244 | 244 | } |
245 | 245 | } |
@@ -256,10 +256,10 @@ discard block |
||
256 | 256 | */ |
257 | 257 | private function buildUpdate() { |
258 | 258 | $queryArr = []; |
259 | - if(!empty($this->update)) { |
|
259 | + if (!empty($this->update)) { |
|
260 | 260 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
261 | 261 | $updateArr = []; |
262 | - if($this->keyField !== null) { |
|
262 | + if ($this->keyField !== null) { |
|
263 | 263 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
264 | 264 | } |
265 | 265 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | private function clearValues(array $values) { |
285 | - if(!count($values)) { |
|
285 | + if (!count($values)) { |
|
286 | 286 | return []; |
287 | 287 | } |
288 | 288 | |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $result = []; |
292 | 292 | |
293 | 293 | foreach ($values as $fieldName => $fieldValue) { |
294 | - if(in_array($fieldName, $fields)) { |
|
294 | + if (in_array($fieldName, $fields)) { |
|
295 | 295 | $result[$fieldName] = $fieldValue; |
296 | 296 | } |
297 | 297 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | * @return $this |
13 | 13 | */ |
14 | 14 | public function groupBy(...$args) { |
15 | - foreach($args as $expression) { |
|
16 | - if(is_array($expression)) { |
|
17 | - if(!count($expression)) { |
|
15 | + foreach ($args as $expression) { |
|
16 | + if (is_array($expression)) { |
|
17 | + if (!count($expression)) { |
|
18 | 18 | continue; |
19 | 19 | } |
20 | 20 | $arguments = [ |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | * @return string |
34 | 34 | */ |
35 | 35 | protected function buildGroups($query) { |
36 | - if(!count($this->groupBy)) { |
|
36 | + if (!count($this->groupBy)) { |
|
37 | 37 | return $query; |
38 | 38 | } |
39 | 39 | $query .= "GROUP BY\n"; |
40 | 40 | $arr = []; |
41 | - foreach($this->groupBy as $expression) { |
|
41 | + foreach ($this->groupBy as $expression) { |
|
42 | 42 | $arr[] = "\t{$expression}"; |
43 | 43 | } |
44 | 44 | return $query.join(",\n", $arr)."\n"; |
@@ -17,8 +17,8 @@ |
||
17 | 17 | * @return $this |
18 | 18 | */ |
19 | 19 | public function where($expression, ...$args) { |
20 | - if($expression instanceof OptionalExpression) { |
|
21 | - if($expression->isValid()) { |
|
20 | + if ($expression instanceof OptionalExpression) { |
|
21 | + if ($expression->isValid()) { |
|
22 | 22 | $this->where[] = [$expression->getExpression(), $expression->getValue()]; |
23 | 23 | } |
24 | 24 | } else { |