@@ -63,19 +63,19 @@ discard block |
||
| 63 | 63 | ]; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
| 67 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
| 68 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
| 69 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
| 70 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? |
|
| 71 | - trim((string)$temp['path'], '/') : null; |
|
| 72 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
| 73 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
| 74 | - parse_str((string)$temp['query'], $connection['opts']); |
|
| 66 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
| 67 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
| 68 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
| 69 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
| 70 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? |
|
| 71 | + trim((string) $temp['path'], '/') : null; |
|
| 72 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
| 73 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
| 74 | + parse_str((string) $temp['query'], $connection['opts']); |
|
| 75 | 75 | } |
| 76 | 76 | // create the driver |
| 77 | 77 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
| 78 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
| 78 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
| 79 | 79 | if (!class_exists($tmp)) { |
| 80 | 80 | throw new DBException('Unknown DB backend'); |
| 81 | 81 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $new = ''; |
| 114 | 114 | $par = array_values($par); |
| 115 | 115 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
| 116 | - $par = [ $par ]; |
|
| 116 | + $par = [$par]; |
|
| 117 | 117 | } |
| 118 | 118 | $parts = explode('??', $sql); |
| 119 | 119 | $index = 0; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | $index += count($tmp) - 1; |
| 124 | 124 | if (isset($par[$index])) { |
| 125 | 125 | if (!is_array($par[$index])) { |
| 126 | - $par[$index] = [ $par[$index] ]; |
|
| 126 | + $par[$index] = [$par[$index]]; |
|
| 127 | 127 | } |
| 128 | 128 | $params = $par[$index]; |
| 129 | 129 | array_splice($par, $index, 1, $params); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $new .= implode(',', array_fill(0, count($params), '?')); |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | - return [ $new, $par ]; |
|
| 134 | + return [$new, $par]; |
|
| 135 | 135 | } |
| 136 | 136 | /** |
| 137 | 137 | * Run a query (prepare & execute). |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | ): Collection { |
| 181 | 181 | $coll = Collection::from($this->query($sql, $par, $buff)); |
| 182 | 182 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
| 183 | - $coll->map(function ($v) use ($keys) { |
|
| 183 | + $coll->map(function($v) use ($keys) { |
|
| 184 | 184 | $new = []; |
| 185 | 185 | foreach ($v as $k => $vv) { |
| 186 | 186 | $new[call_user_func($keys, $k)] = $vv; |
@@ -189,18 +189,18 @@ discard block |
||
| 189 | 189 | }); |
| 190 | 190 | } |
| 191 | 191 | if ($key !== null) { |
| 192 | - $coll->mapKey(function ($v) use ($key) { |
|
| 192 | + $coll->mapKey(function($v) use ($key) { |
|
| 193 | 193 | return $v[$key]; |
| 194 | 194 | }); |
| 195 | 195 | } |
| 196 | 196 | if ($skip) { |
| 197 | - $coll->map(function ($v) use ($key) { |
|
| 197 | + $coll->map(function($v) use ($key) { |
|
| 198 | 198 | unset($v[$key]); |
| 199 | 199 | return $v; |
| 200 | 200 | }); |
| 201 | 201 | } |
| 202 | 202 | if ($opti) { |
| 203 | - $coll->map(function ($v) { |
|
| 203 | + $coll->map(function($v) { |
|
| 204 | 204 | return count($v) === 1 ? current($v) : $v; |
| 205 | 205 | }); |
| 206 | 206 | } |
@@ -309,8 +309,7 @@ discard block |
||
| 309 | 309 | public function definition(string $table, bool $detectRelations = true) : Table |
| 310 | 310 | { |
| 311 | 311 | return isset($this->schema) ? |
| 312 | - $this->schema->getTable($table) : |
|
| 313 | - $this->driver->table($table, $detectRelations); |
|
| 312 | + $this->schema->getTable($table) : $this->driver->table($table, $detectRelations); |
|
| 314 | 313 | } |
| 315 | 314 | |
| 316 | 315 | public function hasSchema(): bool |
@@ -359,11 +358,10 @@ discard block |
||
| 359 | 358 | { |
| 360 | 359 | return new TableQueryMapped($this, $this->definition($table), $findRelations); |
| 361 | 360 | } |
| 362 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
| 361 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
| 363 | 362 | { |
| 364 | 363 | return ($args[0] ?? false) ? |
| 365 | - $this->tableMapped($method, $args[1] ?? false) : |
|
| 366 | - $this->table($method, $args[1] ?? false); |
|
| 364 | + $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false); |
|
| 367 | 365 | } |
| 368 | 366 | public function findRelation(string $start, string $end): array |
| 369 | 367 | { |
@@ -399,12 +397,12 @@ discard block |
||
| 399 | 397 | $relations[$t] = $w; |
| 400 | 398 | } |
| 401 | 399 | if (!isset($schema[$name])) { |
| 402 | - $schema[$name] = [ 'edges' => [] ]; |
|
| 400 | + $schema[$name] = ['edges' => []]; |
|
| 403 | 401 | } |
| 404 | 402 | foreach ($relations as $t => $w) { |
| 405 | 403 | $schema[$name]['edges'][$t] = $w; |
| 406 | 404 | if (!isset($schema[$t])) { |
| 407 | - $schema[$t] = [ 'edges' => [] ]; |
|
| 405 | + $schema[$t] = ['edges' => []]; |
|
| 408 | 406 | } |
| 409 | 407 | $schema[$t]['edges'][$name] = $w; |
| 410 | 408 | } |