Completed
Push — master ( ff62d1...944e6e )
by Ivan
13:59
created
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
             ksort($relations);
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
                 $usedcol = [];
131 131
                 if (count($columns)) {
132 132
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
133
-                        ->filter(function ($v) use ($columns) {
133
+                        ->filter(function($v) use ($columns) {
134 134
                             return in_array($v['from'], $columns);
135 135
                         }) as $relation
136 136
                     ) {
137
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
137
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
138 138
                             $relation['referenced_table'];
139 139
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
140 140
                         $usedcol[] = $relation['from'];
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                         $definition->getName() == $relname ||
154 154
                         $definition->getColumn($relname)
155 155
                     ) {
156
-                        $relname = $orig . '_' . (++ $cntr);
156
+                        $relname = $orig.'_'.(++$cntr);
157 157
                     }
158 158
                     $definition->addRelation(
159 159
                         new TableRelation(
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
             // assuming current table is linked to "one" record in the referenced table
176 176
             // resulting in a "belongsTo" relationship
177 177
             $relations = [];
178
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
179
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table'];
178
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
179
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table'];
180 180
                 $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
181 181
             }
182 182
             ksort($relations);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     $definition->getName() == $relname ||
192 192
                     $definition->getColumn($relname)
193 193
                 ) {
194
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
194
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
195 195
                 }
196 196
                 $orig = $relname;
197 197
                 $cntr = 1;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     $definition->getName() == $relname ||
200 200
                     $definition->getColumn($relname)
201 201
                 ) {
202
-                    $relname = $orig . '_' . (++ $cntr);
202
+                    $relname = $orig.'_'.(++$cntr);
203 203
                 }
204 204
                 $definition->addRelation(
205 205
                     new TableRelation(
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
             // assuming current table is on the "one" end having "many" records in the referencing table
216 216
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
217 217
             $relations = [];
218
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
219
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
218
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
219
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
220 220
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
221 221
             }
222 222
             ksort($relations);
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
                 $usedcol = [];
233 233
                 if (count($columns)) {
234 234
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
235
-                        ->filter(function ($v) use ($columns) {
235
+                        ->filter(function($v) use ($columns) {
236 236
                             return in_array($v['from'], $columns);
237 237
                         }) as $relation
238 238
                     ) {
239
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
239
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
240 240
                             $relation['referenced_table'];
241 241
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
242 242
                         $usedcol[] = $relation['from'];
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
                         $definition->getName() == $relname ||
254 254
                         $definition->getColumn($relname)
255 255
                     ) {
256
-                        $relname .= '_' . array_values($data['keymap'])[0];
256
+                        $relname .= '_'.array_values($data['keymap'])[0];
257 257
                     }
258 258
                     $orig = $relname;
259 259
                     $cntr = 1;
@@ -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(
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
                 "SELECT tbl_name
290 290
                  FROM sqlite_schema
291 291
                  WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';",
292
-                [ 'table', 'view' ]
292
+                ['table', 'view']
293 293
             ))
294
-            ->mapKey(function ($v) {
294
+            ->mapKey(function($v) {
295 295
                 return strtolower($v['tbl_name']);
296 296
             })
297 297
             ->pluck('tbl_name')
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
             $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase();
301 301
         }
302 302
         foreach (array_keys($tables) as $k) {
303
-            $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k];
303
+            $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k];
304 304
         }
305 305
         return $tables;
306 306
     }
Please login to merge, or discard this patch.
src/driver/oracle/Schema.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
         $columns = Collection::from($this
33 33
             ->query(
34 34
                 "SELECT * FROM user_tab_cols WHERE UPPER(table_name) = ?",
35
-                [ strtoupper($table) ]
35
+                [strtoupper($table)]
36 36
             ))
37
-            ->map(function ($v) {
37
+            ->map(function($v) {
38 38
                 $new = [];
39 39
                 foreach ($v as $kk => $vv) {
40 40
                     $new[strtoupper($kk)] = $vv;
41 41
                 }
42 42
                 return $new;
43 43
             })
44
-            ->mapKey(function ($v): string {
44
+            ->mapKey(function($v): string {
45 45
                 return $v['COLUMN_NAME'];
46 46
             })
47
-            ->map(function ($v) {
47
+            ->map(function($v) {
48 48
                 $v['length'] = null;
49 49
                 if (!isset($v['DATA_TYPE'])) {
50 50
                     return $v;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                     default:
57 57
                         if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
58 58
                             // extract length from varchar
59
-                            $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0];
59
+                            $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0];
60 60
                             $v['length'] = $v['length'] > 0 ? $v['length'] : null;
61 61
                         }
62 62
                         break;
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
             ->query(
74 74
                 "SELECT constraint_name FROM user_constraints
75 75
                 WHERE table_name = ? AND constraint_type = ?",
76
-                [ strtoupper($table), 'P' ]
76
+                [strtoupper($table), 'P']
77 77
             ))
78
-            ->map(function ($v) {
78
+            ->map(function($v) {
79 79
                 $new = [];
80 80
                 foreach ($v as $kk => $vv) {
81 81
                     $new[strtoupper($kk)] = $vv;
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
                 ->query(
91 91
                     "SELECT column_name FROM user_cons_columns
92 92
                     WHERE table_name = ? AND constraint_name = ?",
93
-                    [ strtoupper($table), $pkname ]
93
+                    [strtoupper($table), $pkname]
94 94
                 ))
95
-                ->map(function ($v) {
95
+                ->map(function($v) {
96 96
                     $new = [];
97 97
                     foreach ($v as $kk => $vv) {
98 98
                         $new[strtoupper($kk)] = $vv;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
                     LEFT JOIN user_cons_columns cc ON cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
121 121
                     WHERE ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
122 122
                     ORDER BY cc.POSITION",
123
-                    [ strtoupper($table), 'R' ]
123
+                    [strtoupper($table), 'R']
124 124
                 ))
125
-                ->map(function ($v) {
125
+                ->map(function($v) {
126 126
                     $new = [];
127 127
                     foreach ($v as $kk => $vv) {
128 128
                         $new[strtoupper($kk)] = $vv;
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
                     WHERE
139 139
                         ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
140 140
                     ORDER BY cc.POSITION",
141
-                    [ $pkname, 'R' ]
141
+                    [$pkname, 'R']
142 142
                 ))
143
-                ->map(function ($v) {
143
+                ->map(function($v) {
144 144
                     $new = [];
145 145
                     foreach ($v as $kk => $vv) {
146 146
                         $new[strtoupper($kk)] = $vv;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             $relations = [];
164 164
             foreach ($relationsR as $relation) {
165 165
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
166
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
166
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
167 167
                     $relation['COLUMN_NAME'];
168 168
             }
169 169
             ksort($relations);
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
                                 ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
195 195
                                 cc.COLUMN_NAME IN (??)
196 196
                             ORDER BY POSITION",
197
-                            [ $data['table'], 'R', $columns ]
197
+                            [$data['table'], 'R', $columns]
198 198
                         ))
199
-                        ->map(function ($v) {
199
+                        ->map(function($v) {
200 200
                             $new = [];
201 201
                             foreach ($v as $kk => $vv) {
202 202
                                 $new[strtoupper($kk)] = $vv;
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
                         ->query(
217 217
                             "SELECT COLUMN_NAME FROM user_cons_columns
218 218
                             WHERE CONSTRAINT_NAME = ? ORDER BY POSITION",
219
-                            [ current($foreign['keymap']) ]
219
+                            [current($foreign['keymap'])]
220 220
                         ))
221
-                        ->map(function ($v) {
221
+                        ->map(function($v) {
222 222
                             $new = [];
223 223
                             foreach ($v as $kk => $vv) {
224 224
                                 $new[strtoupper($kk)] = $vv;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                     $relname = $foreign['table'];
234 234
                     $cntr = 1;
235 235
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
236
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
236
+                        $relname = $foreign['table'].'_'.(++$cntr);
237 237
                     }
238 238
                     $definition->addRelation(
239 239
                         new TableRelation(
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
                     ->query(
267 267
                         "SELECT COLUMN_NAME FROM user_cons_columns
268 268
                          WHERE CONSTRAINT_NAME = ? ORDER BY POSITION",
269
-                        [ current($data['keymap']) ]
269
+                        [current($data['keymap'])]
270 270
                     ))
271
-                    ->map(function ($v) {
271
+                    ->map(function($v) {
272 272
                         $new = [];
273 273
                         foreach ($v as $kk => $vv) {
274 274
                             $new[strtoupper($kk)] = $vv;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                     $definition->getName() == $relname ||
287 287
                     $definition->getColumn($relname)
288 288
                 ) {
289
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
289
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
290 290
                 }
291 291
                 $orig = $relname;
292 292
                 $cntr = 1;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                     $definition->getName() == $relname ||
296 296
                     $definition->getColumn($relname)
297 297
                 ) {
298
-                    $relname = $orig . '_' . (++ $cntr);
298
+                    $relname = $orig.'_'.(++$cntr);
299 299
                 }
300 300
                 $definition->addRelation(
301 301
                     new TableRelation(
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             $relations = [];
314 314
             foreach ($relationsR as $relation) {
315 315
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
316
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
316
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
317 317
                     $relation['COLUMN_NAME'];
318 318
             }
319 319
             ksort($relations);
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
                                 ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
345 345
                                 cc.COLUMN_NAME IN (??)
346 346
                             ORDER BY POSITION",
347
-                            [ $data['table'], 'R', $columns ]
347
+                            [$data['table'], 'R', $columns]
348 348
                         ))
349
-                        ->map(function ($v) {
349
+                        ->map(function($v) {
350 350
                             $new = [];
351 351
                             foreach ($v as $kk => $vv) {
352 352
                                 $new[strtoupper($kk)] = $vv;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                         $definition->getName() == $relname ||
368 368
                         $definition->getColumn($relname)
369 369
                     ) {
370
-                        $relname .= '_' . array_values($data['keymap'])[0];
370
+                        $relname .= '_'.array_values($data['keymap'])[0];
371 371
                     }
372 372
                     $orig = $relname;
373 373
                     $cntr = 1;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
                         $definition->getName() == $relname ||
377 377
                         $definition->getColumn($relname)
378 378
                     ) {
379
-                        $relname = $orig . '_' . (++ $cntr);
379
+                        $relname = $orig.'_'.(++$cntr);
380 380
                     }
381 381
                     $definition->addRelation(
382 382
                         new TableRelation(
@@ -406,18 +406,18 @@  discard block
 block discarded – undo
406 406
                  SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS",
407 407
                 []
408 408
             ))
409
-            ->map(function ($v) {
409
+            ->map(function($v) {
410 410
                 $new = [];
411 411
                 foreach ($v as $kk => $vv) {
412 412
                     $new[strtoupper($kk)] = $vv;
413 413
                 }
414 414
                 return $new;
415 415
             })
416
-            ->mapKey(function ($v) {
416
+            ->mapKey(function($v) {
417 417
                 return strtolower($v['TABLE_NAME']);
418 418
             })
419 419
             ->pluck('TABLE_NAME')
420
-            ->map(function ($v) {
420
+            ->map(function($v) {
421 421
                 return $this->table($v)->toLowerCase();
422 422
             })
423 423
             ->toArray();
Please login to merge, or discard this patch.