Completed
Push — master ( 4a845b...03e094 )
by Ivan
13:19
created
src/DB.php 1 patch
Spacing   +27 added lines, -29 removed lines patch added patch discarded remove patch
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
                 ];
75 75
             }
76 76
         }
77
-        $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null;
78
-        $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null;
79
-        $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null;
80
-        $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null;
81
-        $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ?
82
-            trim((string)$temp['path'], '/') : null;
83
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
84
-        if (isset($temp['query']) && strlen((string)$temp['query'])) {
85
-            parse_str((string)$temp['query'], $connection['opts']);
77
+        $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null;
78
+        $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null;
79
+        $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null;
80
+        $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null;
81
+        $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ?
82
+            trim((string) $temp['path'], '/') : null;
83
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
84
+        if (isset($temp['query']) && strlen((string) $temp['query'])) {
85
+            parse_str((string) $temp['query'], $connection['opts']);
86 86
         }
87 87
         // create the driver
88 88
         $connection['type'] = $aliases[$connection['type']] ?? $connection['type'];
89
-        $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver';
89
+        $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver';
90 90
         if (!class_exists($tmp)) {
91 91
             throw new DBException('Unknown DB backend');
92 92
         }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         $new = '';
125 125
         $par = array_values($par);
126 126
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
127
-            $par = [ $par ];
127
+            $par = [$par];
128 128
         }
129 129
         $parts = explode('??', $sql);
130 130
         $index = 0;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
             $index += count($tmp) - 1;
135 135
             if (isset($par[$index])) {
136 136
                 if (!is_array($par[$index])) {
137
-                    $par[$index] = [ $par[$index] ];
137
+                    $par[$index] = [$par[$index]];
138 138
                 }
139 139
                 $params = $par[$index];
140 140
                 array_splice($par, $index, 1, $params);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                 $new .= implode(',', array_fill(0, count($params), '?'));
143 143
             }
144 144
         }
145
-        return [ $new, $par ];
145
+        return [$new, $par];
146 146
     }
147 147
     /**
148 148
      * Run a query (prepare & execute).
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     ): Collection {
192 192
         $coll = Collection::from($this->query($sql, $par, $buff));
193 193
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
194
-            $coll->map(function ($v) use ($keys) {
194
+            $coll->map(function($v) use ($keys) {
195 195
                 $new = [];
196 196
                 foreach ($v as $k => $vv) {
197 197
                     $new[call_user_func($keys, $k)] = $vv;
@@ -200,18 +200,18 @@  discard block
 block discarded – undo
200 200
             });
201 201
         }
202 202
         if ($key !== null) {
203
-            $coll->mapKey(function ($v) use ($key): int|string {
203
+            $coll->mapKey(function($v) use ($key): int | string {
204 204
                 return $v[$key];
205 205
             });
206 206
         }
207 207
         if ($skip) {
208
-            $coll->map(function ($v) use ($key) {
208
+            $coll->map(function($v) use ($key) {
209 209
                 unset($v[$key]);
210 210
                 return $v;
211 211
             });
212 212
         }
213 213
         if ($opti) {
214
-            $coll->map(function ($v) {
214
+            $coll->map(function($v) {
215 215
                 return count($v) === 1 ? current($v) : $v;
216 216
             });
217 217
         }
@@ -328,8 +328,7 @@  discard block
 block discarded – undo
328 328
     public function definition(string $table, bool $detectRelations = true) : Table
329 329
     {
330 330
         return isset($this->schema) ?
331
-            $this->schema->getTable($table) :
332
-            $this->driver->table($table, $detectRelations);
331
+            $this->schema->getTable($table) : $this->driver->table($table, $detectRelations);
333 332
     }
334 333
 
335 334
     public function hasSchema(): bool
@@ -439,11 +438,11 @@  discard block
 block discarded – undo
439 438
      * @param class-string<T>|Table|string $table
440 439
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
441 440
      */
442
-    public function getMapper(Table|string $table): MapperInterface
441
+    public function getMapper(Table | string $table): MapperInterface
443 442
     {
444 443
         if (is_string($table)) {
445
-            if (isset($this->mappers['::' . $table])) {
446
-                return $this->mappers['::' . $table];
444
+            if (isset($this->mappers['::'.$table])) {
445
+                return $this->mappers['::'.$table];
447 446
             }
448 447
             $table = $this->definition($table);
449 448
         }
@@ -452,14 +451,14 @@  discard block
 block discarded – undo
452 451
         }
453 452
         return $this->mappers[$table->getFullName()] = new Mapper($this, $table);
454 453
     }
455
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static
454
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static
456 455
     {
457 456
         if (is_string($table)) {
458 457
             $table = $this->definition($table);
459 458
         }
460 459
         $this->mappers[$table->getFullName()] = $mapper;
461 460
         if (isset($class)) {
462
-            $this->mappers['::' . $class] = $mapper;
461
+            $this->mappers['::'.$class] = $mapper;
463 462
         }
464 463
         return $this;
465 464
     }
@@ -470,11 +469,10 @@  discard block
 block discarded – undo
470 469
     ): TableQueryMapped {
471 470
         return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper);
472 471
     }
473
-    public function __call(string $method, array $args): TableQuery|TableQueryMapped
472
+    public function __call(string $method, array $args): TableQuery | TableQueryMapped
474 473
     {
475 474
         return ($args[0] ?? false) ?
476
-            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) :
477
-            $this->table($method, $args[1] ?? false);
475
+            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false);
478 476
     }
479 477
     public function findRelation(string $start, string $end): array
480 478
     {
@@ -510,12 +508,12 @@  discard block
 block discarded – undo
510 508
                     $relations[$t] = $w;
511 509
                 }
512 510
                 if (!isset($schema[$name])) {
513
-                    $schema[$name] = [ 'edges' => [] ];
511
+                    $schema[$name] = ['edges' => []];
514 512
                 }
515 513
                 foreach ($relations as $t => $w) {
516 514
                     $schema[$name]['edges'][$t] = $w;
517 515
                     if (!isset($schema[$t])) {
518
-                        $schema[$t] = [ 'edges' => [] ];
516
+                        $schema[$t] = ['edges' => []];
519 517
                     }
520 518
                     $schema[$t]['edges'][$name] = $w;
521 519
                 }
Please login to merge, or discard this patch.
src/schema/MapperInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,12 +58,12 @@
 block discarded – undo
58 58
      * @param array|T $entity
59 59
      * @return bool
60 60
      */
61
-    public function deleted(array|object $entity): bool;
61
+    public function deleted(array | object $entity): bool;
62 62
     /**
63 63
      * @param array|T $entity
64 64
      * @return bool
65 65
      */
66
-    public function exists(array|object $entity): bool;
66
+    public function exists(array | object $entity): bool;
67 67
     /**
68 68
      * @return array<int,T>
69 69
      */
Please login to merge, or discard this patch.
src/schema/Mapper.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -539,7 +539,7 @@
 block discarded – undo
539 539
                                         (isset($value) && is_array($value) && !in_array($e, $value, true)) ||
540 540
                                         (($value instanceof Collection) && !$value->contains($e))
541 541
                                     )
542
-                                 ) {
542
+                                    ) {
543 543
                                     $mapper->delete($e, true);
544 544
                                 }
545 545
                             }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @param class-string<T> $clss
28 28
      * @return void
29 29
      */
30
-    public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class)
30
+    public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class)
31 31
     {
32 32
         $this->db = $db;
33 33
         if (!$table) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         $temp = [];
64 64
         foreach ($this->table->getPrimaryKey() as $column) {
65 65
             try {
66
-                $temp[(string)$column] = $entity->{$column} ?? null;
66
+                $temp[(string) $column] = $entity->{$column} ?? null;
67 67
                 /** @phpstan-ignore-next-line */
68 68
             } catch (\Throwable $ignore) {
69 69
             }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
         // BEG: ugly hack to get relations changed directly on the object (not hydrated)
95 95
         $hack = [];
96
-        foreach ((array)$entity as $k => $v) {
96
+        foreach ((array) $entity as $k => $v) {
97 97
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
98 98
         }
99 99
         $hack = $hack['changed'] ?? [];
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         foreach ($columns as $column) {
105 105
             try {
106 106
                 if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) {
107
-                    $temp[(string)$column] = $entity->{$column};
107
+                    $temp[(string) $column] = $entity->{$column};
108 108
                 }
109 109
             } catch (\Throwable $ignore) {
110 110
             }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         foreach ($relations as $relation) {
115 115
             try {
116 116
                 if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) {
117
-                    $temp[(string)$relation] = $entity->{$relation};
117
+                    $temp[(string) $relation] = $entity->{$relation};
118 118
                 }
119 119
             } catch (\Throwable $ignore) {
120 120
             }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                         $v = [];
136 136
                     }
137 137
                     if ($v instanceof Entity) {
138
-                        $v = [ $v ];
138
+                        $v = [$v];
139 139
                     }
140 140
                     if (is_array($v)) {
141 141
                         foreach ($v as $kk => $vv) {
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
         $temp = [];
185 185
         foreach ($this->table->getColumns() as $column) {
186 186
             if (array_key_exists($column, $data)) {
187
-                $temp[(string)$column] = $data[$column];
187
+                $temp[(string) $column] = $data[$column];
188 188
             } else {
189 189
                 if ($empty) {
190
-                    $temp[(string)$column] = null;
190
+                    $temp[(string) $column] = null;
191 191
                 }
192 192
             }
193 193
         }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $lazy = [];
216 216
         foreach ($this->table->getColumns() as $column) {
217 217
             if (!array_key_exists($column, $data)) {
218
-                $lazy[$column] = function ($entity) use ($column) {
218
+                $lazy[$column] = function($entity) use ($column) {
219 219
                     $query = $this->db->table($this->table->getFullName());
220 220
                     foreach ($this->id($entity) as $k => $v) {
221 221
                         $query->filter($k, $v);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     {
239 239
         $relations = [];
240 240
         foreach ($this->table->getRelations() as $name => $relation) {
241
-            $relations[$name] = function (
241
+            $relations[$name] = function(
242 242
                 $entity,
243 243
                 bool $queryOnly = false
244 244
             ) use (
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
                         return $this->objects[spl_object_hash($entity)][4][$name] = null;
253 253
                     }
254 254
                     $value = $relation->many ?
255
-                        Collection::from(array_map(function ($v) use ($mapper) {
255
+                        Collection::from(array_map(function($v) use ($mapper) {
256 256
                             return $mapper->entity($v);
257 257
                         }, $data[$name]))
258
-                            ->filter(function ($v) use ($mapper) {
258
+                            ->filter(function($v) use ($mapper) {
259 259
                                 return !$mapper->deleted($v);
260 260
                             }) :
261 261
                         ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name]));
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                 }
265 265
                 $query = $this->db->tableMapped($relation->table->getFullName());
266 266
                 if ($relation->sql) {
267
-                    $query->where($relation->sql, $relation->par?:[]);
267
+                    $query->where($relation->sql, $relation->par ?: []);
268 268
                 }
269 269
                 if ($relation->pivot) {
270 270
                     $nm = null;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                     }
286 286
                     $pk = $this->id($entity);
287 287
                     foreach ($pk as $k => $v) {
288
-                        $query->filter($nm . '.' . $k, $v);
288
+                        $query->filter($nm.'.'.$k, $v);
289 289
                     }
290 290
                 } else {
291 291
                     $temp = $this->toArray($entity, array_keys($relation->keymap));
@@ -297,10 +297,9 @@  discard block
 block discarded – undo
297 297
                     return $query;
298 298
                 }
299 299
                 $value = $relation->many ?
300
-                    $query->iterator() :
301
-                    ($query[0] ?? null);
300
+                    $query->iterator() : ($query[0] ?? null);
302 301
                 if ($value instanceof Collection) {
303
-                    $value->filter(function ($v) use ($mapper) {
302
+                    $value->filter(function($v) use ($mapper) {
304 303
                         return !$mapper->deleted($v);
305 304
                     });
306 305
                 } elseif (isset($value) && $mapper->deleted($value)) {
@@ -320,7 +319,7 @@  discard block
 block discarded – undo
320 319
     {
321 320
         // BEG: ugly hack to get changed columns
322 321
         $hack = [];
323
-        foreach ((array)$entity as $k => $v) {
322
+        foreach ((array) $entity as $k => $v) {
324 323
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
325 324
         }
326 325
         $hack = $hack['changed'] ?? [];
@@ -611,7 +610,7 @@  discard block
 block discarded – undo
611 610
             }
612 611
         }
613 612
     }
614
-    public function exists(array|object $entity): bool
613
+    public function exists(array | object $entity): bool
615 614
     {
616 615
         if (is_array($entity)) {
617 616
             $primary = [];
@@ -625,7 +624,7 @@  discard block
 block discarded – undo
625 624
         return isset($this->objects[spl_object_hash($entity)]) &&
626 625
             $this->objects[spl_object_hash($entity)][5] === false;
627 626
     }
628
-    public function deleted(array|object $entity): bool
627
+    public function deleted(array | object $entity): bool
629 628
     {
630 629
         if (is_array($entity)) {
631 630
             $primary = [];
@@ -711,7 +710,7 @@  discard block
 block discarded – undo
711 710
         return array_filter(
712 711
             array_values(
713 712
                 array_map(
714
-                    function ($v) {
713
+                    function($v) {
715 714
                         return $v[5] ? null : ($v[1] ?? null);
716 715
                     },
717 716
                     $this->objects
Please login to merge, or discard this patch.
src/Schema.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     public function getTable(string $table): Table
32 32
     {
33 33
         if (!$this->hasTable($table)) {
34
-            throw new DBException('Invalid table name: ' . $table);
34
+            throw new DBException('Invalid table name: '.$table);
35 35
         }
36 36
         return $this->tables[$table] ??
37 37
             $this->tables[strtoupper($table)] ??
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
     
65 65
     public function toArray(): array
66 66
     {
67
-        return array_map(function ($table) {
67
+        return array_map(function($table) {
68 68
             return [
69 69
                 'name' => $table->getName(),
70 70
                 'schema' => $table->getSchema(),
71 71
                 'pkey' => $table->getPrimaryKey(),
72 72
                 'comment' => $table->getComment(),
73
-                'columns' => array_map(function ($column) {
73
+                'columns' => array_map(function($column) {
74 74
                     return [
75 75
                         'name' => $column->getName(),
76 76
                         'type' => $column->getType(),
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
                         'nullable' => $column->isNullable()
82 82
                     ];
83 83
                 }, $table->getFullColumns()),
84
-                'relations' => array_map(function ($rel) {
84
+                'relations' => array_map(function($rel) {
85 85
                     $relation = clone $rel;
86
-                    $relation = (array)$relation;
86
+                    $relation = (array) $relation;
87 87
                     $relation['table'] = $rel->table->getName();
88 88
                     if ($rel->pivot) {
89 89
                         $relation['pivot'] = $rel->pivot->getName();
Please login to merge, or discard this patch.
src/schema/Entity.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             }
96 96
             $this->cached[$method] = $rslt;
97 97
         } else {
98
-            throw new DBException('Invalid relation name: ' . $method);
98
+            throw new DBException('Invalid relation name: '.$method);
99 99
         }
100 100
         return $this->cached[$method] ?? null;
101 101
     }
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
     protected function relatedQuery(string $name): TableQueryMapped
107 107
     {
108 108
         if (!array_key_exists($name, $this->relations)) {
109
-            throw new DBException('Invalid relation name: ' . $name);
109
+            throw new DBException('Invalid relation name: '.$name);
110 110
         }
111 111
         return call_user_func_array($this->relations[$name], [$this, true]);
112 112
     }
113 113
     protected function relatedRow(string $name): mixed
114 114
     {
115 115
         if (!array_key_exists($name, $this->relations)) {
116
-            throw new DBException('Invalid relation name: ' . $name);
116
+            throw new DBException('Invalid relation name: '.$name);
117 117
         }
118 118
         return call_user_func_array($this->relations[$name], [$this]);
119 119
     }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     protected function relatedRows(string $name): Collection
125 125
     {
126 126
         if (!array_key_exists($name, $this->relations)) {
127
-            throw new DBException('Invalid relation name: ' . $name);
127
+            throw new DBException('Invalid relation name: '.$name);
128 128
         }
129 129
         return call_user_func_array($this->relations[$name], [$this]);
130 130
     }
Please login to merge, or discard this patch.
src/DBInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param class-string<T>|Table|string $table
119 119
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
120 120
      */
121
-    public function getMapper(Table|string $table): MapperInterface;
121
+    public function getMapper(Table | string $table): MapperInterface;
122 122
     /*
123 123
      * @template T of Entity
124 124
      * @param Table|string $table
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @param null|class-string<T> $class
127 127
      * @return static
128 128
      */
129
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static;
129
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static;
130 130
     public function tableMapped(
131 131
         string $table,
132 132
         bool $findRelations = false,
Please login to merge, or discard this patch.
src/driver/mysql/Schema.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
             $table = $temp[1];
28 28
         }
29 29
 
30
-        if (isset($tables[$schema . '.' . $table])) {
31
-            return $tables[$schema . '.' . $table];
30
+        if (isset($tables[$schema.'.'.$table])) {
31
+            return $tables[$schema.'.'.$table];
32 32
         }
33 33
 
34 34
         static $comments = [];
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
             $comments[$schema] = Collection::from(
37 37
                 $this->query(
38 38
                     "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?",
39
-                    [ $schema ]
39
+                    [$schema]
40 40
                 )
41 41
             )
42
-            ->mapKey(function (array $v): string {
42
+            ->mapKey(function(array $v): string {
43 43
                 return $v['TABLE_NAME'];
44 44
             })
45 45
             ->pluck('TABLE_COMMENT')
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                      WHERE
62 62
                         (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND
63 63
                         TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL",
64
-                    [ $main, $main ]
64
+                    [$main, $main]
65 65
                 )
66 66
             )->toArray();
67 67
             foreach ($col as $row) {
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
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(
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
                         WHERE
85 85
                             TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND
86 86
                             TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL",
87
-                        [ $s, $s ]
87
+                        [$s, $s]
88 88
                     )
89 89
                 )->toArray();
90 90
                 foreach ($col as $row) {
91
-                    $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row;
92
-                    $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row;
91
+                    $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row;
92
+                    $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row;
93 93
                 }
94 94
             }
95 95
 
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
         if (!count($columns)) {
100 100
             throw new DBException('Table not found by name');
101 101
         }
102
-        $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema))
102
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
103 103
             ->addColumns(
104 104
                 $columns
105 105
                     ->clone()
106
-                    ->mapKey(function (array $v): string {
106
+                    ->mapKey(function(array $v): string {
107 107
                         return $v['Field'];
108 108
                     })
109
-                    ->map(function (array $v): array {
109
+                    ->map(function(array $v): array {
110 110
                         $v['length'] = null;
111 111
                         if (!isset($v['Type'])) {
112 112
                             return $v;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                             default:
129 129
                                 if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
130 130
                                     // extract length from varchar
131
-                                    $v['length'] = (int)explode(')', explode('(', $type)[1])[0];
131
+                                    $v['length'] = (int) explode(')', explode('(', $type)[1])[0];
132 132
                                     $v['length'] = $v['length'] > 0 ? $v['length'] : null;
133 133
                                 }
134 134
                                 break;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
             ->setPrimaryKey(
141 141
                 $columns
142 142
                     ->clone()
143
-                    ->filter(function (array $v): bool {
143
+                    ->filter(function(array $v): bool {
144 144
                         return $v['Key'] === 'PRI';
145 145
                     })
146 146
                     ->pluck('Field')
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
 
152 152
         if ($detectRelations) {
153 153
             $duplicated = [];
154
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
155
-                $t = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME'];
154
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
155
+                $t = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME'];
156 156
                 $duplicated[$t] = isset($duplicated[$t]);
157 157
             }
158
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
159
-                $t = $relation['TABLE_SCHEMA'] . '.' . $relation['TABLE_NAME'];
158
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
159
+                $t = $relation['TABLE_SCHEMA'].'.'.$relation['TABLE_NAME'];
160 160
                 $duplicated[$t] = isset($duplicated[$t]);
161 161
             }
162 162
             // pivot relations where the current table is referenced
163 163
             // assuming current table is on the "one" end having "many" records in the referencing table
164 164
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
165 165
             $relations = [];
166
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
167
-                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' .
166
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
167
+                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.
168 168
                     $relation['TABLE_NAME'];
169 169
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] =
170 170
                     $relation['COLUMN_NAME'];
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
                 $usedcol = [];
182 182
                 if (count($columns)) {
183 183
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
184
-                        ->filter(function (array $v) use ($columns): bool {
184
+                        ->filter(function(array $v) use ($columns): bool {
185 185
                             return in_array($v['COLUMN_NAME'], $columns);
186 186
                         })
187
-                        ->map(function (array $v): array {
187
+                        ->map(function(array $v): array {
188 188
                             $new = [];
189 189
                             foreach ($v as $kk => $vv) {
190 190
                                 $new[strtoupper($kk)] = $vv;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                             return $new;
193 193
                         }) as $relation
194 194
                     ) {
195
-                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' .
195
+                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.
196 196
                             $relation['REFERENCED_TABLE_NAME'];
197 197
                         $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] =
198 198
                             $relation['REFERENCED_COLUMN_NAME'];
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                     $orig = $relname;
210 210
                     $cntr = 1;
211 211
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
212
-                        $relname = $orig . '_' . (++ $cntr);
212
+                        $relname = $orig.'_'.(++$cntr);
213 213
                     }
214 214
                     $definition->addRelation(
215 215
                         new TableRelation(
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
             // assuming current table is linked to "one" record in the referenced table
232 232
             // resulting in a "belongsTo" relationship
233 233
             $relations = [];
234
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
235
-                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' .
234
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
235
+                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.
236 236
                     $relation['REFERENCED_TABLE_NAME'];
237 237
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] =
238 238
                     $relation['REFERENCED_COLUMN_NAME'];
@@ -248,12 +248,12 @@  discard block
 block discarded – undo
248 248
                     $definition->getName() == $relname ||
249 249
                     $definition->getColumn($relname)
250 250
                 ) {
251
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
251
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
252 252
                 }
253 253
                 $orig = $relname;
254 254
                 $cntr = 1;
255 255
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
256
-                    $relname = $orig . '_' . (++ $cntr);
256
+                    $relname = $orig.'_'.(++$cntr);
257 257
                 }
258 258
                 $definition->addRelation(
259 259
                     new TableRelation(
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
             // assuming current table is on the "one" end having "many" records in the referencing table
270 270
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
271 271
             $relations = [];
272
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
273
-                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' .
272
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
273
+                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.
274 274
                     $relation['TABLE_NAME'];
275 275
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] =
276 276
                     $relation['COLUMN_NAME'];
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
                 $usedcol = [];
288 288
                 if (count($columns)) {
289 289
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
290
-                        ->filter(function (array $v) use ($columns): bool {
290
+                        ->filter(function(array $v) use ($columns): bool {
291 291
                             return in_array($v['COLUMN_NAME'], $columns);
292 292
                         })
293
-                        ->map(function (array $v): array {
293
+                        ->map(function(array $v): array {
294 294
                             $new = [];
295 295
                             foreach ($v as $kk => $vv) {
296 296
                                 $new[strtoupper($kk)] = $vv;
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                             return $new;
299 299
                         }) as $relation
300 300
                     ) {
301
-                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' .
301
+                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.
302 302
                             $relation['REFERENCED_TABLE_NAME'];
303 303
                         $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] =
304 304
                             $relation['REFERENCED_COLUMN_NAME'];
@@ -316,12 +316,12 @@  discard block
 block discarded – undo
316 316
                         $definition->getName() == $relname ||
317 317
                         $definition->getColumn($relname)
318 318
                     ) {
319
-                        $relname .= '_' . array_values($data['keymap'])[0];
319
+                        $relname .= '_'.array_values($data['keymap'])[0];
320 320
                     }
321 321
                     $orig = $relname;
322 322
                     $cntr = 1;
323 323
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
324
-                        $relname = $orig . '_' . (++ $cntr);
324
+                        $relname = $orig.'_'.(++$cntr);
325 325
                     }
326 326
                     $definition->addRelation(
327 327
                         new TableRelation(
@@ -349,23 +349,23 @@  discard block
 block discarded – undo
349 349
                 "SELECT table_name FROM information_schema.tables where table_schema = ?",
350 350
                 [$this->connection['opts']['schema'] ?? $this->connection['name']]
351 351
             ))
352
-            ->map(function (array $v): array {
352
+            ->map(function(array $v): array {
353 353
                 $new = [];
354 354
                 foreach ($v as $kk => $vv) {
355 355
                     $new[strtoupper($kk)] = $vv;
356 356
                 }
357 357
                 return $new;
358 358
             })
359
-            ->mapKey(function (array $v): string {
359
+            ->mapKey(function(array $v): string {
360 360
                 return strtolower($v['TABLE_NAME']);
361 361
             })
362 362
             ->pluck('TABLE_NAME')
363
-            ->map(function (string $v): Table {
363
+            ->map(function(string $v): Table {
364 364
                 return $this->table($v)->toLowerCase();
365 365
             })
366 366
             ->toArray();
367 367
         foreach (array_keys($tables) as $k) {
368
-            $tables[($this->connection['opts']['schema'] ?? $this->connection['name']) . '.' . $k] = &$tables[$k];
368
+            $tables[($this->connection['opts']['schema'] ?? $this->connection['name']).'.'.$k] = &$tables[$k];
369 369
         }
370 370
         return $tables;
371 371
     }
Please login to merge, or discard this patch.
src/driver/postgre/Schema.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
@@ -114,12 +114,12 @@  discard block
 block discarded – undo
114 114
             ->query(
115 115
                 "SELECT * FROM information_schema.columns
116 116
                  WHERE table_name = ? AND table_schema = ? AND table_catalog = ?",
117
-                [ $table, $schema, $catalog ]
117
+                [$table, $schema, $catalog]
118 118
             ))
119
-            ->mapKey(function ($v): string {
119
+            ->mapKey(function($v): string {
120 120
                 return $v['column_name'];
121 121
             })
122
-            ->map(function ($v) {
122
+            ->map(function($v) {
123 123
                 $v['length'] = null;
124 124
                 if (!isset($v['data_type'])) {
125 125
                     return $v;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 switch ($v['data_type']) {
128 128
                     case 'character':
129 129
                     case 'character varying':
130
-                        $v['length'] = (int)$v['character_maximum_length'];
130
+                        $v['length'] = (int) $v['character_maximum_length'];
131 131
                         break;
132 132
                 }
133 133
                 $v['hidden'] = $v['is_identity'] !== 'YES' && $v['is_generated'] === 'ALWAYS';
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
             })
136 136
             ->toArray();
137 137
         if (!count($columns)) {
138
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
138
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
139 139
         }
140 140
         $pkname = Collection::from($this
141 141
             ->query(
142 142
                 "SELECT constraint_name FROM information_schema.table_constraints
143 143
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?",
144
-                [ $table, 'PRIMARY KEY', $schema, $catalog ]
144
+                [$table, 'PRIMARY KEY', $schema, $catalog]
145 145
             ))
146 146
             ->pluck('constraint_name')
147 147
             ->value();
@@ -151,32 +151,32 @@  discard block
 block discarded – undo
151 151
                 ->query(
152 152
                     "SELECT column_name FROM information_schema.constraint_column_usage
153 153
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?",
154
-                    [ $table, $pkname, $schema, $catalog ]
154
+                    [$table, $pkname, $schema, $catalog]
155 155
                 ))
156 156
                 ->pluck('column_name')
157 157
                 ->toArray();
158 158
         }
159
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
159
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
160 160
             ->addColumns($columns)
161 161
             ->setPrimaryKey($primary)
162 162
             ->setComment('');
163 163
 
164 164
         if ($detectRelations) {
165 165
             $duplicated = [];
166
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
167
-                $t = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
166
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
167
+                $t = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
168 168
                 $duplicated[$t] = isset($duplicated[$t]);
169 169
             }
170
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
171
-                $t = $relation['table_schema'] . '.' . $relation['table_name'];
170
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
171
+                $t = $relation['table_schema'].'.'.$relation['table_name'];
172 172
                 $duplicated[$t] = isset($duplicated[$t]);
173 173
             }
174 174
             // pivot relations where the current table is referenced
175 175
             // assuming current table is on the "one" end having "many" records in the referencing table
176 176
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
177 177
             $relations = [];
178
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
179
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' .
178
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
179
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.
180 180
                     $relation['table_name'];
181 181
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
182 182
                     $relation['column_name'];
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
                 $usedcol = [];
194 194
                 if (count($columns)) {
195 195
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
196
-                        ->filter(function ($v) use ($columns) {
196
+                        ->filter(function($v) use ($columns) {
197 197
                             return in_array($v['column_name'], $columns);
198 198
                         }) as $relation
199 199
                     ) {
200
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
200
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
201 201
                             $relation['referenced_table_name'];
202 202
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
203 203
                             $relation['referenced_column_name'];
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
                         $definition->getName() == $relname ||
218 218
                         $definition->getColumn($relname)
219 219
                     ) {
220
-                        $relname = $orig . '_' . (++ $cntr);
220
+                        $relname = $orig.'_'.(++$cntr);
221 221
                     }
222 222
                     $definition->addRelation(
223 223
                         new TableRelation(
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
             // assuming current table is linked to "one" record in the referenced table
240 240
             // resulting in a "belongsTo" relationship
241 241
             $relations = [];
242
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
243
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
242
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
243
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
244 244
                     $relation['referenced_table_name'];
245 245
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
246 246
                     $relation['referenced_column_name'];
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
                     $definition->getName() == $relname ||
257 257
                     $definition->getColumn($relname)
258 258
                 ) {
259
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
259
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
260 260
                 }
261 261
                 $orig = $relname;
262 262
                 $cntr = 1;
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                     $definition->getName() == $relname ||
265 265
                     $definition->getColumn($relname)
266 266
                 ) {
267
-                    $relname = $orig . '_' . (++ $cntr);
267
+                    $relname = $orig.'_'.(++$cntr);
268 268
                 }
269 269
                 $definition->addRelation(
270 270
                     new TableRelation(
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
             // assuming current table is on the "one" end having "many" records in the referencing table
281 281
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
282 282
             $relations = [];
283
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
284
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' .
283
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
284
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.
285 285
                     $relation['table_name'];
286 286
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
287 287
                     $relation['column_name'];
@@ -298,11 +298,11 @@  discard block
 block discarded – undo
298 298
                 $usedcol = [];
299 299
                 if (count($columns)) {
300 300
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
301
-                        ->filter(function ($v) use ($columns) {
301
+                        ->filter(function($v) use ($columns) {
302 302
                             return in_array($v['column_name'], $columns);
303 303
                         }) as $relation
304 304
                     ) {
305
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
305
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
306 306
                             $relation['referenced_table_name'];
307 307
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
308 308
                             $relation['referenced_column_name'];
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
                         $definition->getName() == $relname ||
321 321
                         $definition->getColumn($relname)
322 322
                     ) {
323
-                        $relname .= '_' . array_values($data['keymap'])[0];
323
+                        $relname .= '_'.array_values($data['keymap'])[0];
324 324
                     }
325 325
                     $orig = $relname;
326 326
                     $cntr = 1;
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
                         $definition->getName() == $relname ||
329 329
                         $definition->getColumn($relname)
330 330
                     ) {
331
-                        $relname = $orig . '_' . (++ $cntr);
331
+                        $relname = $orig.'_'.(++$cntr);
332 332
                     }
333 333
                     $definition->addRelation(
334 334
                         new TableRelation(
@@ -378,20 +378,20 @@  discard block
 block discarded – undo
378 378
                     attr.attnum > 0
379 379
                  order by
380 380
                     attr.attnum",
381
-                [ $table, $schema ]
381
+                [$table, $schema]
382 382
             ))
383
-            ->mapKey(function ($v): string {
383
+            ->mapKey(function($v): string {
384 384
                 return $v['column_name'];
385 385
             })
386
-            ->map(function ($v) {
386
+            ->map(function($v) {
387 387
                 $v['length'] = null;
388 388
                 return $v;
389 389
             })
390 390
             ->toArray();
391 391
         if (!count($columns)) {
392
-            throw new DBException('View not found by name: ' . implode('.', [$schema,$table]));
392
+            throw new DBException('View not found by name: '.implode('.', [$schema, $table]));
393 393
         }
394
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
394
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
395 395
             ->addColumns($columns)
396 396
             ->setComment('');
397 397
         return $definition;
@@ -401,13 +401,13 @@  discard block
 block discarded – undo
401 401
         $tables = Collection::from($this
402 402
             ->query(
403 403
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
404
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
404
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
405 405
             ))
406
-            ->mapKey(function ($v) {
406
+            ->mapKey(function($v) {
407 407
                 return strtolower($v['table_name']);
408 408
             })
409 409
             ->pluck('table_name')
410
-            ->map(function ($v) {
410
+            ->map(function($v) {
411 411
                 return $this->table($v)->toLowerCase();
412 412
             })
413 413
             ->toArray();
@@ -418,19 +418,19 @@  discard block
 block discarded – undo
418 418
                  FROM pg_catalog.pg_class cls
419 419
                  join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace
420 420
                  WHERE cls.relkind = 'm' and ns.nspname = ?",
421
-                [ $this->connection['opts']['schema'] ?? 'public' ]
421
+                [$this->connection['opts']['schema'] ?? 'public']
422 422
             ))
423
-            ->mapKey(function ($v) {
423
+            ->mapKey(function($v) {
424 424
                 return strtolower($v['table_name']);
425 425
             })
426 426
             ->pluck('table_name')
427
-            ->map(function ($v) {
427
+            ->map(function($v) {
428 428
                 return $this->view($v)->toLowerCase();
429 429
             })
430 430
             ->toArray();
431 431
         $tables = array_merge($views, $tables);
432 432
         foreach (array_keys($tables) as $k) {
433
-            $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k];
433
+            $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k];
434 434
         }
435 435
         return $tables;
436 436
     }
Please login to merge, or discard this patch.
src/driver/sqlite/Schema.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
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,8 +53,8 @@  discard block
 block discarded – undo
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
         }
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
          */
65 65
         $columns = Collection::from($this
66 66
             ->query("PRAGMA table_info(".$table.")"))
67
-            ->mapKey(function ($v): string {
67
+            ->mapKey(function($v): string {
68 68
                 return $v['name'];
69 69
             })
70
-            ->map(function ($v) {
70
+            ->map(function($v) {
71 71
                 $v['length'] = null;
72 72
                 if (!isset($v['type'])) {
73 73
                     return $v;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                     default:
78 78
                         if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
79 79
                             // extract length from varchar
80
-                            $v['length'] = (int)explode(')', explode('(', $type)[1])[0];
80
+                            $v['length'] = (int) explode(')', explode('(', $type)[1])[0];
81 81
                             $v['length'] = $v['length'] > 0 ? $v['length'] : null;
82 82
                         }
83 83
                         break;
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
             })
87 87
             ->toArray();
88 88
         if (!count($columns)) {
89
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
89
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
90 90
         }
91 91
         $primary = [];
92 92
         foreach ($columns as $column) {
93
-            if ((int)$column['pk']) {
93
+            if ((int) $column['pk']) {
94 94
                 $primary[] = $column['name'];
95 95
             }
96 96
         }
97
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
97
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
98 98
             ->addColumns($columns)
99 99
             ->setPrimaryKey($primary)
100 100
             ->setComment('');
101 101
 
102 102
         if ($detectRelations) {
103 103
             $duplicated = [];
104
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
105
-                $t = 'main.' . $relation['referenced_table'];
104
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
105
+                $t = 'main.'.$relation['referenced_table'];
106 106
                 $duplicated[$t] = isset($duplicated[$t]);
107 107
             }
108
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
109
-                $t = 'main.' . $relation['table'];
108
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
109
+                $t = 'main.'.$relation['table'];
110 110
                 $duplicated[$t] = isset($duplicated[$t]);
111 111
             }
112 112
             // pivot relations where the current table is referenced
113 113
             // assuming current table is on the "one" end having "many" records in the referencing table
114 114
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
115 115
             $relations = [];
116
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
117
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
116
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
117
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
118 118
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
119 119
             }
120 120
             foreach ($relations as $data) {
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
                 $usedcol = [];
130 130
                 if (count($columns)) {
131 131
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
132
-                        ->filter(function ($v) use ($columns) {
132
+                        ->filter(function($v) use ($columns) {
133 133
                             return in_array($v['from'], $columns);
134 134
                         }) as $relation
135 135
                     ) {
136
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
136
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
137 137
                             $relation['referenced_table'];
138 138
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
139 139
                         $usedcol[] = $relation['from'];
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
                         $definition->getName() == $relname ||
153 153
                         $definition->getColumn($relname)
154 154
                     ) {
155
-                        $relname = $orig . '_' . (++ $cntr);
155
+                        $relname = $orig.'_'.(++$cntr);
156 156
                     }
157 157
                     $definition->addRelation(
158 158
                         new TableRelation(
@@ -174,8 +174,8 @@  discard block
 block discarded – undo
174 174
             // assuming current table is linked to "one" record in the referenced table
175 175
             // resulting in a "belongsTo" relationship
176 176
             $relations = [];
177
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
178
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table'];
177
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
178
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table'];
179 179
                 $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
180 180
             }
181 181
             foreach ($relations as $name => $data) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                     $definition->getName() == $relname ||
190 190
                     $definition->getColumn($relname)
191 191
                 ) {
192
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
192
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
193 193
                 }
194 194
                 $orig = $relname;
195 195
                 $cntr = 1;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                     $definition->getName() == $relname ||
198 198
                     $definition->getColumn($relname)
199 199
                 ) {
200
-                    $relname = $orig . '_' . (++ $cntr);
200
+                    $relname = $orig.'_'.(++$cntr);
201 201
                 }
202 202
                 $definition->addRelation(
203 203
                     new TableRelation(
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
             // assuming current table is on the "one" end having "many" records in the referencing table
214 214
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
215 215
             $relations = [];
216
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
217
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
216
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
217
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
218 218
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
219 219
             }
220 220
             foreach ($relations as $data) {
@@ -229,11 +229,11 @@  discard block
 block discarded – undo
229 229
                 $usedcol = [];
230 230
                 if (count($columns)) {
231 231
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
232
-                        ->filter(function ($v) use ($columns) {
232
+                        ->filter(function($v) use ($columns) {
233 233
                             return in_array($v['from'], $columns);
234 234
                         }) as $relation
235 235
                     ) {
236
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
236
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
237 237
                             $relation['referenced_table'];
238 238
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
239 239
                         $usedcol[] = $relation['from'];
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                         $definition->getName() == $relname ||
251 251
                         $definition->getColumn($relname)
252 252
                     ) {
253
-                        $relname .= '_' . array_values($data['keymap'])[0];
253
+                        $relname .= '_'.array_values($data['keymap'])[0];
254 254
                     }
255 255
                     $orig = $relname;
256 256
                     $cntr = 1;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
                         $definition->getName() == $relname ||
259 259
                         $definition->getColumn($relname)
260 260
                     ) {
261
-                        $relname = $orig . '_' . (++ $cntr);
261
+                        $relname = $orig.'_'.(++$cntr);
262 262
                     }
263 263
                     $definition->addRelation(
264 264
                         new TableRelation(
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
                 "SELECT tbl_name
287 287
                  FROM sqlite_schema
288 288
                  WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';",
289
-                [ 'table', 'view' ]
289
+                ['table', 'view']
290 290
             ))
291
-            ->mapKey(function ($v) {
291
+            ->mapKey(function($v) {
292 292
                 return strtolower($v['tbl_name']);
293 293
             })
294 294
             ->pluck('tbl_name')
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
             $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase();
298 298
         }
299 299
         foreach (array_keys($tables) as $k) {
300
-            $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k];
300
+            $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k];
301 301
         }
302 302
         return $tables;
303 303
     }
Please login to merge, or discard this patch.