Completed
Push — master ( e6de36...718b37 )
by Ivan
14:45
created
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'];
@@ -194,11 +194,11 @@  discard block
 block discarded – undo
194 194
                 $usedcol = [];
195 195
                 if (count($columns)) {
196 196
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
197
-                        ->filter(function ($v) use ($columns) {
197
+                        ->filter(function($v) use ($columns) {
198 198
                             return in_array($v['column_name'], $columns);
199 199
                         }) as $relation
200 200
                     ) {
201
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
201
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
202 202
                             $relation['referenced_table_name'];
203 203
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
204 204
                             $relation['referenced_column_name'];
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                         $definition->getName() == $relname ||
219 219
                         $definition->getColumn($relname)
220 220
                     ) {
221
-                        $relname = $orig . '_' . (++ $cntr);
221
+                        $relname = $orig.'_'.(++$cntr);
222 222
                     }
223 223
                     $definition->addRelation(
224 224
                         new TableRelation(
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
             // assuming current table is linked to "one" record in the referenced table
241 241
             // resulting in a "belongsTo" relationship
242 242
             $relations = [];
243
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
244
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
243
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
244
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
245 245
                     $relation['referenced_table_name'];
246 246
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
247 247
                     $relation['referenced_column_name'];
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
                     $definition->getName() == $relname ||
259 259
                     $definition->getColumn($relname)
260 260
                 ) {
261
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
261
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
262 262
                 }
263 263
                 $orig = $relname;
264 264
                 $cntr = 1;
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                     $definition->getName() == $relname ||
267 267
                     $definition->getColumn($relname)
268 268
                 ) {
269
-                    $relname = $orig . '_' . (++ $cntr);
269
+                    $relname = $orig.'_'.(++$cntr);
270 270
                 }
271 271
                 $definition->addRelation(
272 272
                     new TableRelation(
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
             // assuming current table is on the "one" end having "many" records in the referencing table
283 283
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
284 284
             $relations = [];
285
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
286
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' .
285
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
286
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.
287 287
                     $relation['table_name'];
288 288
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
289 289
                     $relation['column_name'];
@@ -301,11 +301,11 @@  discard block
 block discarded – undo
301 301
                 $usedcol = [];
302 302
                 if (count($columns)) {
303 303
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
304
-                        ->filter(function ($v) use ($columns) {
304
+                        ->filter(function($v) use ($columns) {
305 305
                             return in_array($v['column_name'], $columns);
306 306
                         }) as $relation
307 307
                     ) {
308
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
308
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
309 309
                             $relation['referenced_table_name'];
310 310
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
311 311
                             $relation['referenced_column_name'];
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                         $definition->getName() == $relname ||
324 324
                         $definition->getColumn($relname)
325 325
                     ) {
326
-                        $relname .= '_' . array_values($data['keymap'])[0];
326
+                        $relname .= '_'.array_values($data['keymap'])[0];
327 327
                     }
328 328
                     $orig = $relname;
329 329
                     $cntr = 1;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
                         $definition->getName() == $relname ||
332 332
                         $definition->getColumn($relname)
333 333
                     ) {
334
-                        $relname = $orig . '_' . (++ $cntr);
334
+                        $relname = $orig.'_'.(++$cntr);
335 335
                     }
336 336
                     $definition->addRelation(
337 337
                         new TableRelation(
@@ -381,20 +381,20 @@  discard block
 block discarded – undo
381 381
                     attr.attnum > 0
382 382
                  order by
383 383
                     attr.attnum",
384
-                [ $table, $schema ]
384
+                [$table, $schema]
385 385
             ))
386
-            ->mapKey(function ($v): string {
386
+            ->mapKey(function($v): string {
387 387
                 return $v['column_name'];
388 388
             })
389
-            ->map(function ($v) {
389
+            ->map(function($v) {
390 390
                 $v['length'] = null;
391 391
                 return $v;
392 392
             })
393 393
             ->toArray();
394 394
         if (!count($columns)) {
395
-            throw new DBException('View not found by name: ' . implode('.', [$schema,$table]));
395
+            throw new DBException('View not found by name: '.implode('.', [$schema, $table]));
396 396
         }
397
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
397
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
398 398
             ->addColumns($columns)
399 399
             ->setComment('');
400 400
         return $definition;
@@ -410,13 +410,13 @@  discard block
 block discarded – undo
410 410
                     (cls.relkind = 'p' OR cls.relkind = 'r') AND
411 411
                     ns.nspname = ? AND
412 412
                     NOT EXISTS (SELECT 1 FROM pg_inherits WHERE inhrelid = cls.oid) ",
413
-                [ $this->connection['opts']['schema'] ?? 'public' ]
413
+                [$this->connection['opts']['schema'] ?? 'public']
414 414
             ))
415
-            ->mapKey(function ($v) {
415
+            ->mapKey(function($v) {
416 416
                 return strtolower($v['table_name']);
417 417
             })
418 418
             ->pluck('table_name')
419
-            ->map(function ($v) {
419
+            ->map(function($v) {
420 420
                 return $this->table($v)->toLowerCase();
421 421
             })
422 422
             ->toArray();
@@ -427,19 +427,19 @@  discard block
 block discarded – undo
427 427
                  FROM pg_catalog.pg_class cls
428 428
                  join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace
429 429
                  WHERE cls.relkind = 'm' and ns.nspname = ?",
430
-                [ $this->connection['opts']['schema'] ?? 'public' ]
430
+                [$this->connection['opts']['schema'] ?? 'public']
431 431
             ))
432
-            ->mapKey(function ($v) {
432
+            ->mapKey(function($v) {
433 433
                 return strtolower($v['table_name']);
434 434
             })
435 435
             ->pluck('table_name')
436
-            ->map(function ($v) {
436
+            ->map(function($v) {
437 437
                 return $this->view($v)->toLowerCase();
438 438
             })
439 439
             ->toArray();
440 440
         $tables = array_merge($views, $tables);
441 441
         foreach (array_keys($tables) as $k) {
442
-            $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k];
442
+            $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k];
443 443
         }
444 444
         return $tables;
445 445
     }
Please login to merge, or discard this patch.