Completed
Push — master ( 8061c1...bbde74 )
by Ivan
11:14
created
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/driver/oracle/Schema.php 1 patch
Spacing   +26 added lines, -26 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 all_tab_cols WHERE UPPER(table_name) = ? AND UPPER(owner) = ? and hidden_column = 'NO'",
35
-                [ strtoupper($table), strtoupper($this->name()) ]
35
+                [strtoupper($table), strtoupper($this->name())]
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;
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
             ->query(
73 73
                 "SELECT constraint_name FROM all_constraints
74 74
                 WHERE table_name = ? AND constraint_type = ? AND UPPER(owner) = ?",
75
-                [ strtoupper($table), 'P', $owner ]
75
+                [strtoupper($table), 'P', $owner]
76 76
             ))
77
-            ->map(function ($v) {
77
+            ->map(function($v) {
78 78
                 $new = [];
79 79
                 foreach ($v as $kk => $vv) {
80 80
                     $new[strtoupper($kk)] = $vv;
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
                 ->query(
90 90
                     "SELECT column_name FROM all_cons_columns
91 91
                     WHERE table_name = ? AND constraint_name = ? AND UPPER(owner) = ?",
92
-                    [ strtoupper($table), $pkname, $owner ]
92
+                    [strtoupper($table), $pkname, $owner]
93 93
                 ))
94
-                ->map(function ($v) {
94
+                ->map(function($v) {
95 95
                     $new = [];
96 96
                     foreach ($v as $kk => $vv) {
97 97
                         $new[strtoupper($kk)] = $vv;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
                         UPPER(ac.OWNER) = ? AND UPPER(ac.R_OWNER) = ? AND
121 121
                         ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
122 122
                     ORDER BY cc.POSITION",
123
-                    [ $owner, $owner, $pkname, 'R' ]
123
+                    [$owner, $owner, $pkname, '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;
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                  as $relation
133 133
             ) {
134 134
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
135
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
135
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
136 136
                     $relation['COLUMN_NAME'];
137 137
             }
138 138
             foreach ($relations as $data) {
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
                                 ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
164 164
                                 cc.COLUMN_NAME IN (??)
165 165
                             ORDER BY POSITION",
166
-                            [ $owner, $owner, $data['table'], 'R', $columns ]
166
+                            [$owner, $owner, $data['table'], 'R', $columns]
167 167
                         ))
168
-                        ->map(function ($v) {
168
+                        ->map(function($v) {
169 169
                             $new = [];
170 170
                             foreach ($v as $kk => $vv) {
171 171
                                 $new[strtoupper($kk)] = $vv;
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
                         ->query(
186 186
                             "SELECT COLUMN_NAME FROM all_cons_columns
187 187
                              WHERE UPPER(OWNER) = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
188
-                            [ $owner, current($foreign['keymap']) ]
188
+                            [$owner, current($foreign['keymap'])]
189 189
                         ))
190
-                        ->map(function ($v) {
190
+                        ->map(function($v) {
191 191
                             $new = [];
192 192
                             foreach ($v as $kk => $vv) {
193 193
                                 $new[strtoupper($kk)] = $vv;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                     $relname = $foreign['table'];
203 203
                     $cntr = 1;
204 204
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
205
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
205
+                        $relname = $foreign['table'].'_'.(++$cntr);
206 206
                     }
207 207
                     $definition->addRelation(
208 208
                         new TableRelation(
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                     $relname = $data['table'];
219 219
                     $cntr = 1;
220 220
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
221
-                        $relname = $data['table'] . '_' . (++ $cntr);
221
+                        $relname = $data['table'].'_'.(++$cntr);
222 222
                     }
223 223
                     $definition->addRelation(
224 224
                         new TableRelation(
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
247 247
                     WHERE UPPER(ac.OWNER) = ? AND UPPER(ac.R_OWNER) = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
248 248
                     ORDER BY cc.POSITION",
249
-                    [ $owner, $owner, strtoupper($table), 'R' ]
249
+                    [$owner, $owner, strtoupper($table), 'R']
250 250
                 ))
251
-                ->map(function ($v) {
251
+                ->map(function($v) {
252 252
                     $new = [];
253 253
                     foreach ($v as $kk => $vv) {
254 254
                         $new[strtoupper($kk)] = $vv;
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
                     ->query(
267 267
                         "SELECT COLUMN_NAME FROM all_cons_columns
268 268
                          WHERE UPPER(OWNER) = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
269
-                        [ $owner, current($data['keymap']) ]
269
+                        [$owner, 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;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $relname = $data['table'];
284 284
                 $cntr = 1;
285 285
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
286
-                    $relname = $data['table'] . '_' . (++ $cntr);
286
+                    $relname = $data['table'].'_'.(++$cntr);
287 287
                 }
288 288
                 $definition->addRelation(
289 289
                     new TableRelation(
@@ -306,18 +306,18 @@  discard block
 block discarded – undo
306 306
                  SELECT VIEW_NAME AS TABLE_NAME FROM ALL_VIEWS where UPPER(OWNER) = ?",
307 307
                 [strtoupper($this->connection['name']), strtoupper($this->connection['name'])]
308 308
             ))
309
-            ->map(function ($v) {
309
+            ->map(function($v) {
310 310
                 $new = [];
311 311
                 foreach ($v as $kk => $vv) {
312 312
                     $new[strtoupper($kk)] = $vv;
313 313
                 }
314 314
                 return $new;
315 315
             })
316
-            ->mapKey(function ($v) {
316
+            ->mapKey(function($v) {
317 317
                 return strtolower($v['TABLE_NAME']);
318 318
             })
319 319
             ->pluck('TABLE_NAME')
320
-            ->map(function ($v) {
320
+            ->map(function($v) {
321 321
                 return $this->table($v)->toLowerCase();
322 322
             })
323 323
             ->toArray();
Please login to merge, or discard this patch.
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
         }
@@ -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,20 +127,20 @@  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
                 return $v;
134 134
             })
135 135
             ->toArray();
136 136
         if (!count($columns)) {
137
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
137
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
138 138
         }
139 139
         $pkname = Collection::from($this
140 140
             ->query(
141 141
                 "SELECT constraint_name FROM information_schema.table_constraints
142 142
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?",
143
-                [ $table, 'PRIMARY KEY', $schema, $catalog ]
143
+                [$table, 'PRIMARY KEY', $schema, $catalog]
144 144
             ))
145 145
             ->pluck('constraint_name')
146 146
             ->value();
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
                 ->query(
151 151
                     "SELECT column_name FROM information_schema.constraint_column_usage
152 152
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?",
153
-                    [ $table, $pkname, $schema, $catalog ]
153
+                    [$table, $pkname, $schema, $catalog]
154 154
                 ))
155 155
                 ->pluck('column_name')
156 156
                 ->toArray();
157 157
         }
158
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
158
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
159 159
             ->addColumns($columns)
160 160
             ->setPrimaryKey($primary)
161 161
             ->setComment('');
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             // assuming current table is on the "one" end having "many" records in the referencing table
166 166
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
167 167
             $relations = [];
168
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
169
-                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' .
168
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
169
+                $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'.
170 170
                     $relation['table_name'];
171 171
                 $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] =
172 172
                     $relation['column_name'];
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
                 $usedcol = [];
184 184
                 if (count($columns)) {
185 185
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
186
-                        ->filter(function ($v) use ($columns) {
186
+                        ->filter(function($v) use ($columns) {
187 187
                             return in_array($v['column_name'], $columns);
188 188
                         }) as $relation
189 189
                     ) {
190
-                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
190
+                        $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
191 191
                             $relation['referenced_table_name'];
192 192
                         $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] =
193 193
                             $relation['referenced_column_name'];
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                         $definition->getName() == $relname ||
208 208
                         $definition->getColumn($relname)
209 209
                     ) {
210
-                        $relname = $orig . '_' . (++ $cntr);
210
+                        $relname = $orig.'_'.(++$cntr);
211 211
                     }
212 212
                     $definition->addRelation(
213 213
                         new TableRelation(
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
                         $definition->getName() == $relname ||
232 232
                         $definition->getColumn($relname)
233 233
                     ) {
234
-                        $relname = $orig . '_' . (++ $cntr);
234
+                        $relname = $orig.'_'.(++$cntr);
235 235
                     }
236 236
                     $definition->addRelation(
237 237
                         new TableRelation(
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
             // assuming current table is linked to "one" record in the referenced table
248 248
             // resulting in a "belongsTo" relationship
249 249
             $relations = [];
250
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
251
-                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' .
250
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
251
+                $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.
252 252
                     $relation['referenced_table_name'];
253 253
                 $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] =
254 254
                     $relation['referenced_column_name'];
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
                     $definition->getName() == $relname ||
266 266
                     $definition->getColumn($relname)
267 267
                 ) {
268
-                    $relname = $orig . '_' . (++ $cntr);
268
+                    $relname = $orig.'_'.(++$cntr);
269 269
                 }
270 270
                 $definition->addRelation(
271 271
                     new TableRelation(
@@ -284,19 +284,19 @@  discard block
 block discarded – undo
284 284
         $tables = Collection::from($this
285 285
             ->query(
286 286
                 "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?",
287
-                [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ]
287
+                [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']]
288 288
             ))
289
-            ->mapKey(function ($v) {
289
+            ->mapKey(function($v) {
290 290
                 return strtolower($v['table_name']);
291 291
             })
292 292
             ->pluck('table_name')
293
-            ->map(function ($v) {
293
+            ->map(function($v) {
294 294
                 return $this->table($v)->toLowerCase();
295 295
             })
296 296
             ->toArray();
297 297
 
298 298
         foreach (array_keys($tables) as $k) {
299
-            $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k];
299
+            $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k];
300 300
         }
301 301
         return $tables;
302 302
     }
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +254 added lines, -258 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     protected array $order = [];
23 23
     protected array $group = [];
24 24
     protected array $having = [];
25
-    protected array $li_of = [0,0,0];
25
+    protected array $li_of = [0, 0, 0];
26 26
     protected array $fields = [];
27 27
     protected array $withr = [];
28 28
     protected array $joins = [];
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
      * @param  Table|string   $table           the name or definition of the main table in the query
37 37
      * @param  bool           $findRelations   should the query builder try to find missing joins
38 38
      */
39
-    public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false)
39
+    public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false)
40 40
     {
41 41
         $this->db = $db;
42 42
         $this->findRelations = $findRelations;
43
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
43
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
44 44
         $primary = $this->definition->getPrimaryKey();
45 45
         $columns = $this->definition->getColumns();
46 46
         $this->pkey = count($primary) ? $primary : $columns;
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $column = explode('.', $column);
65 65
         if (count($column) === 1) {
66
-            $column = [ $this->definition->getFullName(), $column[0] ];
66
+            $column = [$this->definition->getFullName(), $column[0]];
67 67
             $col = $this->definition->getColumn($column[1]);
68 68
             if (!$col) {
69 69
                 throw new DBException('Invalid column name in own table');
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                             $path = $this->db->findRelation($this->definition->getName(), $column[0]);
103 103
                         }
104 104
                         if (!count($path)) {
105
-                            throw new DBException('Invalid foreign table / column name: ' . implode(',', $column));
105
+                            throw new DBException('Invalid foreign table / column name: '.implode(',', $column));
106 106
                         }
107 107
                         unset($path[0]);
108 108
                         $this->with(implode('.', $path), false);
@@ -115,26 +115,26 @@  discard block
 block discarded – undo
115 115
             if ($this->definition->hasRelation(implode('.', $column))) {
116 116
                 $this->with(implode('.', $column), false);
117 117
                 $col = $this->definition->getRelation(implode('.', $column))?->table?->getColumn($name);
118
-                $column = [ implode('.', $column), $name ];
118
+                $column = [implode('.', $column), $name];
119 119
             } else {
120 120
                 $this->with(implode('.', $column), false);
121 121
                 $table = $this->definition;
122 122
                 $table = array_reduce(
123 123
                     $column,
124
-                    function ($carry, $item) use (&$table) {
124
+                    function($carry, $item) use (&$table) {
125 125
                         $table = $table->getRelation($item)->table;
126 126
                         return $table;
127 127
                     }
128 128
                 );
129 129
                 $col = $table->getColumn($name);
130
-                $column = [ implode(static::SEP, $column), $name ];
130
+                $column = [implode(static::SEP, $column), $name];
131 131
             }
132 132
         }
133
-        return [ 'name' => implode('.', $column), 'data' => $col ];
133
+        return ['name' => implode('.', $column), 'data' => $col];
134 134
     }
135 135
     protected function normalizeValue(TableColumn $col, mixed $value): mixed
136 136
     {
137
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
137
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
138 138
         if ($value === null && $col->isNullable()) {
139 139
             return null;
140 140
         }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                     $temp = strtotime($value);
145 145
                     if (!$temp) {
146 146
                         if ($strict) {
147
-                            throw new DBException('Invalid value for date column ' . $col->getName());
147
+                            throw new DBException('Invalid value for date column '.$col->getName());
148 148
                         }
149 149
                         return null;
150 150
                     }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                     return $value->format('Y-m-d');
158 158
                 }
159 159
                 if ($strict) {
160
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
160
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
161 161
                 }
162 162
                 return $value;
163 163
             case 'datetime':
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                     $temp = strtotime($value);
166 166
                     if (!$temp) {
167 167
                         if ($strict) {
168
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
168
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
169 169
                         }
170 170
                         return null;
171 171
                     }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                     return $value->format('Y-m-d H:i:s');
179 179
                 }
180 180
                 if ($strict) {
181
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
181
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
182 182
                 }
183 183
                 return $value;
184 184
             case 'enum':
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
                 if (is_int($value)) {
187 187
                     if (!isset($values[$value])) {
188 188
                         if ($strict) {
189
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
189
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
190 190
                         }
191 191
                         return $value;
192 192
                     }
@@ -194,23 +194,23 @@  discard block
 block discarded – undo
194 194
                 }
195 195
                 if (!in_array($value, $col->getValues())) {
196 196
                     if ($strict) {
197
-                        throw new DBException('Invalid value for enum ' . $col->getName());
197
+                        throw new DBException('Invalid value for enum '.$col->getName());
198 198
                     }
199 199
                     return 0;
200 200
                 }
201 201
                 return $value;
202 202
             case 'int':
203 203
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
204
-                return is_string($temp) ? (int)$temp : 0;
204
+                return is_string($temp) ? (int) $temp : 0;
205 205
             case 'float':
206 206
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
207
-                return is_string($temp) ? (float)$temp : 0;
207
+                return is_string($temp) ? (float) $temp : 0;
208 208
             case 'text':
209 209
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
210 210
                 // because the polyfill is quite slow
211 211
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
212 212
                     if ($strict) {
213
-                        throw new DBException('Invalid value for text column ' . $col->getName());
213
+                        throw new DBException('Invalid value for text column '.$col->getName());
214 214
                     }
215 215
                     return mb_substr($value, 0, $col->getLength());
216 216
                 }
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             if ($column->getBasicType() !== 'text') {
235 235
                 switch ($this->db->driverName()) {
236 236
                     case 'oracle':
237
-                        $name = 'CAST(' . $name . ' AS NVARCHAR(500))';
237
+                        $name = 'CAST('.$name.' AS NVARCHAR(500))';
238 238
                         break;
239 239
                     case 'postgre':
240 240
                         $name = $name.'::text';
@@ -242,45 +242,42 @@  discard block
 block discarded – undo
242 242
                 }
243 243
             }
244 244
             $mode = array_keys($value)[0];
245
-            $value = str_replace(['%', '_'], ['\\%','\\_'], array_values($value)[0]) . '%';
245
+            $value = str_replace(['%', '_'], ['\\%', '\\_'], array_values($value)[0]).'%';
246 246
             if ($mode === 'contains' || $mode === 'icontains') {
247
-                $value = '%' . $value;
247
+                $value = '%'.$value;
248 248
             }
249 249
             if ($mode === 'icontains' || $mode === 'ilike') {
250 250
                 $value = mb_strtoupper($value);
251
-                $name = 'UPPER(' . $name . ')';
251
+                $name = 'UPPER('.$name.')';
252 252
             }
253 253
             return $negate ?
254 254
                 [
255
-                    $name . ' NOT LIKE ?',
256
-                    [ (string)$value ]
257
-                ] :
258
-                [
259
-                    $name . ' LIKE ?',
260
-                    [ (string)$value ]
255
+                    $name.' NOT LIKE ?',
256
+                    [(string) $value]
257
+                ] : [
258
+                    $name.' LIKE ?',
259
+                    [(string) $value]
261 260
                 ];
262 261
         }
263 262
         if (is_null($value)) {
264 263
             return $negate ?
265
-                [ $name . ' IS NOT NULL', [] ]:
266
-                [ $name . ' IS NULL', [] ];
264
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
267 265
         }
268 266
         if (!is_array($value)) {
269 267
             return $negate ?
270 268
                 [
271
-                    $name . ' <> ?',
272
-                    [ $this->normalizeValue($column, $value) ]
273
-                ] :
274
-                [
275
-                    $name . ' = ?',
276
-                    [ $this->normalizeValue($column, $value) ]
269
+                    $name.' <> ?',
270
+                    [$this->normalizeValue($column, $value)]
271
+                ] : [
272
+                    $name.' = ?',
273
+                    [$this->normalizeValue($column, $value)]
277 274
                 ];
278 275
         }
279 276
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
280
-            $value = [ 'gte' => $value['beg'] ];
277
+            $value = ['gte' => $value['beg']];
281 278
         }
282 279
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
283
-            $value = [ 'lte' => $value['end'] ];
280
+            $value = ['lte' => $value['end']];
284 281
         }
285 282
         if (isset($value['beg']) && isset($value['end'])) {
286 283
             return $negate ?
@@ -290,8 +287,7 @@  discard block
 block discarded – undo
290 287
                         $this->normalizeValue($column, $value['beg']),
291 288
                         $this->normalizeValue($column, $value['end'])
292 289
                     ]
293
-                ] :
294
-                [
290
+                ] : [
295 291
                     $name.' BETWEEN ? AND ?',
296 292
                     [
297 293
                         $this->normalizeValue($column, $value['beg']),
@@ -303,42 +299,42 @@  discard block
 block discarded – undo
303 299
             $sql = [];
304 300
             $par = [];
305 301
             if (isset($value['gt'])) {
306
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
302
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
307 303
                 $par[] = $this->normalizeValue($column, $value['gt']);
308 304
             }
309 305
             if (isset($value['gte'])) {
310
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
306
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
311 307
                 $par[] = $this->normalizeValue($column, $value['gte']);
312 308
             }
313 309
             if (isset($value['lt'])) {
314
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
310
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
315 311
                 $par[] = $this->normalizeValue($column, $value['lt']);
316 312
             }
317 313
             if (isset($value['lte'])) {
318
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
314
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
319 315
                 $par[] = $this->normalizeValue($column, $value['lte']);
320 316
             }
321 317
             return [
322
-                '(' . implode(' AND ', $sql) . ')',
318
+                '('.implode(' AND ', $sql).')',
323 319
                 $par
324 320
             ];
325 321
         }
326 322
 
327
-        $value = array_values(array_map(function ($v) use ($column) {
323
+        $value = array_values(array_map(function($v) use ($column) {
328 324
             return $this->normalizeValue($column, $v);
329 325
         }, $value));
330 326
         if ($this->db->driverName() === 'oracle') {
331 327
             $sql = [];
332 328
             $par = [];
333 329
             for ($i = 0; $i < count($value); $i += 500) {
334
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
330
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
335 331
                 $par[] = array_slice($value, $i, 500);
336 332
             }
337
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
338
-            return [ $sql, $par ];
333
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
334
+            return [$sql, $par];
339 335
         }
340 336
         return [
341
-            $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)',
337
+            $negate ? $name.' NOT IN (??)' : $name.' IN (??)',
342 338
             [$value]
343 339
         ];
344 340
     }
@@ -370,7 +366,7 @@  discard block
 block discarded – undo
370 366
                 $par = array_merge($par, $temp[1]);
371 367
             }
372 368
         }
373
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
369
+        return $this->where('('.implode(' OR ', $sql).')', $par);
374 370
     }
375 371
     /**
376 372
      * Filter the results matching all of the criteria
@@ -388,7 +384,7 @@  discard block
 block discarded – undo
388 384
                 $par = array_merge($par, $temp[1]);
389 385
             }
390 386
         }
391
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
387
+        return $this->where('('.implode(' AND ', $sql).')', $par);
392 388
     }
393 389
     /**
394 390
      * Sort by a column
@@ -403,7 +399,7 @@  discard block
 block discarded – undo
403 399
         } catch (DBException $e) {
404 400
             throw new DBException('Invalid sort column');
405 401
         }
406
-        return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC'));
402
+        return $this->order($column.' '.($desc ? 'DESC' : 'ASC'));
407 403
     }
408 404
     /**
409 405
      * Group by a column (or columns)
@@ -413,7 +409,7 @@  discard block
 block discarded – undo
413 409
     public function group($column) : static
414 410
     {
415 411
         if (!is_array($column)) {
416
-            $column = [ $column ];
412
+            $column = [$column];
417 413
         }
418 414
         foreach ($column as $k => $v) {
419 415
             $column[$k] = $this->getColumn($v)['name'];
@@ -456,7 +452,7 @@  discard block
 block discarded – undo
456 452
         $this->order = [];
457 453
         $this->having = [];
458 454
         $this->aliases = [];
459
-        $this->li_of = [0,0,0];
455
+        $this->li_of = [0, 0, 0];
460 456
         $this->qiterator = null;
461 457
         return $this;
462 458
     }
@@ -469,7 +465,7 @@  discard block
 block discarded – undo
469 465
     public function groupBy(string $sql, array $params = []) : static
470 466
     {
471 467
         $this->qiterator = null;
472
-        $this->group = [ $sql, $params ];
468
+        $this->group = [$sql, $params];
473 469
         return $this;
474 470
     }
475 471
     /**
@@ -483,7 +479,7 @@  discard block
 block discarded – undo
483 479
     public function join($table, array $fields, string $name = null, bool $multiple = true)
484 480
     {
485 481
         $this->qiterator = null;
486
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
482
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
487 483
         $name = $name ?? $table->getName();
488 484
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
489 485
             throw new DBException('Alias / table name already in use');
@@ -492,7 +488,7 @@  discard block
 block discarded – undo
492 488
         foreach ($fields as $k => $v) {
493 489
             $k = explode('.', $k, 2);
494 490
             $k = count($k) == 2 ? $k[1] : $k[0];
495
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
491
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
496 492
         }
497 493
         return $this;
498 494
     }
@@ -505,7 +501,7 @@  discard block
 block discarded – undo
505 501
     public function where(string $sql, array $params = []) : static
506 502
     {
507 503
         $this->qiterator = null;
508
-        $this->where[] = [ $sql, $params ];
504
+        $this->where[] = [$sql, $params];
509 505
         return $this;
510 506
     }
511 507
     /**
@@ -517,7 +513,7 @@  discard block
 block discarded – undo
517 513
     public function having(string $sql, array $params = []) : static
518 514
     {
519 515
         $this->qiterator = null;
520
-        $this->having[] = [ $sql, $params ];
516
+        $this->having[] = [$sql, $params];
521 517
         return $this;
522 518
     }
523 519
     /**
@@ -537,12 +533,12 @@  discard block
 block discarded – undo
537 533
                     throw new \Exception();
538 534
                 }
539 535
                 $name = $this->getColumn(trim($name))['name'];
540
-                $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
536
+                $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
541 537
             } catch (\Exception $e) {
542 538
                 $name = null;
543 539
             }
544 540
         }
545
-        $this->order = [ $sql, $params, $name ];
541
+        $this->order = [$sql, $params, $name];
546 542
         return $this;
547 543
     }
548 544
     /**
@@ -554,7 +550,7 @@  discard block
 block discarded – undo
554 550
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : static
555 551
     {
556 552
         $this->qiterator = null;
557
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
553
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
558 554
         return $this;
559 555
     }
560 556
     /**
@@ -565,9 +561,9 @@  discard block
 block discarded – undo
565 561
     {
566 562
         $aliases = [];
567 563
         $aliases_ext = [];
568
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
564
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
569 565
             // to bypass use: return $name;
570
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
566
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
571 567
             if (isset($aliases_ext[$name])) {
572 568
                 unset($aliases_ext[$name]);
573 569
             }
@@ -590,7 +586,7 @@  discard block
 block discarded – undo
590 586
         $h = $this->having;
591 587
         $o = $this->order;
592 588
         $g = $this->group;
593
-        $j = array_map(function ($v) {
589
+        $j = array_map(function($v) {
594 590
             return clone $v;
595 591
         }, $this->joins);
596 592
 
@@ -600,28 +596,28 @@  discard block
 block discarded – undo
600 596
                 continue;
601 597
             }
602 598
             foreach ($w as $kk => $v) {
603
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
599
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
604 600
                     $used_relations[] = $k;
605
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
601
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
606 602
                 }
607 603
             }
608 604
             foreach ($h as $kk => $v) {
609
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
605
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
610 606
                     $used_relations[] = $k;
611
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
607
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
612 608
                 }
613 609
             }
614
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
610
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
615 611
                 $used_relations[] = $k;
616
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
612
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
617 613
             }
618 614
             foreach ($j as $kk => $v) {
619 615
                 foreach ($v->keymap as $kkk => $vv) {
620
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
616
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
621 617
                         $used_relations[] = $k;
622 618
                         $j[$kk]->keymap[$kkk] = preg_replace(
623
-                            '(\b'.preg_quote($k . '.'). ')i',
624
-                            $getAlias($k) . '.',
619
+                            '(\b'.preg_quote($k.'.').')i',
620
+                            $getAlias($k).'.',
625 621
                             $vv
626 622
                         );
627 623
                     }
@@ -630,65 +626,65 @@  discard block
 block discarded – undo
630 626
         }
631 627
         foreach ($this->definition->getRelations() as $k => $v) {
632 628
             foreach ($w as $kk => $vv) {
633
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
634
-                    $relations[$k] = [ $v, $table ];
629
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
630
+                    $relations[$k] = [$v, $table];
635 631
                     $used_relations[] = $k;
636
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
632
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
637 633
                 }
638 634
             }
639
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
640
-                $relations[$k] = [ $v, $table ];
635
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
636
+                $relations[$k] = [$v, $table];
641 637
             }
642 638
             foreach ($h as $kk => $vv) {
643
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
644
-                    $relations[$k] = [ $v, $table ];
639
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
640
+                    $relations[$k] = [$v, $table];
645 641
                     $used_relations[] = $k;
646
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
642
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
647 643
                 }
648 644
             }
649
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
650
-                $relations[$k] = [ $v, $table ];
645
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
646
+                $relations[$k] = [$v, $table];
651 647
                 $used_relations[] = $k;
652
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
648
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
653 649
             }
654 650
             foreach ($j as $kk => $vv) {
655 651
                 foreach ($vv->keymap as $kkk => $vvv) {
656
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
657
-                        $relations[$k] = [ $v, $table ];
652
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
653
+                        $relations[$k] = [$v, $table];
658 654
                         $used_relations[] = $k;
659 655
                         $j[$kk]->keymap[$kkk] =
660
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
656
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
661 657
                     }
662 658
                 }
663 659
             }
664 660
         }
665 661
         foreach ($aliases_ext as $k => $alias) {
666 662
             foreach ($w as $kk => $v) {
667
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
668
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
663
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
664
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
669 665
                     $used_relations[] = $k;
670 666
                 }
671 667
             }
672 668
             foreach ($h as $kk => $v) {
673
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
674
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
669
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
670
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
675 671
                     $used_relations[] = $k;
676 672
                 }
677 673
             }
678
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
674
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
679 675
                 $used_relations[] = $k;
680 676
             }
681
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
682
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
677
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
678
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
683 679
                 $used_relations[] = $k;
684 680
             }
685 681
             foreach ($j as $kk => $v) {
686 682
                 foreach ($v->keymap as $kkk => $vv) {
687
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
683
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
688 684
                         $used_relations[] = $k;
689 685
                         $j[$kk]->keymap[$kkk] = preg_replace(
690
-                            '(\b'.preg_quote($k . '.'). ')i',
691
-                            $alias . '.',
686
+                            '(\b'.preg_quote($k.'.').')i',
687
+                            $alias.'.',
692 688
                             $vv
693 689
                         );
694 690
                     }
@@ -707,13 +703,13 @@  discard block
 block discarded – undo
707 703
                     foreach ($v->keymap as $kk => $vv) {
708 704
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
709 705
                     }
710
-                    $sql .= implode(' AND ', $tmp) . ' ';
706
+                    $sql .= implode(' AND ', $tmp).' ';
711 707
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
712 708
                     $tmp = [];
713 709
                     foreach ($v->pivot_keymap as $kk => $vv) {
714 710
                         $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
715 711
                     }
716
-                    $sql .= implode(' AND ', $tmp) . ' ';
712
+                    $sql .= implode(' AND ', $tmp).' ';
717 713
                 } else {
718 714
                     $alias = $getAlias($k);
719 715
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -722,10 +718,10 @@  discard block
 block discarded – undo
722 718
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
723 719
                     }
724 720
                     if ($v->sql) {
725
-                        $tmp[] = $v->sql . ' ';
721
+                        $tmp[] = $v->sql.' ';
726 722
                         $par = array_merge($par, $v->par ?? []);
727 723
                     }
728
-                    $sql .= implode(' AND ', $tmp) . ' ';
724
+                    $sql .= implode(' AND ', $tmp).' ';
729 725
                 }
730 726
             }
731 727
         }
@@ -734,12 +730,12 @@  discard block
 block discarded – undo
734 730
             if ($v->many) {
735 731
                 $jMany = true;
736 732
             }
737
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
733
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
738 734
             $tmp = [];
739 735
             foreach ($v->keymap as $kk => $vv) {
740 736
                 $tmp[] = $kk.' = '.$vv;
741 737
             }
742
-            $sql .= implode(' AND ', $tmp) . ' ';
738
+            $sql .= implode(' AND ', $tmp).' ';
743 739
         }
744 740
         if (!$jMany && !count($used_relations)) {
745 741
             $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql);
@@ -748,20 +744,20 @@  discard block
 block discarded – undo
748 744
             $sql .= 'WHERE ';
749 745
             $tmp = [];
750 746
             foreach ($w as $v) {
751
-                $tmp[] = '(' . $v[0] . ')';
747
+                $tmp[] = '('.$v[0].')';
752 748
                 $par = array_merge($par, $v[1]);
753 749
             }
754 750
             $sql .= implode(' AND ', $tmp).' ';
755 751
         }
756 752
         if (count($g)) {
757
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
753
+            $sql .= 'GROUP BY '.$g[0].' ';
758 754
             $par = array_merge($par, $g[1]);
759 755
         }
760 756
         if (count($h)) {
761 757
             $sql .= 'HAVING ';
762 758
             $tmp = [];
763 759
             foreach ($h as $v) {
764
-                $tmp[] = '(' . $v[0] . ')';
760
+                $tmp[] = '('.$v[0].')';
765 761
                 $par = array_merge($par, $v[1]);
766 762
             }
767 763
             $sql .= implode(' AND ', $tmp).' ';
@@ -796,7 +792,7 @@  discard block
 block discarded – undo
796 792
                     $this->with(implode('.', $temp));
797 793
                     $table = array_reduce(
798 794
                         $temp,
799
-                        function ($carry, $item) use (&$table) {
795
+                        function($carry, $item) use (&$table) {
800 796
                             return $table->getRelation($item)->table;
801 797
                         }
802 798
                     );
@@ -805,7 +801,7 @@  discard block
 block discarded – undo
805 801
                 }
806 802
                 unset($fields[$k]);
807 803
                 foreach ($cols as $col) {
808
-                    $fields[] = $table . '.' . $col;
804
+                    $fields[] = $table.'.'.$col;
809 805
                 }
810 806
             }
811 807
         }
@@ -840,9 +836,9 @@  discard block
 block discarded – undo
840 836
         }
841 837
         $aliases = [];
842 838
         $aliases_ext = [];
843
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
839
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
844 840
             // to bypass use: return $name;
845
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
841
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
846 842
             if (isset($aliases_ext[$name])) {
847 843
                 unset($aliases_ext[$name]);
848 844
             }
@@ -867,7 +863,7 @@  discard block
 block discarded – undo
867 863
         $h = $this->having;
868 864
         $o = $this->order;
869 865
         $g = $this->group;
870
-        $j = array_map(function ($v) {
866
+        $j = array_map(function($v) {
871 867
             return clone $v;
872 868
         }, $this->joins);
873 869
 
@@ -881,32 +877,32 @@  discard block
 block discarded – undo
881 877
                 continue;
882 878
             }
883 879
             foreach ($f as $kk => $field) {
884
-                if (strpos($field, $k . '.') === 0) {
885
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
880
+                if (strpos($field, $k.'.') === 0) {
881
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
886 882
                 }
887 883
             }
888 884
             foreach ($w as $kk => $v) {
889
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
890
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
885
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
886
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
891 887
                 }
892 888
             }
893 889
             foreach ($h as $kk => $v) {
894
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
895
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
890
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
891
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
896 892
                 }
897 893
             }
898
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
899
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
894
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
895
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
900 896
             }
901
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
902
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
897
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
898
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
903 899
             }
904 900
             foreach ($j as $kk => $v) {
905 901
                 foreach ($v->keymap as $kkk => $vv) {
906
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
902
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
907 903
                         $j[$kk]->keymap[$kkk] = preg_replace(
908
-                            '(\b'.preg_quote($k . '.'). ')i',
909
-                            $getAlias($k) . '.',
904
+                            '(\b'.preg_quote($k.'.').')i',
905
+                            $getAlias($k).'.',
910 906
                             $vv
911 907
                         );
912 908
                     }
@@ -915,38 +911,38 @@  discard block
 block discarded – undo
915 911
         }
916 912
         foreach ($this->definition->getRelations() as $k => $relation) {
917 913
             foreach ($f as $kk => $field) {
918
-                if (strpos($field, $k . '.') === 0) {
919
-                    $relations[$k] = [ $relation, $table ];
920
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
914
+                if (strpos($field, $k.'.') === 0) {
915
+                    $relations[$k] = [$relation, $table];
916
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
921 917
                 }
922 918
             }
923 919
             foreach ($w as $kk => $v) {
924
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
925
-                    $relations[$k] = [ $relation, $table ];
926
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
920
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
921
+                    $relations[$k] = [$relation, $table];
922
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
927 923
                 }
928 924
             }
929 925
             foreach ($h as $kk => $v) {
930
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
931
-                    $relations[$k] = [ $relation, $table ];
932
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
926
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
927
+                    $relations[$k] = [$relation, $table];
928
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
933 929
                 }
934 930
             }
935
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
936
-                $relations[$k] = [ $relation, $table ];
937
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
931
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
932
+                $relations[$k] = [$relation, $table];
933
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
938 934
             }
939
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
940
-                $relations[$k] = [ $relation, $table ];
941
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
935
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
936
+                $relations[$k] = [$relation, $table];
937
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
942 938
             }
943 939
             foreach ($j as $kk => $v) {
944 940
                 foreach ($v->keymap as $kkk => $vv) {
945
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
946
-                        $relations[$k] = [ $relation, $table ];
941
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
942
+                        $relations[$k] = [$relation, $table];
947 943
                         $j[$kk]->keymap[$kkk] = preg_replace(
948
-                            '(\b'.preg_quote($k . '.'). ')i',
949
-                            $getAlias($k) . '.',
944
+                            '(\b'.preg_quote($k.'.').')i',
945
+                            $getAlias($k).'.',
950 946
                             $vv
951 947
                         );
952 948
                     }
@@ -955,32 +951,32 @@  discard block
 block discarded – undo
955 951
         }
956 952
         foreach ($aliases_ext as $k => $alias) {
957 953
             foreach ($f as $kk => $field) {
958
-                if (strpos($field, $k . '.') === 0) {
959
-                    $f[$kk] = str_replace($k . '.', $alias . '.', $field);
954
+                if (strpos($field, $k.'.') === 0) {
955
+                    $f[$kk] = str_replace($k.'.', $alias.'.', $field);
960 956
                 }
961 957
             }
962 958
             foreach ($w as $kk => $v) {
963
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
964
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
959
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
960
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
965 961
                 }
966 962
             }
967 963
             foreach ($h as $kk => $v) {
968
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
969
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
964
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
965
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
970 966
                 }
971 967
             }
972
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
973
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
968
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
969
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
974 970
             }
975
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
976
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
971
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
972
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
977 973
             }
978 974
             foreach ($j as $kk => $v) {
979 975
                 foreach ($v->keymap as $kkk => $vv) {
980
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
976
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
981 977
                         $j[$kk]->keymap[$kkk] = preg_replace(
982
-                            '(\b'.preg_quote($k . '.'). ')i',
983
-                            $alias . '.',
978
+                            '(\b'.preg_quote($k.'.').')i',
979
+                            $alias.'.',
984 980
                             $vv
985 981
                         );
986 982
                     }
@@ -989,12 +985,12 @@  discard block
 block discarded – undo
989 985
         }
990 986
         $select = [];
991 987
         foreach ($f as $k => $field) {
992
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
988
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
993 989
         }
994 990
         foreach ($this->withr as $name => $relation) {
995 991
             if ($relation[2]) {
996 992
                 foreach ($relation[0]->table->getColumns() as $column) {
997
-                    $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
993
+                    $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
998 994
                 }
999 995
             }
1000 996
         }
@@ -1015,13 +1011,13 @@  discard block
 block discarded – undo
1015 1011
                 foreach ($v->keymap as $kk => $vv) {
1016 1012
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1017 1013
                 }
1018
-                $sql .= implode(' AND ', $tmp) . ' ';
1014
+                $sql .= implode(' AND ', $tmp).' ';
1019 1015
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
1020 1016
                 $tmp = [];
1021 1017
                 foreach ($v->pivot_keymap as $kk => $vv) {
1022 1018
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1023 1019
                 }
1024
-                $sql .= implode(' AND ', $tmp) . ' ';
1020
+                $sql .= implode(' AND ', $tmp).' ';
1025 1021
             } else {
1026 1022
                 $alias = $getAlias($relation);
1027 1023
 
@@ -1031,22 +1027,22 @@  discard block
 block discarded – undo
1031 1027
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1032 1028
                 }
1033 1029
                 if ($v->sql) {
1034
-                    $tmp[] = $v->sql . ' ';
1030
+                    $tmp[] = $v->sql.' ';
1035 1031
                     $par = array_merge($par, $v->par ?? []);
1036 1032
                 }
1037
-                $sql .= implode(' AND ', $tmp) . ' ';
1033
+                $sql .= implode(' AND ', $tmp).' ';
1038 1034
             }
1039 1035
         }
1040 1036
         foreach ($j as $k => $v) {
1041 1037
             if ($v->many) {
1042 1038
                 $many = true;
1043 1039
             }
1044
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1040
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1045 1041
             $tmp = [];
1046 1042
             foreach ($v->keymap as $kk => $vv) {
1047 1043
                 $tmp[] = $kk.' = '.$vv;
1048 1044
             }
1049
-            $sql .= implode(' AND ', $tmp) . ' ';
1045
+            $sql .= implode(' AND ', $tmp).' ';
1050 1046
         }
1051 1047
         if ($many && count($porder) && $this->li_of[2] === 1) {
1052 1048
             $ids = $this->ids();
@@ -1054,9 +1050,9 @@  discard block
 block discarded – undo
1054 1050
                 if (count($porder) > 1) {
1055 1051
                     $pkw = [];
1056 1052
                     foreach ($porder as $name) {
1057
-                        $pkw[] = $name . ' = ?';
1053
+                        $pkw[] = $name.' = ?';
1058 1054
                     }
1059
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
1055
+                    $pkw = '('.implode(' AND ', $pkw).')';
1060 1056
                     $pkp = [];
1061 1057
                     foreach ($ids as $id) {
1062 1058
                         foreach ($id as $p) {
@@ -1068,60 +1064,60 @@  discard block
 block discarded – undo
1068 1064
                         $pkp
1069 1065
                     ];
1070 1066
                 } else {
1071
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
1067
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
1072 1068
                 }
1073 1069
             } else {
1074
-                $w[] = [ '1=0', [] ];
1070
+                $w[] = ['1=0', []];
1075 1071
             }
1076 1072
         }
1077 1073
         if (count($w)) {
1078 1074
             $sql .= 'WHERE ';
1079 1075
             $tmp = [];
1080 1076
             foreach ($w as $v) {
1081
-                $tmp[] = '(' . $v[0] . ')';
1077
+                $tmp[] = '('.$v[0].')';
1082 1078
                 $par = array_merge($par, $v[1]);
1083 1079
             }
1084 1080
             $sql .= implode(' AND ', $tmp).' ';
1085 1081
         }
1086 1082
         if (count($g)) {
1087
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1083
+            $sql .= 'GROUP BY '.$g[0].' ';
1088 1084
             $par = array_merge($par, $g[1]);
1089 1085
         }
1090 1086
         if (count($h)) {
1091 1087
             $sql .= 'HAVING ';
1092 1088
             $tmp = [];
1093 1089
             foreach ($h as $v) {
1094
-                $tmp[] = '(' . $v[0] . ')';
1090
+                $tmp[] = '('.$v[0].')';
1095 1091
                 $par = array_merge($par, $v[1]);
1096 1092
             }
1097 1093
             $sql .= implode(' AND ', $tmp).' ';
1098 1094
         }
1099 1095
         $ordered = false;
1100 1096
         if (count($o)) {
1101
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1097
+            $sql .= 'ORDER BY '.$o[0].' ';
1102 1098
             $par = array_merge($par, $o[1]);
1103 1099
             $ordered = true;
1104 1100
         }
1105 1101
         if (!count($g) && count($porder)) {
1106 1102
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1107
-            $porder = array_map(function ($v) use ($pdir) {
1108
-                return $v . ' ' . $pdir;
1103
+            $porder = array_map(function($v) use ($pdir) {
1104
+                return $v.' '.$pdir;
1109 1105
             }, $porder);
1110
-            $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1106
+            $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1111 1107
             $ordered = true;
1112 1108
         }
1113 1109
         foreach ($this->withr as $k => $v) {
1114 1110
             if (isset($v[3])) {
1115
-                $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC');
1111
+                $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC');
1116 1112
                 $ordered = true;
1117 1113
             }
1118 1114
         }
1119 1115
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
1120 1116
             if ($this->db->driverName() === 'oracle') {
1121
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1122
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1117
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1118
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1123 1119
                 } else {
1124
-                    $f = array_map(function ($v) {
1120
+                    $f = array_map(function($v) {
1125 1121
                         $v = explode(' ', trim($v), 2);
1126 1122
                         if (count($v) === 2) {
1127 1123
                             return $v[1];
@@ -1129,16 +1125,16 @@  discard block
 block discarded – undo
1129 1125
                         $v = explode('.', $v[0], 2);
1130 1126
                         return count($v) === 2 ? $v[1] : $v[0];
1131 1127
                     }, $select);
1132
-                    $sql = "SELECT " . implode(', ', $f) . " 
1128
+                    $sql = "SELECT ".implode(', ', $f)." 
1133 1129
                             FROM (
1134 1130
                                 SELECT tbl__.*, rownum rnum__ FROM (
1135
-                                    " . $sql . "
1131
+                                    " . $sql."
1136 1132
                                 ) tbl__ 
1137
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1133
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1138 1134
                             ) WHERE rnum__ > " . $this->li_of[1];
1139 1135
                 }
1140 1136
             } else {
1141
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1137
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1142 1138
             }
1143 1139
         }
1144 1140
         return $this->qiterator = new TableQueryIterator(
@@ -1188,12 +1184,12 @@  discard block
 block discarded – undo
1188 1184
                 $ret[$k] = str_repeat(' ', 255);
1189 1185
                 $par[] = &$ret[$k];
1190 1186
             }
1191
-            $sql .= ' RETURNING ' . implode(',', $primary) .
1192
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
1187
+            $sql .= ' RETURNING '.implode(',', $primary).
1188
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
1193 1189
             $this->db->query($sql, $par);
1194 1190
             return $ret;
1195 1191
         } elseif ($this->db->driverName() === 'postgre') {
1196
-            $sql .= ' RETURNING ' . implode(',', $primary);
1192
+            $sql .= ' RETURNING '.implode(',', $primary);
1197 1193
             return $this->db->one($sql, $par, false);
1198 1194
         } else {
1199 1195
             $ret = [];
@@ -1224,9 +1220,9 @@  discard block
 block discarded – undo
1224 1220
         }
1225 1221
         $sql = 'UPDATE '.$table.' SET ';
1226 1222
         $par = [];
1227
-        $sql .= implode(', ', array_map(function ($v) {
1228
-            return $v . ' = ?';
1229
-        }, array_keys($update))) . ' ';
1223
+        $sql .= implode(', ', array_map(function($v) {
1224
+            return $v.' = ?';
1225
+        }, array_keys($update))).' ';
1230 1226
         $par = array_merge($par, array_values($update));
1231 1227
         if (count($this->where)) {
1232 1228
             $sql .= 'WHERE ';
@@ -1235,7 +1231,7 @@  discard block
 block discarded – undo
1235 1231
                 $tmp[] = $v[0];
1236 1232
                 $par = array_merge($par, $v[1]);
1237 1233
             }
1238
-            $sql .= implode(' AND ', $tmp) . ' ';
1234
+            $sql .= implode(' AND ', $tmp).' ';
1239 1235
         }
1240 1236
         if (count($this->order)) {
1241 1237
             $sql .= $this->order[0];
@@ -1259,7 +1255,7 @@  discard block
 block discarded – undo
1259 1255
                 $tmp[] = $v[0];
1260 1256
                 $par = array_merge($par, $v[1]);
1261 1257
             }
1262
-            $sql .= implode(' AND ', $tmp) . ' ';
1258
+            $sql .= implode(' AND ', $tmp).' ';
1263 1259
         }
1264 1260
         if (count($this->order)) {
1265 1261
             $sql .= $this->order[0];
@@ -1290,15 +1286,15 @@  discard block
 block discarded – undo
1290 1286
             try {
1291 1287
                 $name = array_reduce(
1292 1288
                     $parts,
1293
-                    function ($carry, $item) use (&$table, $select) {
1289
+                    function($carry, $item) use (&$table, $select) {
1294 1290
                         if (!$table->hasRelation($item)) {
1295
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1291
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1296 1292
                         }
1297 1293
                         $relation = $table->getRelation($item);
1298 1294
                         if (!$relation) {
1299
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1295
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1300 1296
                         }
1301
-                        $name = $carry ? $carry . static::SEP . $item : $item;
1297
+                        $name = $carry ? $carry.static::SEP.$item : $item;
1302 1298
                         $this->withr[$name] = [
1303 1299
                             $relation,
1304 1300
                             $carry ?? $table->getName(),
@@ -1367,9 +1363,9 @@  discard block
 block discarded – undo
1367 1363
 
1368 1364
         $aliases = [];
1369 1365
         $aliases_ext = [];
1370
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
1366
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
1371 1367
             // to bypass use: return $name;
1372
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1368
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1373 1369
             if (isset($aliases_ext[$name])) {
1374 1370
                 unset($aliases_ext[$name]);
1375 1371
             }
@@ -1389,7 +1385,7 @@  discard block
 block discarded – undo
1389 1385
         $w = $this->where;
1390 1386
         $h = $this->having;
1391 1387
         $o = $this->order;
1392
-        $j = array_map(function ($v) {
1388
+        $j = array_map(function($v) {
1393 1389
             return clone $v;
1394 1390
         }, $this->joins);
1395 1391
 
@@ -1398,24 +1394,24 @@  discard block
 block discarded – undo
1398 1394
                 continue;
1399 1395
             }
1400 1396
             foreach ($w as $kk => $v) {
1401
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1402
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1397
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1398
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1403 1399
                 }
1404 1400
             }
1405 1401
             foreach ($h as $kk => $v) {
1406
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1407
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1402
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1403
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1408 1404
                 }
1409 1405
             }
1410
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1411
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1406
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1407
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1412 1408
             }
1413 1409
             foreach ($j as $kk => $v) {
1414 1410
                 foreach ($v->keymap as $kkk => $vv) {
1415
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1411
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1416 1412
                         $j[$kk]->keymap[$kkk] = preg_replace(
1417
-                            '(\b'.preg_quote($k . '.'). ')i',
1418
-                            $getAlias($k) . '.',
1413
+                            '(\b'.preg_quote($k.'.').')i',
1414
+                            $getAlias($k).'.',
1419 1415
                             $vv
1420 1416
                         );
1421 1417
                     }
@@ -1424,52 +1420,52 @@  discard block
 block discarded – undo
1424 1420
         }
1425 1421
         foreach ($this->definition->getRelations() as $k => $v) {
1426 1422
             foreach ($w as $kk => $vv) {
1427
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1428
-                    $relations[$k] = [ $v, $table ];
1429
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1423
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1424
+                    $relations[$k] = [$v, $table];
1425
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1430 1426
                 }
1431 1427
             }
1432
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1433
-                $relations[$k] = [ $v, $table ];
1434
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1435
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1428
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1429
+                $relations[$k] = [$v, $table];
1430
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1431
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1436 1432
             }
1437 1433
             foreach ($h as $kk => $vv) {
1438
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1439
-                    $relations[$k] = [ $v, $table ];
1440
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1434
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1435
+                    $relations[$k] = [$v, $table];
1436
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1441 1437
                 }
1442 1438
             }
1443 1439
             foreach ($j as $kk => $vv) {
1444 1440
                 foreach ($vv->keymap as $kkk => $vvv) {
1445
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1446
-                        $relations[$k] = [ $v, $table ];
1441
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1442
+                        $relations[$k] = [$v, $table];
1447 1443
                         $j[$kk]->keymap[$kkk] =
1448
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1444
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1449 1445
                     }
1450 1446
                 }
1451 1447
             }
1452 1448
         }
1453 1449
         foreach ($aliases_ext as $k => $alias) {
1454 1450
             foreach ($w as $kk => $v) {
1455
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1456
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1451
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1452
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1457 1453
                 }
1458 1454
             }
1459 1455
             foreach ($h as $kk => $v) {
1460
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1461
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1456
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1457
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1462 1458
                 }
1463 1459
             }
1464
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1465
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
1460
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1461
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
1466 1462
             }
1467 1463
             foreach ($j as $kk => $v) {
1468 1464
                 foreach ($v->keymap as $kkk => $vv) {
1469
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1465
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1470 1466
                         $j[$kk]->keymap[$kkk] = preg_replace(
1471
-                            '(\b'.preg_quote($k . '.'). ')i',
1472
-                            $alias . '.',
1467
+                            '(\b'.preg_quote($k.'.').')i',
1468
+                            $alias.'.',
1473 1469
                             $vv
1474 1470
                         );
1475 1471
                     }
@@ -1477,29 +1473,29 @@  discard block
 block discarded – undo
1477 1473
             }
1478 1474
         }
1479 1475
 
1480
-        $key = array_map(function ($v) use ($table) {
1481
-            return $table . '.' . $v;
1476
+        $key = array_map(function($v) use ($table) {
1477
+            return $table.'.'.$v;
1482 1478
         }, $this->pkey);
1483 1479
         $own = false;
1484 1480
         $dir = 'ASC';
1485 1481
         if (count($o)) {
1486 1482
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1487
-            $own = strpos($o[2], $table . '.') === 0;
1483
+            $own = strpos($o[2], $table.'.') === 0;
1488 1484
         }
1489 1485
 
1490 1486
         $dst = $key;
1491 1487
         if (count($o)) {
1492 1488
             if ($own) {
1493 1489
                 // if using own table - do not use max/min in order - that will prevent index usage
1494
-                $dst[] = $o[2] . ' orderbyfix___';
1490
+                $dst[] = $o[2].' orderbyfix___';
1495 1491
             } else {
1496
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1492
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1497 1493
             }
1498 1494
         }
1499 1495
         $dst = array_unique($dst);
1500 1496
 
1501 1497
         $par = [];
1502
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1498
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1503 1499
         foreach ($relations as $k => $v) {
1504 1500
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1505 1501
             $v = $v[0];
@@ -1510,13 +1506,13 @@  discard block
 block discarded – undo
1510 1506
                 foreach ($v->keymap as $kk => $vv) {
1511 1507
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1512 1508
                 }
1513
-                $sql .= implode(' AND ', $tmp) . ' ';
1509
+                $sql .= implode(' AND ', $tmp).' ';
1514 1510
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
1515 1511
                 $tmp = [];
1516 1512
                 foreach ($v->pivot_keymap as $kk => $vv) {
1517 1513
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1518 1514
                 }
1519
-                $sql .= implode(' AND ', $tmp) . ' ';
1515
+                $sql .= implode(' AND ', $tmp).' ';
1520 1516
             } else {
1521 1517
                 $alias = $getAlias($k);
1522 1518
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -1525,37 +1521,37 @@  discard block
 block discarded – undo
1525 1521
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1526 1522
                 }
1527 1523
                 if ($v->sql) {
1528
-                    $tmp[] = $v->sql . ' ';
1524
+                    $tmp[] = $v->sql.' ';
1529 1525
                     $par = array_merge($par, $v->par ?? []);
1530 1526
                 }
1531
-                $sql .= implode(' AND ', $tmp) . ' ';
1527
+                $sql .= implode(' AND ', $tmp).' ';
1532 1528
             }
1533 1529
         }
1534 1530
         foreach ($j as $k => $v) {
1535
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1531
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1536 1532
             $tmp = [];
1537 1533
             foreach ($v->keymap as $kk => $vv) {
1538 1534
                 $tmp[] = $kk.' = '.$vv;
1539 1535
             }
1540
-            $sql .= implode(' AND ', $tmp) . ' ';
1536
+            $sql .= implode(' AND ', $tmp).' ';
1541 1537
         }
1542 1538
         if (count($w)) {
1543 1539
             $sql .= 'WHERE ';
1544 1540
             $tmp = [];
1545 1541
             foreach ($w as $v) {
1546
-                $tmp[] = '(' . $v[0] . ')';
1542
+                $tmp[] = '('.$v[0].')';
1547 1543
                 $par = array_merge($par, $v[1]);
1548 1544
             }
1549 1545
             $sql .= implode(' AND ', $tmp).' ';
1550 1546
         }
1551 1547
         if (!$own) {
1552
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1548
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1553 1549
         }
1554 1550
         if (count($h)) {
1555 1551
             $sql .= 'HAVING ';
1556 1552
             $tmp = [];
1557 1553
             foreach ($h as $v) {
1558
-                $tmp[] = '(' . $v[0] . ')';
1554
+                $tmp[] = '('.$v[0].')';
1559 1555
                 $par = array_merge($par, $v[1]);
1560 1556
             }
1561 1557
             $sql .= implode(' AND ', $tmp).' ';
@@ -1563,38 +1559,38 @@  discard block
 block discarded – undo
1563 1559
         if (count($o)) {
1564 1560
             $sql .= 'ORDER BY ';
1565 1561
             if ($own) {
1566
-                $sql .= $o[2] . ' ' . $dir;
1562
+                $sql .= $o[2].' '.$dir;
1567 1563
             } else {
1568
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1564
+                $sql .= 'MAX('.$o[2].') '.$dir;
1569 1565
             }
1570 1566
         }
1571 1567
         $porder = [];
1572 1568
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1573 1569
         foreach ($this->definition->getPrimaryKey() as $field) {
1574
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1570
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1575 1571
         }
1576 1572
         if (count($porder)) {
1577
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1573
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1578 1574
         }
1579 1575
 
1580 1576
         if ($this->li_of[0]) {
1581 1577
             if ($this->db->driverName() === 'oracle') {
1582
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1583
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1578
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1579
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1584 1580
                 } else {
1585
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1581
+                    $sql = "SELECT ".implode(', ', $dst)." 
1586 1582
                             FROM (
1587 1583
                                 SELECT tbl__.*, rownum rnum__ FROM (
1588
-                                    " . $sql . "
1584
+                                    " . $sql."
1589 1585
                                 ) tbl__ 
1590
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1586
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1591 1587
                             ) WHERE rnum__ > " . $this->li_of[1];
1592 1588
                 }
1593 1589
             } else {
1594
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1590
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1595 1591
             }
1596 1592
         }
1597
-        return array_map(function ($v) {
1593
+        return array_map(function($v) {
1598 1594
             if (array_key_exists('orderbyfix___', $v)) {
1599 1595
                 unset($v['orderbyfix___']);
1600 1596
             }
Please login to merge, or discard this patch.
src/schema/Mapper.php 1 patch
Spacing   +18 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      * @param class-string<T> $clss
27 27
      * @return void
28 28
      */
29
-    public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class)
29
+    public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class)
30 30
     {
31 31
         $this->db = $db;
32 32
         if (!$table) {
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $temp = [];
63 63
         foreach ($this->table->getPrimaryKey() as $column) {
64 64
             try {
65
-                $temp[(string)$column] = $entity->{$column} ?? null;
65
+                $temp[(string) $column] = $entity->{$column} ?? null;
66 66
                 /** @phpstan-ignore-next-line */
67 67
             } catch (\Throwable $ignore) {
68 68
             }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
         // BEG: ugly hack to get relations changed directly on the object (not hydrated)
94 94
         $hack = [];
95
-        foreach ((array)$entity as $k => $v) {
95
+        foreach ((array) $entity as $k => $v) {
96 96
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
97 97
         }
98 98
         $hack = $hack['changed'] ?? [];
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         foreach ($columns as $column) {
104 104
             try {
105 105
                 if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) {
106
-                    $temp[(string)$column] = $entity->{$column};
106
+                    $temp[(string) $column] = $entity->{$column};
107 107
                 }
108 108
             } catch (\Throwable $ignore) {
109 109
             }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         foreach ($relations as $relation) {
114 114
             try {
115 115
                 if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) {
116
-                    $temp[(string)$relation] = $entity->{$relation};
116
+                    $temp[(string) $relation] = $entity->{$relation};
117 117
                 }
118 118
             } catch (\Throwable $ignore) {
119 119
             }
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
         $temp = [];
153 153
         foreach ($this->table->getColumns() as $column) {
154 154
             if (array_key_exists($column, $data)) {
155
-                $temp[(string)$column] = $data[$column];
155
+                $temp[(string) $column] = $data[$column];
156 156
             }
157 157
             if ($empty) {
158
-                $temp[(string)$column] = null;
158
+                $temp[(string) $column] = null;
159 159
             }
160 160
         }
161 161
         $entity = $this->instance(
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         $lazy = [];
182 182
         foreach ($this->table->getColumns() as $column) {
183 183
             if (!array_key_exists($column, $data)) {
184
-                $lazy[$column] = function ($entity) use ($column) {
184
+                $lazy[$column] = function($entity) use ($column) {
185 185
                     $query = $this->db->table($this->table->getFullName());
186 186
                     foreach ($this->id($entity) as $k => $v) {
187 187
                         $query->filter($k, $v);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         $relations = [];
206 206
         foreach ($this->table->getRelations() as $name => $relation) {
207
-            $relations[$name] = function (
207
+            $relations[$name] = function(
208 208
                 $entity,
209 209
                 bool $queryOnly = false
210 210
             ) use (
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
                         return $this->objects[spl_object_hash($entity)][4][$name] = null;
219 219
                     }
220 220
                     $value = $relation->many ?
221
-                        Collection::from(array_map(function ($v) use ($mapper) {
221
+                        Collection::from(array_map(function($v) use ($mapper) {
222 222
                             return $mapper->entity($v);
223 223
                         }, $data[$name]))
224
-                            ->filter(function ($v) use ($mapper) {
224
+                            ->filter(function($v) use ($mapper) {
225 225
                                 return !$mapper->deleted($v);
226 226
                             }) :
227 227
                         ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name]));
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                 }
231 231
                 $query = $this->db->tableMapped($relation->table->getFullName());
232 232
                 if ($relation->sql) {
233
-                    $query->where($relation->sql, $relation->par?:[]);
233
+                    $query->where($relation->sql, $relation->par ?: []);
234 234
                 }
235 235
                 if ($relation->pivot) {
236 236
                     $nm = null;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                     }
252 252
                     $pk = $this->id($entity);
253 253
                     foreach ($pk as $k => $v) {
254
-                        $query->filter($nm . '.' . $k, $v);
254
+                        $query->filter($nm.'.'.$k, $v);
255 255
                     }
256 256
                 } else {
257 257
                     $temp = $this->toArray($entity, array_keys($relation->keymap));
@@ -263,10 +263,9 @@  discard block
 block discarded – undo
263 263
                     return $query;
264 264
                 }
265 265
                 $value = $relation->many ?
266
-                    $query->iterator() :
267
-                    ($query[0] ?? null);
266
+                    $query->iterator() : ($query[0] ?? null);
268 267
                 if ($value instanceof Collection) {
269
-                    $value->filter(function ($v) use ($mapper) {
268
+                    $value->filter(function($v) use ($mapper) {
270 269
                         return !$mapper->deleted($v);
271 270
                     });
272 271
                 } elseif (isset($value) && $mapper->deleted($value)) {
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
             }
500 499
         }
501 500
     }
502
-    public function exists(array|object $entity): bool
501
+    public function exists(array | object $entity): bool
503 502
     {
504 503
         if (is_array($entity)) {
505 504
             $primary = [];
@@ -512,7 +511,7 @@  discard block
 block discarded – undo
512 511
         return isset($this->objects[spl_object_hash($entity)]) &&
513 512
             $this->objects[spl_object_hash($entity)] !== false;
514 513
     }
515
-    public function deleted(array|object $entity): bool
514
+    public function deleted(array | object $entity): bool
516 515
     {
517 516
         if (is_array($entity)) {
518 517
             $primary = [];
@@ -584,7 +583,7 @@  discard block
 block discarded – undo
584 583
         return array_filter(
585 584
             array_values(
586 585
                 array_map(
587
-                    function ($v) {
586
+                    function($v) {
588 587
                         return $v[1] ?? null;
589 588
                     },
590 589
                     $this->objects
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.