@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | ]; |
70 | 70 | } |
71 | 71 | } |
72 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
73 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
74 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
75 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
76 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? trim((string)$temp['path'], '/') : null; |
|
77 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
78 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
79 | - parse_str((string)$temp['query'], $connection['opts']); |
|
72 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
73 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
74 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
75 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
76 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? trim((string) $temp['path'], '/') : null; |
|
77 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
78 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
79 | + parse_str((string) $temp['query'], $connection['opts']); |
|
80 | 80 | } |
81 | 81 | // create the driver |
82 | 82 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
83 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
83 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
84 | 84 | if (!class_exists($tmp)) { |
85 | 85 | throw new DBException('Unknown DB backend'); |
86 | 86 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $new = ''; |
119 | 119 | $par = array_values($par); |
120 | 120 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
121 | - $par = [ $par ]; |
|
121 | + $par = [$par]; |
|
122 | 122 | } |
123 | 123 | $parts = explode('??', $sql); |
124 | 124 | $index = 0; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $index += count($tmp) - 1; |
129 | 129 | if (isset($par[$index])) { |
130 | 130 | if (!is_array($par[$index])) { |
131 | - $par[$index] = [ $par[$index] ]; |
|
131 | + $par[$index] = [$par[$index]]; |
|
132 | 132 | } |
133 | 133 | $params = $par[$index]; |
134 | 134 | array_splice($par, $index, 1, $params); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $new .= implode(',', array_fill(0, count($params), '?')); |
137 | 137 | } |
138 | 138 | } |
139 | - return [ $new, $par ]; |
|
139 | + return [$new, $par]; |
|
140 | 140 | } |
141 | 141 | /** |
142 | 142 | * Run a query (prepare & execute). |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | ): Collection { |
186 | 186 | $coll = Collection::from($this->query($sql, $par, $buff)); |
187 | 187 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
188 | - $coll->map(function ($v) use ($keys) { |
|
188 | + $coll->map(function($v) use ($keys) { |
|
189 | 189 | $new = []; |
190 | 190 | foreach ($v as $k => $vv) { |
191 | 191 | $new[call_user_func($keys, $k)] = $vv; |
@@ -194,18 +194,18 @@ discard block |
||
194 | 194 | }); |
195 | 195 | } |
196 | 196 | if ($key !== null) { |
197 | - $coll->mapKey(function ($v) use ($key) { |
|
197 | + $coll->mapKey(function($v) use ($key) { |
|
198 | 198 | return $v[$key]; |
199 | 199 | }); |
200 | 200 | } |
201 | 201 | if ($skip) { |
202 | - $coll->map(function ($v) use ($key) { |
|
202 | + $coll->map(function($v) use ($key) { |
|
203 | 203 | unset($v[$key]); |
204 | 204 | return $v; |
205 | 205 | }); |
206 | 206 | } |
207 | 207 | if ($opti) { |
208 | - $coll->map(function ($v) { |
|
208 | + $coll->map(function($v) { |
|
209 | 209 | return count($v) === 1 ? current($v) : $v; |
210 | 210 | }); |
211 | 211 | } |
@@ -300,8 +300,7 @@ discard block |
||
300 | 300 | public function definition(string $table, bool $detectRelations = true) : Table |
301 | 301 | { |
302 | 302 | return isset($this->tables[$table]) ? |
303 | - $this->tables[$table] : |
|
304 | - $this->driver->table($table, $detectRelations); |
|
303 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
305 | 304 | } |
306 | 305 | /** |
307 | 306 | * Parse all tables from the database. |
@@ -318,13 +317,13 @@ discard block |
||
318 | 317 | */ |
319 | 318 | public function getSchema(bool $asPlainArray = true): array |
320 | 319 | { |
321 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
320 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
322 | 321 | return [ |
323 | 322 | 'name' => $table->getName(), |
324 | 323 | 'schema' => $table->getSchema(), |
325 | 324 | 'pkey' => $table->getPrimaryKey(), |
326 | 325 | 'comment' => $table->getComment(), |
327 | - 'columns' => array_map(function ($column) { |
|
326 | + 'columns' => array_map(function($column) { |
|
328 | 327 | return [ |
329 | 328 | 'name' => $column->getName(), |
330 | 329 | 'type' => $column->getType(), |
@@ -335,9 +334,9 @@ discard block |
||
335 | 334 | 'nullable' => $column->isNullable() |
336 | 335 | ]; |
337 | 336 | }, $table->getFullColumns()), |
338 | - 'relations' => array_map(function ($rel) { |
|
337 | + 'relations' => array_map(function($rel) { |
|
339 | 338 | $relation = clone $rel; |
340 | - $relation = (array)$relation; |
|
339 | + $relation = (array) $relation; |
|
341 | 340 | $relation['table'] = $rel->table->getName(); |
342 | 341 | if ($rel->pivot) { |
343 | 342 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -399,11 +398,10 @@ discard block |
||
399 | 398 | { |
400 | 399 | return new TableQueryMapped($this, $this->definition($table), $findRelations); |
401 | 400 | } |
402 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
401 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
403 | 402 | { |
404 | 403 | return ($args[0] ?? false) ? |
405 | - $this->tableMapped($method, $args[1] ?? false) : |
|
406 | - $this->table($method, $args[1] ?? false); |
|
404 | + $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false); |
|
407 | 405 | } |
408 | 406 | public function findRelation(string $start, string $end): array |
409 | 407 | { |
@@ -436,12 +434,12 @@ discard block |
||
436 | 434 | $relations[$t] = $w; |
437 | 435 | } |
438 | 436 | if (!isset($schema[$name])) { |
439 | - $schema[$name] = [ 'edges' => [] ]; |
|
437 | + $schema[$name] = ['edges' => []]; |
|
440 | 438 | } |
441 | 439 | foreach ($relations as $t => $w) { |
442 | 440 | $schema[$name]['edges'][$t] = $w; |
443 | 441 | if (!isset($schema[$t])) { |
444 | - $schema[$t] = [ 'edges' => [] ]; |
|
442 | + $schema[$t] = ['edges' => []]; |
|
445 | 443 | } |
446 | 444 | $schema[$t]['edges'][$name] = $w; |
447 | 445 | } |