@@ -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 | public function hasSchema(): bool |
@@ -323,13 +322,13 @@ discard block |
||
| 323 | 322 | */ |
| 324 | 323 | public function getSchema(bool $asPlainArray = true): array |
| 325 | 324 | { |
| 326 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
| 325 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
| 327 | 326 | return [ |
| 328 | 327 | 'name' => $table->getName(), |
| 329 | 328 | 'schema' => $table->getSchema(), |
| 330 | 329 | 'pkey' => $table->getPrimaryKey(), |
| 331 | 330 | 'comment' => $table->getComment(), |
| 332 | - 'columns' => array_map(function ($column) { |
|
| 331 | + 'columns' => array_map(function($column) { |
|
| 333 | 332 | return [ |
| 334 | 333 | 'name' => $column->getName(), |
| 335 | 334 | 'type' => $column->getType(), |
@@ -340,9 +339,9 @@ discard block |
||
| 340 | 339 | 'nullable' => $column->isNullable() |
| 341 | 340 | ]; |
| 342 | 341 | }, $table->getFullColumns()), |
| 343 | - 'relations' => array_map(function ($rel) { |
|
| 342 | + 'relations' => array_map(function($rel) { |
|
| 344 | 343 | $relation = clone $rel; |
| 345 | - $relation = (array)$relation; |
|
| 344 | + $relation = (array) $relation; |
|
| 346 | 345 | $relation['table'] = $rel->table->getName(); |
| 347 | 346 | if ($rel->pivot) { |
| 348 | 347 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -404,11 +403,10 @@ discard block |
||
| 404 | 403 | { |
| 405 | 404 | return new TableQueryMapped($this, $this->definition($table), $findRelations); |
| 406 | 405 | } |
| 407 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
| 406 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
| 408 | 407 | { |
| 409 | 408 | return ($args[0] ?? false) ? |
| 410 | - $this->tableMapped($method, $args[1] ?? false) : |
|
| 411 | - $this->table($method, $args[1] ?? false); |
|
| 409 | + $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false); |
|
| 412 | 410 | } |
| 413 | 411 | public function findRelation(string $start, string $end): array |
| 414 | 412 | { |
@@ -441,12 +439,12 @@ discard block |
||
| 441 | 439 | $relations[$t] = $w; |
| 442 | 440 | } |
| 443 | 441 | if (!isset($schema[$name])) { |
| 444 | - $schema[$name] = [ 'edges' => [] ]; |
|
| 442 | + $schema[$name] = ['edges' => []]; |
|
| 445 | 443 | } |
| 446 | 444 | foreach ($relations as $t => $w) { |
| 447 | 445 | $schema[$name]['edges'][$t] = $w; |
| 448 | 446 | if (!isset($schema[$t])) { |
| 449 | - $schema[$t] = [ 'edges' => [] ]; |
|
| 447 | + $schema[$t] = ['edges' => []]; |
|
| 450 | 448 | } |
| 451 | 449 | $schema[$t]['edges'][$name] = $w; |
| 452 | 450 | } |