@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * @return $this |
30 | 30 | */ |
31 | 31 | public function from(string $alias, $table = null) { |
32 | - if($table !== null) { |
|
32 | + if ($table !== null) { |
|
33 | 33 | $this->aliases[] = $alias; |
34 | 34 | } |
35 | - if($table === null) { |
|
35 | + if ($table === null) { |
|
36 | 36 | [$alias, $table] = [$table, $alias]; |
37 | 37 | } |
38 | 38 | $this->addTable($alias, $table); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function __toString(): string { |
52 | 52 | $query = "DELETE "; |
53 | 53 | $query .= implode(', ', $this->aliases); |
54 | - $query = trim($query) . " FROM\n"; |
|
54 | + $query = trim($query)." FROM\n"; |
|
55 | 55 | $query = $this->buildTables($query); |
56 | 56 | $query = $this->buildJoins($query); |
57 | 57 | $query = $this->buildWhereConditions($query); |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | * @param array<int, mixed> $args |
11 | 11 | */ |
12 | 12 | public static function addCondition(callable $addFn, $expression, array $args): void { |
13 | - if($expression instanceof OptionalExpression) { |
|
14 | - if($expression->isValid()) { |
|
13 | + if ($expression instanceof OptionalExpression) { |
|
14 | + if ($expression->isValid()) { |
|
15 | 15 | $addFn($expression->getExpression(), [$expression->getValue()]); |
16 | 16 | } |
17 | - } elseif(is_object($expression)) { |
|
17 | + } elseif (is_object($expression)) { |
|
18 | 18 | self::addAsArray($addFn, (array) $expression, $args); |
19 | - } elseif(is_array($expression)) { |
|
19 | + } elseif (is_array($expression)) { |
|
20 | 20 | self::addAsArray($addFn, $expression, $args); |
21 | 21 | } else { |
22 | 22 | $addFn($expression, $args); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param array<int, mixed> $args |
30 | 30 | */ |
31 | 31 | private static function addAsArray(callable $addFn, array $expression, array $args): void { |
32 | - if(count($expression) > 0) { |
|
32 | + if (count($expression) > 0) { |
|
33 | 33 | $addFn($expression, $args); |
34 | 34 | } |
35 | 35 | } |
@@ -9,8 +9,8 @@ |
||
9 | 9 | */ |
10 | 10 | public static function convertValues(array $row, array $columnDefinitions): array { |
11 | 11 | $result = []; |
12 | - foreach($row as $key => $value) { |
|
13 | - if($value !== null) { |
|
12 | + foreach ($row as $key => $value) { |
|
13 | + if ($value !== null) { |
|
14 | 14 | $result[$key] = self::convertValue($value, $columnDefinitions[$key]); |
15 | 15 | } else { |
16 | 16 | $result[$key] = $value; |
@@ -10,7 +10,7 @@ |
||
10 | 10 | */ |
11 | 11 | public static function getFieldTypes(QueryStatement $statement): array { |
12 | 12 | $fieldTypes = []; |
13 | - for($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
13 | + for ($i = 0; $column = $statement->getColumnMeta($i); $i++) { |
|
14 | 14 | $fieldTypes[(string) $column['name']] = self::getTypeFromNativeType($column['native_type']); |
15 | 15 | } |
16 | 16 | return $fieldTypes; |
@@ -13,15 +13,15 @@ |
||
13 | 13 | * @return string |
14 | 14 | */ |
15 | 15 | public static function build(Database $db, string $query, array $conditions, string $token): string { |
16 | - if(!count($conditions)) { |
|
16 | + if (!count($conditions)) { |
|
17 | 17 | return $query; |
18 | 18 | } |
19 | 19 | $query .= "{$token}\n"; |
20 | 20 | $arr = []; |
21 | - foreach($conditions as [$expression, $arguments]) { |
|
22 | - if(is_array($expression)) { |
|
23 | - foreach($expression as $key => $value) { |
|
24 | - if($value === null) { |
|
21 | + foreach ($conditions as [$expression, $arguments]) { |
|
22 | + if (is_array($expression)) { |
|
23 | + foreach ($expression as $key => $value) { |
|
24 | + if ($value === null) { |
|
25 | 25 | $arr = self::buildCondition($arr, "ISNULL(`{$key}`)", [$value], $db); |
26 | 26 | } else { |
27 | 27 | $arr = self::buildCondition($arr, "`{$key}`=?", [$value], $db); |
@@ -28,7 +28,7 @@ |
||
28 | 28 | public function run(array $params = []) { |
29 | 29 | $this->query->execute($params); |
30 | 30 | $response = $this->query->getStatement()->rowCount(); |
31 | - if($this->callbackFn !== null) { |
|
31 | + if ($this->callbackFn !== null) { |
|
32 | 32 | $response = call_user_func($this->callbackFn); |
33 | 33 | } |
34 | 34 | return $response; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return $this |
89 | 89 | */ |
90 | 90 | public function addExpr(string $str, ...$args) { |
91 | - if(count($args) > 0) { |
|
91 | + if (count($args) > 0) { |
|
92 | 92 | $this->fields[] = func_get_args(); |
93 | 93 | } else { |
94 | 94 | $this->fields[] = $str; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * @return $this |
103 | 103 | */ |
104 | 104 | public function updateExpr(string $str, ...$args) { |
105 | - if(count($args) > 0) { |
|
105 | + if (count($args) > 0) { |
|
106 | 106 | $this->update[] = func_get_args(); |
107 | 107 | } else { |
108 | 108 | $this->update[] = $str; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | * @return $this |
117 | 117 | */ |
118 | 118 | public function addOrUpdateExpr(string $expr, ...$args) { |
119 | - if(count($args) > 0) { |
|
119 | + if (count($args) > 0) { |
|
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,8 +146,8 @@ 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) { |
|
150 | - if($field !== $this->keyField) { |
|
149 | + $this->addAllTo($data, $mask, $excludeFields, function($field, $value) { |
|
150 | + if ($field !== $this->keyField) { |
|
151 | 151 | $this->update($field, $value); |
152 | 152 | } |
153 | 153 | }); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @return string |
192 | 192 | */ |
193 | 193 | public function __toString(): string { |
194 | - if($this->table === null) { |
|
194 | + if ($this->table === null) { |
|
195 | 195 | throw new RuntimeException('Specify a table-name'); |
196 | 196 | } |
197 | 197 | |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | $ignoreStr = $this->ignore ? ' IGNORE' : ''; |
202 | 202 | $queryArr[] = "INSERT{$ignoreStr} INTO\n\t{$tableName}\n"; |
203 | 203 | |
204 | - if($this->from !== null) { |
|
204 | + if ($this->from !== null) { |
|
205 | 205 | $fields = $this->from->getFields(); |
206 | 206 | $queryArr[] = sprintf("\t(%s)\n", implode(', ', array_keys($fields))); |
207 | 207 | $queryArr[] = $this->from; |
208 | 208 | } else { |
209 | 209 | $fields = $this->fields; |
210 | 210 | $insertData = $this->buildFieldList($fields); |
211 | - if(!count($insertData)) { |
|
211 | + if (!count($insertData)) { |
|
212 | 212 | throw new RuntimeException('No field-data found'); |
213 | 213 | } |
214 | 214 | $queryArr[] = sprintf("SET\n%s\n", implode(",\n", $insertData)); |
215 | 215 | } |
216 | 216 | |
217 | 217 | $updateData = $this->buildUpdate(); |
218 | - if($updateData) { |
|
218 | + if ($updateData) { |
|
219 | 219 | $queryArr[] = "{$updateData}\n"; |
220 | 220 | } |
221 | 221 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return array<string|int, mixed> |
230 | 230 | */ |
231 | 231 | private function addTo(array $fields, string $field, $value): array { |
232 | - if(!$this->isFieldNameValid($field)) { |
|
232 | + if (!$this->isFieldNameValid($field)) { |
|
233 | 233 | throw new UnexpectedValueException('Field name is invalid'); |
234 | 234 | } |
235 | 235 | $sqlField = $field; |
@@ -245,18 +245,18 @@ discard block |
||
245 | 245 | * @param callable(string, mixed): void $fn |
246 | 246 | */ |
247 | 247 | private function addAllTo(array $data, ?array $mask, ?array $excludeFields, callable $fn): void { |
248 | - if($mask !== null) { |
|
248 | + if ($mask !== null) { |
|
249 | 249 | $data = array_intersect_key($data, array_combine($mask, $mask)); |
250 | 250 | } |
251 | - if($excludeFields !== null) { |
|
252 | - foreach($excludeFields as $excludeField) { |
|
253 | - if(array_key_exists($excludeField, $data)) { |
|
251 | + if ($excludeFields !== null) { |
|
252 | + foreach ($excludeFields as $excludeField) { |
|
253 | + if (array_key_exists($excludeField, $data)) { |
|
254 | 254 | unset($data[$excludeField]); |
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
258 | 258 | $data = $this->clearValues($data); |
259 | - foreach($data as $field => $value) { |
|
259 | + foreach ($data as $field => $value) { |
|
260 | 260 | $fn($field, $value); |
261 | 261 | } |
262 | 262 | } |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | */ |
267 | 267 | private function buildUpdate(): string { |
268 | 268 | $queryArr = []; |
269 | - if(!empty($this->update)) { |
|
269 | + if (!empty($this->update)) { |
|
270 | 270 | $queryArr[] = "ON DUPLICATE KEY UPDATE\n"; |
271 | 271 | $updateArr = []; |
272 | - if($this->keyField !== null) { |
|
272 | + if ($this->keyField !== null) { |
|
273 | 273 | $updateArr[] = "\t`{$this->keyField}` = LAST_INSERT_ID({$this->keyField})"; |
274 | 274 | } |
275 | 275 | $updateArr = $this->buildFieldList($this->update, $updateArr); |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array<string, mixed> |
293 | 293 | */ |
294 | 294 | private function clearValues(array $values): array { |
295 | - if(!count($values)) { |
|
295 | + if (!count($values)) { |
|
296 | 296 | return []; |
297 | 297 | } |
298 | 298 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | $fields = $this->db()->getTableFields($tableName); |
301 | 301 | $result = []; |
302 | 302 | |
303 | - foreach($values as $fieldName => $fieldValue) { |
|
304 | - if(in_array($fieldName, $fields)) { |
|
303 | + foreach ($values as $fieldName => $fieldValue) { |
|
304 | + if (in_array($fieldName, $fields)) { |
|
305 | 305 | $result[$fieldName] = $fieldValue; |
306 | 306 | } |
307 | 307 | } |
@@ -122,7 +122,7 @@ |
||
122 | 122 | * @return $this |
123 | 123 | */ |
124 | 124 | public function from(?string $alias, $table = null): self { |
125 | - if($table === null) { |
|
125 | + if ($table === null) { |
|
126 | 126 | [$alias, $table] = [$table, $alias]; |
127 | 127 | $this->addTable($alias, (string) $table); |
128 | 128 | } else { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return $this |
30 | 30 | */ |
31 | 31 | public function table(string $alias, $table = null): self { |
32 | - if($table === null) { |
|
32 | + if ($table === null) { |
|
33 | 33 | [$alias, $table] = [$table, $alias]; |
34 | 34 | } |
35 | 35 | $this->addTable($alias, $table); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return $this |
65 | 65 | */ |
66 | 66 | public function setExpr(string $expr, ...$args): self { |
67 | - if(count($args) > 0) { |
|
67 | + if (count($args) > 0) { |
|
68 | 68 | $this->fields[] = func_get_args(); |
69 | 69 | } else { |
70 | 70 | $this->fields[] = $expr; |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | * @return $this |
79 | 79 | */ |
80 | 80 | public function setAll(array $data, array $allowedFields = null): self { |
81 | - if($allowedFields !== null) { |
|
82 | - foreach($data as $fieldName => $value) { |
|
83 | - if(in_array($fieldName, $allowedFields)) { |
|
81 | + if ($allowedFields !== null) { |
|
82 | + foreach ($data as $fieldName => $value) { |
|
83 | + if (in_array($fieldName, $allowedFields)) { |
|
84 | 84 | $this->set($fieldName, $value); |
85 | 85 | } |
86 | 86 | } |
87 | 87 | } else { |
88 | 88 | $values = $this->clearValues($data); |
89 | - foreach($values as $fieldName => $value) { |
|
89 | + foreach ($values as $fieldName => $value) { |
|
90 | 90 | $this->set($fieldName, $value); |
91 | 91 | } |
92 | 92 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | */ |
122 | 122 | private function buildAssignments(string $query): string { |
123 | 123 | $sqlFields = $this->buildFieldList($this->fields); |
124 | - if(!count($sqlFields)) { |
|
124 | + if (!count($sqlFields)) { |
|
125 | 125 | throw new RuntimeException('No field-data found'); |
126 | 126 | } |
127 | 127 | return sprintf("%s%s\n", $query, implode(",\n", $sqlFields)); |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | * @return array<string, mixed> |
133 | 133 | */ |
134 | 134 | private function clearValues(array $values): array { |
135 | - if(!count($values)) { |
|
135 | + if (!count($values)) { |
|
136 | 136 | return []; |
137 | 137 | } |
138 | 138 | $tables = $this->getTables(); |
139 | - if(!count($tables)) { |
|
139 | + if (!count($tables)) { |
|
140 | 140 | throw new RuntimeException('Table name is missing'); |
141 | 141 | } |
142 | - if(count($tables) > 1) { |
|
142 | + if (count($tables) > 1) { |
|
143 | 143 | throw new RuntimeException('Batch values only work with max. one table'); |
144 | 144 | } |
145 | 145 | |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | $tableName = $table['name']; |
148 | 148 | |
149 | 149 | $result = []; |
150 | - if(is_string($tableName)) { |
|
150 | + if (is_string($tableName)) { |
|
151 | 151 | $fields = $this->db()->getTableFields($tableName); |
152 | 152 | |
153 | - foreach($values as $fieldName => $fieldValue) { |
|
154 | - if(in_array($fieldName, $fields, true)) { |
|
153 | + foreach ($values as $fieldName => $fieldValue) { |
|
154 | + if (in_array($fieldName, $fields, true)) { |
|
155 | 155 | $result[$fieldName] = $fieldValue; |
156 | 156 | } |
157 | 157 | } |