Completed
Push — master ( 849cc1...c9d76a )
by Ivan
14:29
created
src/driver/postgre/Schema.php 1 patch
Spacing   +27 added lines, -27 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('.', [$catalog,$schema,$table]));
133
+            throw new DBException('Table not found by name: '.implode('.', [$catalog, $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'];
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
                     $orig = $relname;
199 199
                     $cntr = 1;
200 200
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
201
-                        $relname = $orig . '_' . (++ $cntr);
201
+                        $relname = $orig.'_'.(++$cntr);
202 202
                     }
203 203
                     $definition->addRelation(
204 204
                         new TableRelation(
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                     $orig = $relname;
220 220
                     $cntr = 1;
221 221
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
222
-                        $relname = $orig . '_' . (++ $cntr);
222
+                        $relname = $orig.'_'.(++$cntr);
223 223
                     }
224 224
                     $definition->addRelation(
225 225
                         new TableRelation(
@@ -235,8 +235,8 @@  discard block
 block discarded – undo
235 235
             // assuming current table is linked to "one" record in the referenced table
236 236
             // resulting in a "belongsTo" relationship
237 237
             $relations = [];
238
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
239
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name'];
238
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
239
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name'];
240 240
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
241 241
                     $relation['referenced_column_name'];
242 242
             }
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
                 $orig = $relname;
250 250
                 $cntr = 1;
251 251
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
252
-                    $relname = $orig . '_' . (++ $cntr);
252
+                    $relname = $orig.'_'.(++$cntr);
253 253
                 }
254 254
                 $definition->addRelation(
255 255
                     new TableRelation(
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
         return Collection::from($this
269 269
             ->query(
270 270
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
271
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
271
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
272 272
             ))
273 273
             ->pluck('table_name')
274
-            ->map(function ($v) {
274
+            ->map(function($v) {
275 275
                 return $this->table($v);
276 276
             })
277 277
             ->toArray();
Please login to merge, or discard this patch.