Completed
Push — master ( 0c3196...9dfbff )
by Ivan
10:30
created
src/driver/postgre/Schema.php 1 patch
Spacing   +37 added lines, -37 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,12 +151,12 @@  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('');
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
             // assuming current table is on the "one" end having "many" records in the referencing table
167 167
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
168 168
             $relations = [];
169
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
170
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' .
169
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
170
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.
171 171
                     $relation['table_name'];
172 172
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
173 173
                     $relation['column_name'];
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
                 $usedcol = [];
185 185
                 if (count($columns)) {
186 186
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
187
-                        ->filter(function ($v) use ($columns) {
187
+                        ->filter(function($v) use ($columns) {
188 188
                             return in_array($v['column_name'], $columns);
189 189
                         }) as $relation
190 190
                     ) {
191
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
191
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
192 192
                             $relation['referenced_table_name'];
193 193
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
194 194
                             $relation['referenced_column_name'];
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                         $definition->getName() == $relname ||
209 209
                         $definition->getColumn($relname)
210 210
                     ) {
211
-                        $relname = $orig . '_' . (++ $cntr);
211
+                        $relname = $orig.'_'.(++$cntr);
212 212
                     }
213 213
                     $definition->addRelation(
214 214
                         new TableRelation(
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
                         $definition->getName() == $relname ||
237 237
                         $definition->getColumn($relname)
238 238
                     ) {
239
-                        $relname = $orig . '_' . (++ $cntr);
239
+                        $relname = $orig.'_'.(++$cntr);
240 240
                     }
241 241
                     $definition->addRelation(
242 242
                         new TableRelation(
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
             // assuming current table is linked to "one" record in the referenced table
259 259
             // resulting in a "belongsTo" relationship
260 260
             $relations = [];
261
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
262
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
261
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
262
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
263 263
                     $relation['referenced_table_name'];
264 264
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
265 265
                     $relation['referenced_column_name'];
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
                     $definition->getName() == $relname ||
277 277
                     $definition->getColumn($relname)
278 278
                 ) {
279
-                    $relname = $orig . '_' . (++ $cntr);
279
+                    $relname = $orig.'_'.(++$cntr);
280 280
                 }
281 281
                 $definition->addRelation(
282 282
                     new TableRelation(
@@ -320,20 +320,20 @@  discard block
 block discarded – undo
320 320
                     attr.attnum > 0
321 321
                  order by
322 322
                     attr.attnum",
323
-                [ $table, $schema ]
323
+                [$table, $schema]
324 324
             ))
325
-            ->mapKey(function ($v): string {
325
+            ->mapKey(function($v): string {
326 326
                 return $v['column_name'];
327 327
             })
328
-            ->map(function ($v) {
328
+            ->map(function($v) {
329 329
                 $v['length'] = null;
330 330
                 return $v;
331 331
             })
332 332
             ->toArray();
333 333
         if (!count($columns)) {
334
-            throw new DBException('View not found by name: ' . implode('.', [$schema,$table]));
334
+            throw new DBException('View not found by name: '.implode('.', [$schema, $table]));
335 335
         }
336
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
336
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
337 337
             ->addColumns($columns)
338 338
             ->setComment('');
339 339
         return $definition;
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
         $tables = Collection::from($this
344 344
             ->query(
345 345
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
346
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
346
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
347 347
             ))
348
-            ->mapKey(function ($v) {
348
+            ->mapKey(function($v) {
349 349
                 return strtolower($v['table_name']);
350 350
             })
351 351
             ->pluck('table_name')
352
-            ->map(function ($v) {
352
+            ->map(function($v) {
353 353
                 return $this->table($v)->toLowerCase();
354 354
             })
355 355
             ->toArray();
@@ -360,19 +360,19 @@  discard block
 block discarded – undo
360 360
                  FROM pg_catalog.pg_class cls
361 361
                  join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace
362 362
                  WHERE cls.relkind = 'm' and ns.nspname = ?",
363
-                [ $this->connection['opts']['schema'] ?? 'public' ]
363
+                [$this->connection['opts']['schema'] ?? 'public']
364 364
             ))
365
-            ->mapKey(function ($v) {
365
+            ->mapKey(function($v) {
366 366
                 return strtolower($v['table_name']);
367 367
             })
368 368
             ->pluck('table_name')
369
-            ->map(function ($v) {
369
+            ->map(function($v) {
370 370
                 return $this->view($v)->toLowerCase();
371 371
             })
372 372
             ->toArray();
373 373
         $tables = array_merge($views, $tables);
374 374
         foreach (array_keys($tables) as $k) {
375
-            $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k];
375
+            $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k];
376 376
         }
377 377
         return $tables;
378 378
     }
Please login to merge, or discard this patch.