@@ -67,8 +67,8 @@ |
||
67 | 67 | } |
68 | 68 | public function next(): void |
69 | 69 | { |
70 | - $this->fetched ++; |
|
71 | - $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT)?:null; |
|
70 | + $this->fetched++; |
|
71 | + $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT) ?: null; |
|
72 | 72 | } |
73 | 73 | public function valid(): bool |
74 | 74 | { |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | * @param array|string $column either a single column name or an array of column names |
80 | 80 | * @return static |
81 | 81 | */ |
82 | - public function setPrimaryKey(array|string $column): static |
|
82 | + public function setPrimaryKey(array | string $column): static |
|
83 | 83 | { |
84 | 84 | if (!is_array($column)) { |
85 | - $column = [ $column ]; |
|
85 | + $column = [$column]; |
|
86 | 86 | } |
87 | 87 | $this->data['primary'] = array_values($column); |
88 | 88 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getFullName(): string |
111 | 111 | { |
112 | - return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name']; |
|
112 | + return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name']; |
|
113 | 113 | } |
114 | 114 | /** |
115 | 115 | * Get a column definition |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | public function hasOne( |
157 | 157 | Table $toTable, |
158 | 158 | string $name = null, |
159 | - string|array|null $toTableColumn = null, |
|
159 | + string | array | null $toTableColumn = null, |
|
160 | 160 | string $sql = null, |
161 | 161 | array $par = [] |
162 | 162 | ) : static { |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | if (!isset($name)) { |
187 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
187 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
188 | 188 | } |
189 | 189 | $this->addRelation(new TableRelation( |
190 | 190 | $name, |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | public function hasMany( |
211 | 211 | Table $toTable, |
212 | 212 | string $name = null, |
213 | - string|array|null $toTableColumn = null, |
|
213 | + string | array | null $toTableColumn = null, |
|
214 | 214 | ?string $sql = null, |
215 | 215 | array $par = [] |
216 | 216 | ): static { |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | public function belongsTo( |
265 | 265 | Table $toTable, |
266 | 266 | string $name = null, |
267 | - string|array|null $localColumn = null, |
|
267 | + string | array | null $localColumn = null, |
|
268 | 268 | ?string $sql = null, |
269 | 269 | array $par = [] |
270 | 270 | ): static { |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | Table $toTable, |
320 | 320 | Table $pivot, |
321 | 321 | ?string $name = null, |
322 | - string|array|null $toTableColumn = null, |
|
323 | - string|array|null $localColumn = null |
|
322 | + string | array | null $toTableColumn = null, |
|
323 | + string | array | null $localColumn = null |
|
324 | 324 | ): static { |
325 | 325 | $pivotColumns = $pivot->getColumns(); |
326 | 326 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $instance->setLength($data['length']); |
52 | 52 | } |
53 | 53 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
54 | - $temp = array_map(function ($v) { |
|
54 | + $temp = array_map(function($v) { |
|
55 | 55 | return str_replace("''", "'", $v); |
56 | 56 | }, explode("','", substr($instance->getType(), 6, -2))); |
57 | 57 | $instance->setValues($temp); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | public function getLength(): int |
171 | 171 | { |
172 | - return (int)$this->length; |
|
172 | + return (int) $this->length; |
|
173 | 173 | } |
174 | 174 | public function setLength(int $length): static |
175 | 175 | { |
@@ -124,7 +124,7 @@ |
||
124 | 124 | $this->btype = 'enum'; |
125 | 125 | } elseif (strpos($type, 'json') !== false) { |
126 | 126 | $this->btype = 'json'; |
127 | - } elseif (strpos($type, 'text') !== false || strpos($type, 'char') !== false) { |
|
127 | + } elseif (strpos($type, 'text') !== false || strpos($type, 'char') !== false) { |
|
128 | 128 | $this->btype = 'text'; |
129 | 129 | } elseif (strpos($type, 'int') !== false || strpos($type, 'bit') !== false) { |
130 | 130 | $this->btype = 'int'; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | protected static array $mappers = []; |
15 | 15 | protected MapperInterface $mapper; |
16 | 16 | |
17 | - public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false) |
|
17 | + public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false) |
|
18 | 18 | { |
19 | 19 | parent::__construct($db, $table, $findRelations); |
20 | 20 | if (!isset(static::$mappers[spl_object_hash($db)])) { |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function collection(TableQueryIterator $iterator, Table $definition) : Collection |
53 | 53 | { |
54 | 54 | return Collection::from($iterator) |
55 | - ->map(function ($v) use ($definition) { |
|
55 | + ->map(function($v) use ($definition) { |
|
56 | 56 | return $this->entity($definition, $v); |
57 | 57 | }); |
58 | 58 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $definition = $entity->definition(); |
137 | 137 | foreach ($definition->getColumns() as $column) { |
138 | 138 | if (!array_key_exists($column, $data)) { |
139 | - $entity->__lazyProperty($column, function () use ($definition, $primary, $column) { |
|
139 | + $entity->__lazyProperty($column, function() use ($definition, $primary, $column) { |
|
140 | 140 | $query = $this->db->table($definition->getFullName()); |
141 | 141 | foreach ($primary as $k => $v) { |
142 | 142 | $query->filter($k, $v); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | $name, |
151 | 151 | array_key_exists($name, $data) && isset($data[$name]) ? |
152 | 152 | ($relation->many ? |
153 | - array_map(function ($v) use ($relation) { |
|
153 | + array_map(function($v) use ($relation) { |
|
154 | 154 | return $this->entity($relation->table, $v); |
155 | 155 | }, $data[$name]) : |
156 | 156 | $this->entity($relation->table, $data[$name]) |
157 | 157 | ) : |
158 | - function (array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) { |
|
158 | + function(array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) { |
|
159 | 159 | $query = $this->db->tableMapped($relation->table->getFullName()); |
160 | 160 | if ($columns !== null) { |
161 | 161 | $query->columns($columns); |
162 | 162 | } |
163 | 163 | if ($relation->sql) { |
164 | - $query->where($relation->sql, $relation->par?:[]); |
|
164 | + $query->where($relation->sql, $relation->par ?: []); |
|
165 | 165 | } |
166 | 166 | if ($relation->pivot) { |
167 | 167 | $nm = null; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($definition->getPrimaryKey() as $v) { |
184 | - $query->filter($nm . '.' . $v, $data[$v] ?? null); |
|
184 | + $query->filter($nm.'.'.$v, $data[$v] ?? null); |
|
185 | 185 | } |
186 | 186 | } else { |
187 | 187 | foreach ($relation->keymap as $k => $v) { |
@@ -192,8 +192,7 @@ discard block |
||
192 | 192 | $query->sort($order, $desc); |
193 | 193 | } |
194 | 194 | return $relation->many ? |
195 | - $query->iterator() : |
|
196 | - $query[0]; |
|
195 | + $query->iterator() : $query[0]; |
|
197 | 196 | } |
198 | 197 | ); |
199 | 198 | } |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | $temp = @\pg_query( |
38 | 38 | $this->driver, |
39 | 39 | $sequence ? |
40 | - 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : |
|
41 | - 'SELECT lastval()' |
|
40 | + 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : 'SELECT lastval()' |
|
42 | 41 | ); |
43 | 42 | if ($temp) { |
44 | 43 | $res = \pg_fetch_row($temp); |
@@ -76,8 +75,8 @@ discard block |
||
76 | 75 | } |
77 | 76 | public function next(): void |
78 | 77 | { |
79 | - $this->fetched ++; |
|
80 | - $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC)?:null; |
|
78 | + $this->fetched++; |
|
79 | + $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC) ?: null; |
|
81 | 80 | if (is_array($this->last) && count($this->last)) { |
82 | 81 | $this->cast(); |
83 | 82 | } |
@@ -102,15 +101,15 @@ discard block |
||
102 | 101 | case 'int2': |
103 | 102 | case 'int4': |
104 | 103 | case 'int8': |
105 | - $this->last[$k] = (int)$v; |
|
104 | + $this->last[$k] = (int) $v; |
|
106 | 105 | break; |
107 | 106 | case 'bit': |
108 | 107 | case 'bool': |
109 | - $this->last[$k] = $v !== 'f' && (int)$v ? true : false; |
|
108 | + $this->last[$k] = $v !== 'f' && (int) $v ? true : false; |
|
110 | 109 | break; |
111 | 110 | case 'float4': |
112 | 111 | case 'float8': |
113 | - $this->last[$k] = (float)$v; |
|
112 | + $this->last[$k] = (float) $v; |
|
114 | 113 | case 'money': |
115 | 114 | case 'numeric': |
116 | 115 | // TODO: |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | public function affected() : int |
26 | 26 | { |
27 | - return (int)\oci_num_rows($this->statement); |
|
27 | + return (int) \oci_num_rows($this->statement); |
|
28 | 28 | } |
29 | 29 | public function insertID(string $sequence = null): mixed |
30 | 30 | { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function count(): int |
39 | 39 | { |
40 | - return (int)\oci_num_rows($this->statement); |
|
40 | + return (int) \oci_num_rows($this->statement); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | public function key(): mixed |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | } |
66 | 66 | public function next(): void |
67 | 67 | { |
68 | - $this->fetched ++; |
|
69 | - $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS)?:null; |
|
68 | + $this->fetched++; |
|
69 | + $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC +\OCI_RETURN_NULLS +\OCI_RETURN_LOBS) ?: null; |
|
70 | 70 | if (is_array($this->last) && count($this->last)) { |
71 | 71 | $this->cast(); |
72 | 72 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->types[$v] = \oci_field_type($this->statement, $k + 1); |
83 | 83 | if ($this->types[$v] === 'NUMBER') { |
84 | 84 | $size = \oci_field_size($this->statement, $k + 1); |
85 | - if ((int)(explode(',', $size, 2)[1] ?? '') > 0) { |
|
85 | + if ((int) (explode(',', $size, 2)[1] ?? '') > 0) { |
|
86 | 86 | $this->types[$v] === 'FLOAT'; |
87 | 87 | } |
88 | 88 | } |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | } |
95 | 95 | switch ($this->types[$k]) { |
96 | 96 | case 'NUMBER': |
97 | - $this->last[$k] = (int)$v; |
|
97 | + $this->last[$k] = (int) $v; |
|
98 | 98 | break; |
99 | 99 | case 'FLOAT': |
100 | - $this->last[$k] = (float)$v; |
|
100 | + $this->last[$k] = (float) $v; |
|
101 | 101 | break; |
102 | 102 | } |
103 | 103 | } |
@@ -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 | } |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function getSchema(bool $asPlainArray = true): array |
326 | 326 | { |
327 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
327 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
328 | 328 | return [ |
329 | 329 | 'name' => $table->getName(), |
330 | 330 | 'schema' => $table->getSchema(), |
331 | 331 | 'pkey' => $table->getPrimaryKey(), |
332 | 332 | 'comment' => $table->getComment(), |
333 | - 'columns' => array_map(function ($column) { |
|
333 | + 'columns' => array_map(function($column) { |
|
334 | 334 | return [ |
335 | 335 | 'name' => $column->getName(), |
336 | 336 | 'type' => $column->getType(), |
@@ -341,9 +341,9 @@ discard block |
||
341 | 341 | 'nullable' => $column->isNullable() |
342 | 342 | ]; |
343 | 343 | }, $table->getFullColumns()), |
344 | - 'relations' => array_map(function ($rel) { |
|
344 | + 'relations' => array_map(function($rel) { |
|
345 | 345 | $relation = clone $rel; |
346 | - $relation = (array)$relation; |
|
346 | + $relation = (array) $relation; |
|
347 | 347 | $relation['table'] = $rel->table->getName(); |
348 | 348 | if ($rel->pivot) { |
349 | 349 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -405,11 +405,10 @@ discard block |
||
405 | 405 | { |
406 | 406 | return new TableQueryMapped($this, $this->definition($table), $findRelations); |
407 | 407 | } |
408 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
408 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
409 | 409 | { |
410 | 410 | return ($args[0] ?? false) ? |
411 | - $this->tableMapped($method, $args[1] ?? false) : |
|
412 | - $this->table($method, $args[1] ?? false); |
|
411 | + $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false); |
|
413 | 412 | } |
414 | 413 | public function findRelation(string $start, string $end): array |
415 | 414 | { |
@@ -442,12 +441,12 @@ discard block |
||
442 | 441 | $relations[$t] = $w; |
443 | 442 | } |
444 | 443 | if (!isset($schema[$name])) { |
445 | - $schema[$name] = [ 'edges' => [] ]; |
|
444 | + $schema[$name] = ['edges' => []]; |
|
446 | 445 | } |
447 | 446 | foreach ($relations as $t => $w) { |
448 | 447 | $schema[$name]['edges'][$t] = $w; |
449 | 448 | if (!isset($schema[$t])) { |
450 | - $schema[$t] = [ 'edges' => [] ]; |
|
449 | + $schema[$t] = ['edges' => []]; |
|
451 | 450 | } |
452 | 451 | $schema[$t]['edges'][$name] = $w; |
453 | 452 | } |
@@ -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; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | (kc.table_schema = ? OR ct.table_schema = ?) AND |
62 | 62 | kc.table_name IS NOT NULL AND |
63 | 63 | kc.position_in_unique_constraint IS NOT NULL", |
64 | - [ $catalog, $main, $main ] |
|
64 | + [$catalog, $main, $main] |
|
65 | 65 | ) |
66 | 66 | )->toArray(); |
67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | if ($row['referenced_table_schema'] !== $main) { |
72 | 72 | $additional[] = $row['referenced_table_schema']; |
73 | 73 | } |
74 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
75 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
74 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
75 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
76 | 76 | } |
77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
78 | 78 | $col = Collection::from( |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | (kc.table_schema = ? AND ct.table_schema = ?) AND |
98 | 98 | kc.table_name IS NOT NULL AND |
99 | 99 | kc.position_in_unique_constraint IS NOT NULL", |
100 | - [ $catalog, $s, $s ] |
|
100 | + [$catalog, $s, $s] |
|
101 | 101 | ) |
102 | 102 | )->toArray(); |
103 | 103 | foreach ($col as $row) { |
104 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
105 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
104 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
105 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | $columns = Collection::from($this |
111 | 111 | ->query( |
112 | 112 | "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
113 | - [ $table, $schema, $catalog ] |
|
113 | + [$table, $schema, $catalog] |
|
114 | 114 | )) |
115 | - ->mapKey(function ($v) { |
|
115 | + ->mapKey(function($v) { |
|
116 | 116 | return $v['column_name']; |
117 | 117 | }) |
118 | - ->map(function ($v) { |
|
118 | + ->map(function($v) { |
|
119 | 119 | $v['length'] = null; |
120 | 120 | if (!isset($v['data_type'])) { |
121 | 121 | return $v; |
@@ -123,20 +123,20 @@ discard block |
||
123 | 123 | switch ($v['data_type']) { |
124 | 124 | case 'character': |
125 | 125 | case 'character varying': |
126 | - $v['length'] = (int)$v['character_maximum_length']; |
|
126 | + $v['length'] = (int) $v['character_maximum_length']; |
|
127 | 127 | break; |
128 | 128 | } |
129 | 129 | return $v; |
130 | 130 | }) |
131 | 131 | ->toArray(); |
132 | 132 | if (!count($columns)) { |
133 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
133 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
134 | 134 | } |
135 | 135 | $pkname = Collection::from($this |
136 | 136 | ->query( |
137 | 137 | "SELECT constraint_name FROM information_schema.table_constraints |
138 | 138 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
139 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
139 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
140 | 140 | )) |
141 | 141 | ->pluck('constraint_name') |
142 | 142 | ->value(); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | ->query( |
147 | 147 | "SELECT column_name FROM information_schema.constraint_column_usage |
148 | 148 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
149 | - [ $table, $pkname, $schema, $catalog ] |
|
149 | + [$table, $pkname, $schema, $catalog] |
|
150 | 150 | )) |
151 | 151 | ->pluck('column_name') |
152 | 152 | ->toArray(); |
153 | 153 | } |
154 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
154 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
155 | 155 | ->addColumns($columns) |
156 | 156 | ->setPrimaryKey($primary) |
157 | 157 | ->setComment(''); |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | // assuming current table is on the "one" end having "many" records in the referencing table |
162 | 162 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
163 | 163 | $relations = []; |
164 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
165 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . $relation['table_name']; |
|
164 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
165 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.$relation['table_name']; |
|
166 | 166 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
167 | 167 | $relation['column_name']; |
168 | 168 | } |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | $usedcol = []; |
179 | 179 | if (count($columns)) { |
180 | 180 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
181 | - ->filter(function ($v) use ($columns) { |
|
181 | + ->filter(function($v) use ($columns) { |
|
182 | 182 | return in_array($v['column_name'], $columns); |
183 | 183 | }) as $relation |
184 | 184 | ) { |
185 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
185 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
186 | 186 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
187 | 187 | $relation['referenced_column_name']; |
188 | 188 | $usedcol[] = $relation['column_name']; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $definition->getName() == $relname || |
203 | 203 | $definition->getColumn($relname) |
204 | 204 | ) { |
205 | - $relname = $orig . '_' . (++ $cntr); |
|
205 | + $relname = $orig.'_'.(++$cntr); |
|
206 | 206 | } |
207 | 207 | $definition->addRelation( |
208 | 208 | new TableRelation( |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $definition->getName() == $relname || |
228 | 228 | $definition->getColumn($relname) |
229 | 229 | ) { |
230 | - $relname = $orig . '_' . (++ $cntr); |
|
230 | + $relname = $orig.'_'.(++$cntr); |
|
231 | 231 | } |
232 | 232 | $definition->addRelation( |
233 | 233 | new TableRelation( |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | // assuming current table is linked to "one" record in the referenced table |
244 | 244 | // resulting in a "belongsTo" relationship |
245 | 245 | $relations = []; |
246 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
247 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
246 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
247 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
248 | 248 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
249 | 249 | $relation['referenced_column_name']; |
250 | 250 | } |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $definition->getName() == $relname || |
262 | 262 | $definition->getColumn($relname) |
263 | 263 | ) { |
264 | - $relname = $orig . '_' . (++ $cntr); |
|
264 | + $relname = $orig.'_'.(++$cntr); |
|
265 | 265 | } |
266 | 266 | $definition->addRelation( |
267 | 267 | new TableRelation( |
@@ -280,19 +280,19 @@ discard block |
||
280 | 280 | $tables = Collection::from($this |
281 | 281 | ->query( |
282 | 282 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
283 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
283 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
284 | 284 | )) |
285 | - ->mapKey(function ($v) { |
|
285 | + ->mapKey(function($v) { |
|
286 | 286 | return strtolower($v['table_name']); |
287 | 287 | }) |
288 | 288 | ->pluck('table_name') |
289 | - ->map(function ($v) { |
|
289 | + ->map(function($v) { |
|
290 | 290 | return $this->table($v)->toLowerCase(); |
291 | 291 | }) |
292 | 292 | ->toArray(); |
293 | 293 | |
294 | 294 | foreach (array_keys($tables) as $k) { |
295 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
295 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
296 | 296 | } |
297 | 297 | return $tables; |
298 | 298 | } |