Completed
Push — master ( 21c39e...6982ba )
by Ivan
10:49
created
src/driver/mysql/Schema.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
             $table = $temp[1];
28 28
         }
29 29
 
30
-        if (isset($tables[$schema . '.' . $table])) {
31
-            return $tables[$schema . '.' . $table];
30
+        if (isset($tables[$schema.'.'.$table])) {
31
+            return $tables[$schema.'.'.$table];
32 32
         }
33 33
 
34 34
         static $comments = [];
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
36 36
             $comments[$schema] = Collection::from(
37 37
                 $this->query(
38 38
                     "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?",
39
-                    [ $schema ]
39
+                    [$schema]
40 40
                 )
41 41
             )
42
-            ->mapKey(function (array $v): string {
42
+            ->mapKey(function(array $v): string {
43 43
                 return $v['TABLE_NAME'];
44 44
             })
45 45
             ->pluck('TABLE_COMMENT')
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
                      WHERE
62 62
                         (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND
63 63
                         TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL",
64
-                    [ $main, $main ]
64
+                    [$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(
@@ -84,12 +84,12 @@  discard block
 block discarded – undo
84 84
                         WHERE
85 85
                             TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND
86 86
                             TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL",
87
-                        [ $s, $s ]
87
+                        [$s, $s]
88 88
                     )
89 89
                 )->toArray();
90 90
                 foreach ($col as $row) {
91
-                    $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row;
92
-                    $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row;
91
+                    $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row;
92
+                    $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row;
93 93
                 }
94 94
             }
95 95
         }
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
         if (!count($columns)) {
99 99
             throw new DBException('Table not found by name');
100 100
         }
101
-        $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema))
101
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
102 102
             ->addColumns(
103 103
                 $columns
104 104
                     ->clone()
105
-                    ->mapKey(function (array $v): string {
105
+                    ->mapKey(function(array $v): string {
106 106
                         return $v['Field'];
107 107
                     })
108
-                    ->map(function (array $v): array {
108
+                    ->map(function(array $v): array {
109 109
                         $v['length'] = null;
110 110
                         if (!isset($v['Type'])) {
111 111
                             return $v;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                             default:
128 128
                                 if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
129 129
                                     // extract length from varchar
130
-                                    $v['length'] = (int)explode(')', explode('(', $type)[1])[0];
130
+                                    $v['length'] = (int) explode(')', explode('(', $type)[1])[0];
131 131
                                     $v['length'] = $v['length'] > 0 ? $v['length'] : null;
132 132
                                 }
133 133
                                 break;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             ->setPrimaryKey(
140 140
                 $columns
141 141
                     ->clone()
142
-                    ->filter(function (array $v): bool {
142
+                    ->filter(function(array $v): bool {
143 143
                         return $v['Key'] === 'PRI';
144 144
                     })
145 145
                     ->pluck('Field')
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
             // assuming current table is on the "one" end having "many" records in the referencing table
154 154
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
155 155
             $relations = [];
156
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
157
-                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' .
156
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
157
+                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.
158 158
                     $relation['TABLE_NAME'];
159 159
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] =
160 160
                     $relation['COLUMN_NAME'];
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
                 $usedcol = [];
172 172
                 if (count($columns)) {
173 173
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
174
-                        ->filter(function (array $v) use ($columns): bool {
174
+                        ->filter(function(array $v) use ($columns): bool {
175 175
                             return in_array($v['COLUMN_NAME'], $columns);
176 176
                         })
177
-                        ->map(function (array $v): array {
177
+                        ->map(function(array $v): array {
178 178
                             $new = [];
179 179
                             foreach ($v as $kk => $vv) {
180 180
                                 $new[strtoupper($kk)] = $vv;
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                             return $new;
183 183
                         }) as $relation
184 184
                     ) {
185
-                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' .
185
+                        $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.
186 186
                             $relation['REFERENCED_TABLE_NAME'];
187 187
                         $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] =
188 188
                             $relation['REFERENCED_COLUMN_NAME'];
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     $orig = $relname;
200 200
                     $cntr = 1;
201 201
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
202
-                        $relname = $orig . '_' . (++ $cntr);
202
+                        $relname = $orig.'_'.(++$cntr);
203 203
                     }
204 204
                     $definition->addRelation(
205 205
                         new TableRelation(
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
                     $orig = $relname;
221 221
                     $cntr = 1;
222 222
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
223
-                        $relname = $orig . '_' . (++ $cntr);
223
+                        $relname = $orig.'_'.(++$cntr);
224 224
                     }
225 225
                     $definition->addRelation(
226 226
                         new TableRelation(
@@ -236,8 +236,8 @@  discard block
 block discarded – undo
236 236
             // assuming current table is linked to "one" record in the referenced table
237 237
             // resulting in a "belongsTo" relationship
238 238
             $relations = [];
239
-            foreach (Collection::from($relationsT[$schema . '.' . $table] ?? [])
240
-                ->map(function (array $v): array {
239
+            foreach (Collection::from($relationsT[$schema.'.'.$table] ?? [])
240
+                ->map(function(array $v): array {
241 241
                     $new = [];
242 242
                     foreach ($v as $kk => $vv) {
243 243
                         $new[strtoupper($kk)] = $vv;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
                     return $new;
246 246
                 }) as $relation
247 247
             ) {
248
-                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' .
248
+                $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.
249 249
                     $relation['REFERENCED_TABLE_NAME'];
250 250
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] =
251 251
                     $relation['REFERENCED_COLUMN_NAME'];
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                 $orig = $relname;
260 260
                 $cntr = 1;
261 261
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
262
-                    $relname = $orig . '_' . (++ $cntr);
262
+                    $relname = $orig.'_'.(++$cntr);
263 263
                 }
264 264
                 $definition->addRelation(
265 265
                     new TableRelation(
@@ -280,23 +280,23 @@  discard block
 block discarded – undo
280 280
                 "SELECT table_name FROM information_schema.tables where table_schema = ?",
281 281
                 [$this->connection['opts']['schema'] ?? $this->connection['name']]
282 282
             ))
283
-            ->map(function (array $v): array {
283
+            ->map(function(array $v): array {
284 284
                 $new = [];
285 285
                 foreach ($v as $kk => $vv) {
286 286
                     $new[strtoupper($kk)] = $vv;
287 287
                 }
288 288
                 return $new;
289 289
             })
290
-            ->mapKey(function (array $v): string {
290
+            ->mapKey(function(array $v): string {
291 291
                 return strtolower($v['TABLE_NAME']);
292 292
             })
293 293
             ->pluck('TABLE_NAME')
294
-            ->map(function (string $v): Table {
294
+            ->map(function(string $v): Table {
295 295
                 return $this->table($v)->toLowerCase();
296 296
             })
297 297
             ->toArray();
298 298
         foreach (array_keys($tables) as $k) {
299
-            $tables[($this->connection['opts']['schema'] ?? $this->connection['name']) . '.' . $k] = &$tables[$k];
299
+            $tables[($this->connection['opts']['schema'] ?? $this->connection['name']).'.'.$k] = &$tables[$k];
300 300
         }
301 301
         return $tables;
302 302
     }
Please login to merge, or discard this patch.
src/Schema.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
     
65 65
     public function toArray(): array
66 66
     {
67
-        return array_map(function ($table) {
67
+        return array_map(function($table) {
68 68
             return [
69 69
                 'name' => $table->getName(),
70 70
                 'schema' => $table->getSchema(),
71 71
                 'pkey' => $table->getPrimaryKey(),
72 72
                 'comment' => $table->getComment(),
73
-                'columns' => array_map(function ($column) {
73
+                'columns' => array_map(function($column) {
74 74
                     return [
75 75
                         'name' => $column->getName(),
76 76
                         'type' => $column->getType(),
@@ -81,9 +81,9 @@  discard block
 block discarded – undo
81 81
                         'nullable' => $column->isNullable()
82 82
                     ];
83 83
                 }, $table->getFullColumns()),
84
-                'relations' => array_map(function ($rel) {
84
+                'relations' => array_map(function($rel) {
85 85
                     $relation = clone $rel;
86
-                    $relation = (array)$relation;
86
+                    $relation = (array) $relation;
87 87
                     $relation['table'] = $rel->table->getName();
88 88
                     if ($rel->pivot) {
89 89
                         $relation['pivot'] = $rel->pivot->getName();
Please login to merge, or discard this patch.
src/driver/postgre/Statement.php 1 patch
Spacing   +12 added lines, -14 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
         if (strpos(strtolower($statement), 'prepare') === 0) {
24 24
             $this->drv->raw($this->statement);
25 25
             if (!isset($this->name)) {
26
-                $this->name = trim((preg_split('(\s+)', trim($this->statement))?:[])[1]??'', '"');
26
+                $this->name = trim((preg_split('(\s+)', trim($this->statement)) ?: [])[1] ?? '', '"');
27 27
             }
28 28
         } elseif ($this->name !== null) {
29 29
             $temp = \pg_prepare($this->driver, $this->name, $this->statement);
30 30
             if (!$temp) {
31 31
                 $log = $this->drv->option('log_file');
32
-                if ($log && (int)$this->drv->option('log_errors', 1)) {
32
+                if ($log && (int) $this->drv->option('log_errors', 1)) {
33 33
                     @file_put_contents(
34 34
                         $log,
35
-                        '--' . date('Y-m-d H:i:s') . ' ERROR PREPARING: ' . \pg_last_error($this->driver) . "\r\n" .
36
-                        $this->statement . "\r\n" .
35
+                        '--'.date('Y-m-d H:i:s').' ERROR PREPARING: '.\pg_last_error($this->driver)."\r\n".
36
+                        $this->statement."\r\n".
37 37
                         "\r\n",
38 38
                         FILE_APPEND
39 39
                     );
@@ -62,22 +62,20 @@  discard block
 block discarded – undo
62 62
         try {
63 63
             if ($this->name !== null) {
64 64
                 $temp = (is_array($data) && count($data)) ?
65
-                    \pg_execute($this->driver, $this->name, $data) :
66
-                    \pg_execute($this->driver, $this->name, array());
65
+                    \pg_execute($this->driver, $this->name, $data) : \pg_execute($this->driver, $this->name, array());
67 66
             } else {
68 67
                 $temp = (is_array($data) && count($data)) ?
69
-                    \pg_query_params($this->driver, $this->statement, $data) :
70
-                    \pg_query_params($this->driver, $this->statement, array());
68
+                    \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array());
71 69
             }
72 70
         } catch (\Exception $e) {
73 71
             $temp = false;
74 72
         }
75 73
         if (!$temp) {
76
-            if ($log && (int)$this->drv->option('log_errors', 1)) {
74
+            if ($log && (int) $this->drv->option('log_errors', 1)) {
77 75
                 @file_put_contents(
78 76
                     $log,
79
-                    '--' . date('Y-m-d H:i:s') . ' ERROR: ' . \pg_last_error($this->driver) . "\r\n" .
80
-                    $this->statement . "\r\n" .
77
+                    '--'.date('Y-m-d H:i:s').' ERROR: '.\pg_last_error($this->driver)."\r\n".
78
+                    $this->statement."\r\n".
81 79
                     "\r\n",
82 80
                     FILE_APPEND
83 81
                 );
@@ -86,11 +84,11 @@  discard block
 block discarded – undo
86 84
         }
87 85
         if ($log) {
88 86
             $tm = microtime(true) - $tm;
89
-            if ($tm >= (float)$this->drv->option('log_slow', 0)) {
87
+            if ($tm >= (float) $this->drv->option('log_slow', 0)) {
90 88
                 @file_put_contents(
91 89
                     $log,
92
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
93
-                    $this->statement . "\r\n" .
90
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
91
+                    $this->statement."\r\n".
94 92
                     "\r\n",
95 93
                     FILE_APPEND
96 94
                 );
Please login to merge, or discard this patch.
src/driver/mysql/Statement.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             foreach ($lng as $index) {
78 78
                 if (is_resource($data[$index]) && get_resource_type($data[$index]) === 'stream') {
79 79
                     while (!feof($data[$index])) {
80
-                        $this->statement->send_long_data($index, (string)fread($data[$index], $lds));
80
+                        $this->statement->send_long_data($index, (string) fread($data[$index], $lds));
81 81
                     }
82 82
                 } else {
83 83
                     $data[$index] = str_split($data[$index], $lds);
@@ -97,24 +97,24 @@  discard block
 block discarded – undo
97 97
             $res = false;
98 98
         }
99 99
         if (!$res) {
100
-            if ($log && (int)$this->driver->option('log_errors', 1)) {
100
+            if ($log && (int) $this->driver->option('log_errors', 1)) {
101 101
                 @file_put_contents(
102 102
                     $log,
103
-                    '--' . date('Y-m-d H:i:s') . ' ERROR: ' . $this->statement->error . "\r\n" .
104
-                    $this->sql . "\r\n" .
103
+                    '--'.date('Y-m-d H:i:s').' ERROR: '.$this->statement->error."\r\n".
104
+                    $this->sql."\r\n".
105 105
                     "\r\n",
106 106
                     FILE_APPEND
107 107
                 );
108 108
             }
109
-            throw new DBException('Prepared execute error: ' . $this->statement->error);
109
+            throw new DBException('Prepared execute error: '.$this->statement->error);
110 110
         }
111 111
         if ($log) {
112 112
             $tm = microtime(true) - $tm;
113
-            if ($tm >= (float)$this->driver->option('log_slow', 0)) {
113
+            if ($tm >= (float) $this->driver->option('log_slow', 0)) {
114 114
                 @file_put_contents(
115 115
                     $log,
116
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
117
-                    $this->sql . "\r\n" .
116
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
117
+                    $this->sql."\r\n".
118 118
                     "\r\n",
119 119
                     FILE_APPEND
120 120
                 );
Please login to merge, or discard this patch.
src/driver/sqlite/Driver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
         if ($this->lnk === null) {
39 39
             try {
40 40
                 $this->lnk = new \SQLite3($this->connection['name']);
41
-                $this->lnk->exec('PRAGMA encoding = "'.$this->option('charset', 'utf-8') . '"');
41
+                $this->lnk->exec('PRAGMA encoding = "'.$this->option('charset', 'utf-8').'"');
42 42
             } catch (\Exception $e) {
43 43
                 if ($this->lnk !== null) {
44 44
                     throw new DBException('Connect error: '.$this->lnk->lastErrorMsg());
Please login to merge, or discard this patch.
src/schema/TableColumn.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
             $instance->setNullable($data['nullable']);
43 43
         }
44 44
         if (isset($data['notnull'])) {
45
-            $instance->setNullable(!((int)$data['notnull']));
45
+            $instance->setNullable(!((int) $data['notnull']));
46 46
         }
47 47
         if (isset($data['Default'])) {
48 48
             $instance->setDefault($data['Default']);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             $instance->setLength($data['length']);
58 58
         }
59 59
         if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
60
-            $temp = array_map(function ($v) {
60
+            $temp = array_map(function($v) {
61 61
                 return str_replace("''", "'", $v);
62 62
             }, explode("','", substr($instance->getType(), 6, -2)));
63 63
             $instance->setValues($temp);
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 $instance->setDefault(null);
87 87
             }
88 88
         }
89
-        if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int)$data['CHAR_LENGTH']) {
89
+        if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int) $data['CHAR_LENGTH']) {
90 90
             $instance->setLength($data['CHAR_LENGTH']);
91 91
         }
92 92
         return $instance;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
     }
184 184
     public function getLength(): int
185 185
     {
186
-        return (int)$this->length;
186
+        return (int) $this->length;
187 187
     }
188 188
     public function setLength(int $length): static
189 189
     {
Please login to merge, or discard this patch.
src/driver/sqlite/Schema.php 1 patch
Spacing   +22 added lines, -22 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,15 +86,15 @@  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('');
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
             // assuming current table is on the "one" end having "many" records in the referencing table
105 105
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
106 106
             $relations = [];
107
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
108
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
107
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
108
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
109 109
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
110 110
             }
111 111
             foreach ($relations as $data) {
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
                 $usedcol = [];
121 121
                 if (count($columns)) {
122 122
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
123
-                        ->filter(function ($v) use ($columns) {
123
+                        ->filter(function($v) use ($columns) {
124 124
                             return in_array($v['from'], $columns);
125 125
                         }) as $relation
126 126
                     ) {
127
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
127
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
128 128
                             $relation['referenced_table'];
129 129
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
130 130
                         $usedcol[] = $relation['from'];
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                         $definition->getName() == $relname ||
144 144
                         $definition->getColumn($relname)
145 145
                     ) {
146
-                        $relname = $orig . '_' . (++ $cntr);
146
+                        $relname = $orig.'_'.(++$cntr);
147 147
                     }
148 148
                     $definition->addRelation(
149 149
                         new TableRelation(
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
                         $definition->getName() == $relname ||
168 168
                         $definition->getColumn($relname)
169 169
                     ) {
170
-                        $relname = $orig . '_' . (++ $cntr);
170
+                        $relname = $orig.'_'.(++$cntr);
171 171
                     }
172 172
                     $definition->addRelation(
173 173
                         new TableRelation(
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
             // assuming current table is linked to "one" record in the referenced table
184 184
             // resulting in a "belongsTo" relationship
185 185
             $relations = [];
186
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
187
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table'];
186
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
187
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table'];
188 188
                 $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
189 189
             }
190 190
             foreach ($relations as $name => $data) {
@@ -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(
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
                 "SELECT tbl_name
221 221
                  FROM sqlite_schema
222 222
                  WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';",
223
-                [ 'table', 'view' ]
223
+                ['table', 'view']
224 224
             ))
225
-            ->mapKey(function ($v) {
225
+            ->mapKey(function($v) {
226 226
                 return strtolower($v['tbl_name']);
227 227
             })
228 228
             ->pluck('tbl_name')
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
             $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase();
232 232
         }
233 233
         foreach (array_keys($tables) as $k) {
234
-            $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k];
234
+            $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k];
235 235
         }
236 236
         return $tables;
237 237
     }
Please login to merge, or discard this patch.
src/schema/TableQueryMapped.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
     public function __construct(
21 21
         DBInterface $db,
22
-        Table|string $table,
22
+        Table | string $table,
23 23
         bool $findRelations = false,
24 24
         ?MapperInterface $mapper = null
25 25
     ) {
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public function iterator(array $fields = null, array $collectionKey = null): Collection
35 35
     {
36 36
         return Collection::from(parent::iterator($fields, $collectionKey))
37
-            ->map(function ($v) {
37
+            ->map(function($v) {
38 38
                 return $this->mapper->entity($v);
39 39
             })
40 40
             ->values();
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +27 added lines, -29 removed lines patch added patch discarded remove patch
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
                 ];
75 75
             }
76 76
         }
77
-        $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null;
78
-        $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null;
79
-        $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null;
80
-        $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null;
81
-        $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ?
82
-            trim((string)$temp['path'], '/') : null;
83
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
84
-        if (isset($temp['query']) && strlen((string)$temp['query'])) {
85
-            parse_str((string)$temp['query'], $connection['opts']);
77
+        $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null;
78
+        $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null;
79
+        $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null;
80
+        $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null;
81
+        $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ?
82
+            trim((string) $temp['path'], '/') : null;
83
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
84
+        if (isset($temp['query']) && strlen((string) $temp['query'])) {
85
+            parse_str((string) $temp['query'], $connection['opts']);
86 86
         }
87 87
         // create the driver
88 88
         $connection['type'] = $aliases[$connection['type']] ?? $connection['type'];
89
-        $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver';
89
+        $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver';
90 90
         if (!class_exists($tmp)) {
91 91
             throw new DBException('Unknown DB backend');
92 92
         }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         $new = '';
125 125
         $par = array_values($par);
126 126
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
127
-            $par = [ $par ];
127
+            $par = [$par];
128 128
         }
129 129
         $parts = explode('??', $sql);
130 130
         $index = 0;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
             $index += count($tmp) - 1;
135 135
             if (isset($par[$index])) {
136 136
                 if (!is_array($par[$index])) {
137
-                    $par[$index] = [ $par[$index] ];
137
+                    $par[$index] = [$par[$index]];
138 138
                 }
139 139
                 $params = $par[$index];
140 140
                 array_splice($par, $index, 1, $params);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                 $new .= implode(',', array_fill(0, count($params), '?'));
143 143
             }
144 144
         }
145
-        return [ $new, $par ];
145
+        return [$new, $par];
146 146
     }
147 147
     /**
148 148
      * Run a query (prepare & execute).
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     ): Collection {
192 192
         $coll = Collection::from($this->query($sql, $par, $buff));
193 193
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
194
-            $coll->map(function ($v) use ($keys) {
194
+            $coll->map(function($v) use ($keys) {
195 195
                 $new = [];
196 196
                 foreach ($v as $k => $vv) {
197 197
                     $new[call_user_func($keys, $k)] = $vv;
@@ -200,18 +200,18 @@  discard block
 block discarded – undo
200 200
             });
201 201
         }
202 202
         if ($key !== null) {
203
-            $coll->mapKey(function ($v) use ($key): int|string {
203
+            $coll->mapKey(function($v) use ($key): int | string {
204 204
                 return $v[$key];
205 205
             });
206 206
         }
207 207
         if ($skip) {
208
-            $coll->map(function ($v) use ($key) {
208
+            $coll->map(function($v) use ($key) {
209 209
                 unset($v[$key]);
210 210
                 return $v;
211 211
             });
212 212
         }
213 213
         if ($opti) {
214
-            $coll->map(function ($v) {
214
+            $coll->map(function($v) {
215 215
                 return count($v) === 1 ? current($v) : $v;
216 216
             });
217 217
         }
@@ -328,8 +328,7 @@  discard block
 block discarded – undo
328 328
     public function definition(string $table, bool $detectRelations = true) : Table
329 329
     {
330 330
         return isset($this->schema) ?
331
-            $this->schema->getTable($table) :
332
-            $this->driver->table($table, $detectRelations);
331
+            $this->schema->getTable($table) : $this->driver->table($table, $detectRelations);
333 332
     }
334 333
 
335 334
     public function hasSchema(): bool
@@ -439,11 +438,11 @@  discard block
 block discarded – undo
439 438
      * @param class-string<T>|Table|string $table
440 439
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
441 440
      */
442
-    public function getMapper(Table|string $table): MapperInterface
441
+    public function getMapper(Table | string $table): MapperInterface
443 442
     {
444 443
         if (is_string($table)) {
445
-            if (isset($this->mappers['::' . $table])) {
446
-                return $this->mappers['::' . $table];
444
+            if (isset($this->mappers['::'.$table])) {
445
+                return $this->mappers['::'.$table];
447 446
             }
448 447
             $table = $this->definition($table);
449 448
         }
@@ -452,14 +451,14 @@  discard block
 block discarded – undo
452 451
         }
453 452
         return $this->mappers[$table->getFullName()] = new Mapper($this, $table);
454 453
     }
455
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static
454
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static
456 455
     {
457 456
         if (is_string($table)) {
458 457
             $table = $this->definition($table);
459 458
         }
460 459
         $this->mappers[$table->getFullName()] = $mapper;
461 460
         if (isset($class)) {
462
-            $this->mappers['::' . $class] = $mapper;
461
+            $this->mappers['::'.$class] = $mapper;
463 462
         }
464 463
         return $this;
465 464
     }
@@ -470,11 +469,10 @@  discard block
 block discarded – undo
470 469
     ): TableQueryMapped {
471 470
         return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper);
472 471
     }
473
-    public function __call(string $method, array $args): TableQuery|TableQueryMapped
472
+    public function __call(string $method, array $args): TableQuery | TableQueryMapped
474 473
     {
475 474
         return ($args[0] ?? false) ?
476
-            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) :
477
-            $this->table($method, $args[1] ?? false);
475
+            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false);
478 476
     }
479 477
     public function findRelation(string $start, string $end): array
480 478
     {
@@ -510,12 +508,12 @@  discard block
 block discarded – undo
510 508
                     $relations[$t] = $w;
511 509
                 }
512 510
                 if (!isset($schema[$name])) {
513
-                    $schema[$name] = [ 'edges' => [] ];
511
+                    $schema[$name] = ['edges' => []];
514 512
                 }
515 513
                 foreach ($relations as $t => $w) {
516 514
                     $schema[$name]['edges'][$t] = $w;
517 515
                     if (!isset($schema[$t])) {
518
-                        $schema[$t] = [ 'edges' => [] ];
516
+                        $schema[$t] = ['edges' => []];
519 517
                     }
520 518
                     $schema[$t]['edges'][$name] = $w;
521 519
                 }
Please login to merge, or discard this patch.