Completed
Push — master ( a8c749...61a9ae )
by Ivan
12:12
created
src/driver/postgre/Schema.php 1 patch
Spacing   +29 added lines, -29 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
         }
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
         $columns = Collection::from($this
111 111
             ->query(
112 112
                 "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ? AND table_catalog = ?",
113
-                [ $table, $schema, $catalog ]
113
+                [$table, $schema, $catalog]
114 114
             ))
115
-            ->mapKey(function ($v) {
115
+            ->mapKey(function($v) {
116 116
                 return $v['column_name'];
117 117
             })
118
-            ->map(function ($v) {
118
+            ->map(function($v) {
119 119
                 $v['length'] = null;
120 120
                 if (!isset($v['data_type'])) {
121 121
                     return $v;
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
                 switch ($v['data_type']) {
124 124
                     case 'character':
125 125
                     case 'character varying':
126
-                        $v['length'] = (int)$v['character_maximum_length'];
126
+                        $v['length'] = (int) $v['character_maximum_length'];
127 127
                         break;
128 128
                 }
129 129
                 return $v;
130 130
             })
131 131
             ->toArray();
132 132
         if (!count($columns)) {
133
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
133
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
134 134
         }
135 135
         $pkname = Collection::from($this
136 136
             ->query(
137 137
                 "SELECT constraint_name FROM information_schema.table_constraints
138 138
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?",
139
-                [ $table, 'PRIMARY KEY', $schema, $catalog ]
139
+                [$table, 'PRIMARY KEY', $schema, $catalog]
140 140
             ))
141 141
             ->pluck('constraint_name')
142 142
             ->value();
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
                 ->query(
147 147
                     "SELECT column_name FROM information_schema.constraint_column_usage
148 148
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?",
149
-                    [ $table, $pkname, $schema, $catalog ]
149
+                    [$table, $pkname, $schema, $catalog]
150 150
                 ))
151 151
                 ->pluck('column_name')
152 152
                 ->toArray();
153 153
         }
154
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
154
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
155 155
             ->addColumns($columns)
156 156
             ->setPrimaryKey($primary)
157 157
             ->setComment('');
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
             // assuming current table is on the "one" end having "many" records in the referencing table
162 162
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
163 163
             $relations = [];
164
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
165
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . $relation['table_name'];
164
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
165
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.$relation['table_name'];
166 166
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
167 167
                     $relation['column_name'];
168 168
             }
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
                 $usedcol = [];
179 179
                 if (count($columns)) {
180 180
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
181
-                        ->filter(function ($v) use ($columns) {
181
+                        ->filter(function($v) use ($columns) {
182 182
                             return in_array($v['column_name'], $columns);
183 183
                         }) as $relation
184 184
                     ) {
185
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
185
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
186 186
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
187 187
                             $relation['referenced_column_name'];
188 188
                         $usedcol[] = $relation['column_name'];
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                         $definition->getName() == $relname ||
203 203
                         $definition->getColumn($relname)
204 204
                     ) {
205
-                        $relname = $orig . '_' . (++ $cntr);
205
+                        $relname = $orig.'_'.(++$cntr);
206 206
                     }
207 207
                     $definition->addRelation(
208 208
                         new TableRelation(
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
                         $definition->getName() == $relname ||
228 228
                         $definition->getColumn($relname)
229 229
                     ) {
230
-                        $relname = $orig . '_' . (++ $cntr);
230
+                        $relname = $orig.'_'.(++$cntr);
231 231
                     }
232 232
                     $definition->addRelation(
233 233
                         new TableRelation(
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
             // assuming current table is linked to "one" record in the referenced table
244 244
             // resulting in a "belongsTo" relationship
245 245
             $relations = [];
246
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
247
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
246
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
247
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
248 248
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
249 249
                     $relation['referenced_column_name'];
250 250
             }
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
                     $definition->getName() == $relname ||
262 262
                     $definition->getColumn($relname)
263 263
                 ) {
264
-                    $relname = $orig . '_' . (++ $cntr);
264
+                    $relname = $orig.'_'.(++$cntr);
265 265
                 }
266 266
                 $definition->addRelation(
267 267
                     new TableRelation(
@@ -280,19 +280,19 @@  discard block
 block discarded – undo
280 280
         $tables = Collection::from($this
281 281
             ->query(
282 282
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
283
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
283
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
284 284
             ))
285
-            ->mapKey(function ($v) {
285
+            ->mapKey(function($v) {
286 286
                 return $v['table_name'];
287 287
             })
288 288
             ->pluck('table_name')
289
-            ->map(function ($v) {
289
+            ->map(function($v) {
290 290
                 return $this->table($v);
291 291
             })
292 292
             ->toArray();
293 293
 
294 294
         foreach (array_keys($tables) as $k) {
295
-            $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k];
295
+            $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k];
296 296
         }
297 297
         return $tables;
298 298
     }
Please login to merge, or discard this patch.