@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $instance->setNullable($data['nullable']); |
43 | 43 | } |
44 | 44 | if (isset($data['notnull'])) { |
45 | - $instance->setNullable(!((int)$data['notnull'])); |
|
45 | + $instance->setNullable(!((int) $data['notnull'])); |
|
46 | 46 | } |
47 | 47 | if (isset($data['Default'])) { |
48 | 48 | $instance->setDefault($data['Default']); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $instance->setLength($data['length']); |
58 | 58 | } |
59 | 59 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
60 | - $temp = array_map(function ($v) { |
|
60 | + $temp = array_map(function($v) { |
|
61 | 61 | return str_replace("''", "'", $v); |
62 | 62 | }, explode("','", substr($instance->getType(), 6, -2))); |
63 | 63 | $instance->setValues($temp); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $instance->setDefault(null); |
87 | 87 | } |
88 | 88 | } |
89 | - if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int)$data['CHAR_LENGTH']) { |
|
89 | + if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int) $data['CHAR_LENGTH']) { |
|
90 | 90 | $instance->setLength($data['CHAR_LENGTH']); |
91 | 91 | } |
92 | 92 | return $instance; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | } |
184 | 184 | public function getLength(): int |
185 | 185 | { |
186 | - return (int)$this->length; |
|
186 | + return (int) $this->length; |
|
187 | 187 | } |
188 | 188 | public function setLength(int $length): static |
189 | 189 | { |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $table = $temp[1]; |
30 | 30 | } |
31 | 31 | |
32 | - if (isset($tables[$schema . '.' . $table])) { |
|
33 | - return $tables[$schema . '.' . $table]; |
|
32 | + if (isset($tables[$schema.'.'.$table])) { |
|
33 | + return $tables[$schema.'.'.$table]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | static $relationsT = null; |
@@ -53,18 +53,18 @@ discard block |
||
53 | 53 | ] |
54 | 54 | ) |
55 | 55 | ); |
56 | - $relationsT['main.' . $row['table']][] = $row; |
|
57 | - $relationsR['main.' . $row['referenced_table']][] = $row; |
|
56 | + $relationsT['main.'.$row['table']][] = $row; |
|
57 | + $relationsR['main.'.$row['referenced_table']][] = $row; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | 62 | $columns = Collection::from($this |
63 | 63 | ->query("PRAGMA table_info(".$table.")")) |
64 | - ->mapKey(function ($v) { |
|
64 | + ->mapKey(function($v) { |
|
65 | 65 | return $v['name']; |
66 | 66 | }) |
67 | - ->map(function ($v) { |
|
67 | + ->map(function($v) { |
|
68 | 68 | $v['length'] = null; |
69 | 69 | if (!isset($v['type'])) { |
70 | 70 | return $v; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | default: |
75 | 75 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
76 | 76 | // extract length from varchar |
77 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
77 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
78 | 78 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
79 | 79 | } |
80 | 80 | break; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | }) |
84 | 84 | ->toArray(); |
85 | 85 | if (!count($columns)) { |
86 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
86 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
87 | 87 | } |
88 | 88 | $primary = []; |
89 | 89 | foreach ($columns as $column) { |
90 | - if ((int)$column['pk']) { |
|
90 | + if ((int) $column['pk']) { |
|
91 | 91 | $primary[] = $column['name']; |
92 | 92 | } |
93 | 93 | } |
94 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
94 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
95 | 95 | ->addColumns($columns) |
96 | 96 | ->setPrimaryKey($primary) |
97 | 97 | ->setComment(''); |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | // assuming current table is on the "one" end having "many" records in the referencing table |
102 | 102 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
103 | 103 | $relations = []; |
104 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) { |
|
105 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table']; |
|
104 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) { |
|
105 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table']; |
|
106 | 106 | $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from']; |
107 | 107 | } |
108 | 108 | foreach ($relations as $data) { |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | $usedcol = []; |
118 | 118 | if (count($columns)) { |
119 | 119 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
120 | - ->filter(function ($v) use ($columns) { |
|
120 | + ->filter(function($v) use ($columns) { |
|
121 | 121 | return in_array($v['from'], $columns); |
122 | 122 | }) as $relation |
123 | 123 | ) { |
124 | - $foreign[$relation['constraint_name']]['table'] = 'main.' . |
|
124 | + $foreign[$relation['constraint_name']]['table'] = 'main.'. |
|
125 | 125 | $relation['referenced_table']; |
126 | 126 | $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
127 | 127 | $usedcol[] = $relation['from']; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $definition->getName() == $relname || |
141 | 141 | $definition->getColumn($relname) |
142 | 142 | ) { |
143 | - $relname = $orig . '_' . (++ $cntr); |
|
143 | + $relname = $orig.'_'.(++$cntr); |
|
144 | 144 | } |
145 | 145 | $definition->addRelation( |
146 | 146 | new TableRelation( |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $definition->getName() == $relname || |
165 | 165 | $definition->getColumn($relname) |
166 | 166 | ) { |
167 | - $relname = $orig . '_' . (++ $cntr); |
|
167 | + $relname = $orig.'_'.(++$cntr); |
|
168 | 168 | } |
169 | 169 | $definition->addRelation( |
170 | 170 | new TableRelation( |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | // assuming current table is linked to "one" record in the referenced table |
181 | 181 | // resulting in a "belongsTo" relationship |
182 | 182 | $relations = []; |
183 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
184 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table']; |
|
183 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
184 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table']; |
|
185 | 185 | $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
186 | 186 | } |
187 | 187 | foreach ($relations as $name => $data) { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $definition->getName() == $relname || |
197 | 197 | $definition->getColumn($relname) |
198 | 198 | ) { |
199 | - $relname = $orig . '_' . (++ $cntr); |
|
199 | + $relname = $orig.'_'.(++$cntr); |
|
200 | 200 | } |
201 | 201 | $definition->addRelation( |
202 | 202 | new TableRelation( |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | "SELECT tbl_name |
218 | 218 | FROM sqlite_schema |
219 | 219 | WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';", |
220 | - [ 'table', 'view' ] |
|
220 | + ['table', 'view'] |
|
221 | 221 | )) |
222 | - ->mapKey(function ($v) { |
|
222 | + ->mapKey(function($v) { |
|
223 | 223 | return strtolower($v['tbl_name']); |
224 | 224 | }) |
225 | 225 | ->pluck('tbl_name') |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase(); |
229 | 229 | } |
230 | 230 | foreach (array_keys($tables) as $k) { |
231 | - $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k]; |
|
231 | + $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k]; |
|
232 | 232 | } |
233 | 233 | return $tables; |
234 | 234 | } |
@@ -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 | ) { |