@@ -65,19 +65,19 @@ discard block |
||
65 | 65 | ]; |
66 | 66 | } |
67 | 67 | } |
68 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
69 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
70 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
71 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
72 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? |
|
73 | - trim((string)$temp['path'], '/') : null; |
|
74 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
75 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
76 | - parse_str((string)$temp['query'], $connection['opts']); |
|
68 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
69 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
70 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
71 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
72 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? |
|
73 | + trim((string) $temp['path'], '/') : null; |
|
74 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
75 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
76 | + parse_str((string) $temp['query'], $connection['opts']); |
|
77 | 77 | } |
78 | 78 | // create the driver |
79 | 79 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
80 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
80 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
81 | 81 | if (!class_exists($tmp)) { |
82 | 82 | throw new DBException('Unknown DB backend'); |
83 | 83 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $new = ''; |
116 | 116 | $par = array_values($par); |
117 | 117 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
118 | - $par = [ $par ]; |
|
118 | + $par = [$par]; |
|
119 | 119 | } |
120 | 120 | $parts = explode('??', $sql); |
121 | 121 | $index = 0; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $index += count($tmp) - 1; |
126 | 126 | if (isset($par[$index])) { |
127 | 127 | if (!is_array($par[$index])) { |
128 | - $par[$index] = [ $par[$index] ]; |
|
128 | + $par[$index] = [$par[$index]]; |
|
129 | 129 | } |
130 | 130 | $params = $par[$index]; |
131 | 131 | array_splice($par, $index, 1, $params); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $new .= implode(',', array_fill(0, count($params), '?')); |
134 | 134 | } |
135 | 135 | } |
136 | - return [ $new, $par ]; |
|
136 | + return [$new, $par]; |
|
137 | 137 | } |
138 | 138 | /** |
139 | 139 | * Run a query (prepare & execute). |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | ): Collection { |
183 | 183 | $coll = Collection::from($this->query($sql, $par, $buff)); |
184 | 184 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
185 | - $coll->map(function ($v) use ($keys) { |
|
185 | + $coll->map(function($v) use ($keys) { |
|
186 | 186 | $new = []; |
187 | 187 | foreach ($v as $k => $vv) { |
188 | 188 | $new[call_user_func($keys, $k)] = $vv; |
@@ -191,18 +191,18 @@ discard block |
||
191 | 191 | }); |
192 | 192 | } |
193 | 193 | if ($key !== null) { |
194 | - $coll->mapKey(function ($v) use ($key) { |
|
194 | + $coll->mapKey(function($v) use ($key) { |
|
195 | 195 | return $v[$key]; |
196 | 196 | }); |
197 | 197 | } |
198 | 198 | if ($skip) { |
199 | - $coll->map(function ($v) use ($key) { |
|
199 | + $coll->map(function($v) use ($key) { |
|
200 | 200 | unset($v[$key]); |
201 | 201 | return $v; |
202 | 202 | }); |
203 | 203 | } |
204 | 204 | if ($opti) { |
205 | - $coll->map(function ($v) { |
|
205 | + $coll->map(function($v) { |
|
206 | 206 | return count($v) === 1 ? current($v) : $v; |
207 | 207 | }); |
208 | 208 | } |
@@ -311,8 +311,7 @@ discard block |
||
311 | 311 | public function definition(string $table, bool $detectRelations = true) : Table |
312 | 312 | { |
313 | 313 | return isset($this->schema) ? |
314 | - $this->schema->getTable($table) : |
|
315 | - $this->driver->table($table, $detectRelations); |
|
314 | + $this->schema->getTable($table) : $this->driver->table($table, $detectRelations); |
|
316 | 315 | } |
317 | 316 | |
318 | 317 | public function hasSchema(): bool |
@@ -365,11 +364,10 @@ discard block |
||
365 | 364 | { |
366 | 365 | return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper); |
367 | 366 | } |
368 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
367 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
369 | 368 | { |
370 | 369 | return ($args[0] ?? false) ? |
371 | - $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : |
|
372 | - $this->table($method, $args[1] ?? false); |
|
370 | + $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false); |
|
373 | 371 | } |
374 | 372 | public function findRelation(string $start, string $end): array |
375 | 373 | { |
@@ -405,12 +403,12 @@ discard block |
||
405 | 403 | $relations[$t] = $w; |
406 | 404 | } |
407 | 405 | if (!isset($schema[$name])) { |
408 | - $schema[$name] = [ 'edges' => [] ]; |
|
406 | + $schema[$name] = ['edges' => []]; |
|
409 | 407 | } |
410 | 408 | foreach ($relations as $t => $w) { |
411 | 409 | $schema[$name]['edges'][$t] = $w; |
412 | 410 | if (!isset($schema[$t])) { |
413 | - $schema[$t] = [ 'edges' => [] ]; |
|
411 | + $schema[$t] = ['edges' => []]; |
|
414 | 412 | } |
415 | 413 | $schema[$t]['edges'][$name] = $w; |
416 | 414 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | |
17 | 17 | public function __construct( |
18 | 18 | DBInterface $db, |
19 | - Table|string $table, |
|
19 | + Table | string $table, |
|
20 | 20 | bool $findRelations = false, |
21 | 21 | ?MapperInterface $mapper = null |
22 | 22 | ) { |