Completed
Push — master ( 3afc72...36726b )
by Ivan
10:25
created
src/driver/oracle/Schema.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -124,7 +124,7 @@
 block discarded – undo
124 124
                     }
125 125
                     return $new;
126 126
                 })
127
-                 as $relation
127
+                    as $relation
128 128
             ) {
129 129
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
130 130
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,19 +29,19 @@  discard block
 block discarded – undo
29 29
         $columns = Collection::from($this
30 30
             ->query(
31 31
                 "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?",
32
-                [ strtoupper($table), $this->name() ]
32
+                [strtoupper($table), $this->name()]
33 33
             ))
34
-            ->map(function ($v) {
34
+            ->map(function($v) {
35 35
                 $new = [];
36 36
                 foreach ($v as $kk => $vv) {
37 37
                     $new[strtoupper($kk)] = $vv;
38 38
                 }
39 39
                 return $new;
40 40
             })
41
-            ->mapKey(function ($v) {
41
+            ->mapKey(function($v) {
42 42
                 return $v['COLUMN_NAME'];
43 43
             })
44
-            ->map(function ($v) {
44
+            ->map(function($v) {
45 45
                 $v['length'] = null;
46 46
                 if (!isset($v['DATA_TYPE'])) {
47 47
                     return $v;
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
                     default:
54 54
                         if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
55 55
                             // extract length from varchar
56
-                            $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0];
56
+                            $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0];
57 57
                             $v['length'] = $v['length'] > 0 ? $v['length'] : null;
58 58
                         }
59 59
                         break;
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
             ->query(
70 70
                 "SELECT constraint_name FROM all_constraints
71 71
                 WHERE table_name = ? AND constraint_type = ? AND owner = ?",
72
-                [ strtoupper($table), 'P', $owner ]
72
+                [strtoupper($table), 'P', $owner]
73 73
             ))
74
-            ->map(function ($v) {
74
+            ->map(function($v) {
75 75
                 $new = [];
76 76
                 foreach ($v as $kk => $vv) {
77 77
                     $new[strtoupper($kk)] = $vv;
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
                 ->query(
87 87
                     "SELECT column_name FROM all_cons_columns
88 88
                     WHERE table_name = ? AND constraint_name = ? AND owner = ?",
89
-                    [ strtoupper($table), $pkname, $owner ]
89
+                    [strtoupper($table), $pkname, $owner]
90 90
                 ))
91
-                ->map(function ($v) {
91
+                ->map(function($v) {
92 92
                     $new = [];
93 93
                     foreach ($v as $kk => $vv) {
94 94
                         $new[strtoupper($kk)] = $vv;
@@ -115,9 +115,9 @@  discard block
 block discarded – undo
115 115
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
116 116
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
117 117
                     ORDER BY cc.POSITION",
118
-                    [ $owner, $owner, $pkname, 'R' ]
118
+                    [$owner, $owner, $pkname, 'R']
119 119
                 ))
120
-                ->map(function ($v) {
120
+                ->map(function($v) {
121 121
                     $new = [];
122 122
                     foreach ($v as $kk => $vv) {
123 123
                         $new[strtoupper($kk)] = $vv;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                  as $relation
128 128
             ) {
129 129
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
130
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
130
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
131 131
                     $relation['COLUMN_NAME'];
132 132
             }
133 133
             foreach ($relations as $data) {
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
                                 ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
158 158
                                 cc.COLUMN_NAME IN (??)
159 159
                             ORDER BY POSITION",
160
-                            [ $owner, $owner, $data['table'], 'R', $columns ]
160
+                            [$owner, $owner, $data['table'], 'R', $columns]
161 161
                         ))
162
-                        ->map(function ($v) {
162
+                        ->map(function($v) {
163 163
                             $new = [];
164 164
                             foreach ($v as $kk => $vv) {
165 165
                                 $new[strtoupper($kk)] = $vv;
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
                         ->query(
180 180
                             "SELECT COLUMN_NAME FROM all_cons_columns
181 181
                              WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
182
-                            [ $owner, current($foreign['keymap']) ]
182
+                            [$owner, current($foreign['keymap'])]
183 183
                         ))
184
-                        ->map(function ($v) {
184
+                        ->map(function($v) {
185 185
                             $new = [];
186 186
                             foreach ($v as $kk => $vv) {
187 187
                                 $new[strtoupper($kk)] = $vv;
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
                     $relname = $foreign['table'];
197 197
                     $cntr = 1;
198 198
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
199
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
199
+                        $relname = $foreign['table'].'_'.(++$cntr);
200 200
                     }
201 201
                     $definition->addRelation(
202 202
                         new TableRelation(
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
                     $relname = $data['table'];
213 213
                     $cntr = 1;
214 214
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
215
-                        $relname = $data['table'] . '_' . (++ $cntr);
215
+                        $relname = $data['table'].'_'.(++$cntr);
216 216
                     }
217 217
                     $definition->addRelation(
218 218
                         new TableRelation(
@@ -240,9 +240,9 @@  discard block
 block discarded – undo
240 240
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
241 241
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
242 242
                     ORDER BY cc.POSITION",
243
-                    [ $owner, $owner, strtoupper($table), 'R' ]
243
+                    [$owner, $owner, strtoupper($table), 'R']
244 244
                 ))
245
-                ->map(function ($v) {
245
+                ->map(function($v) {
246 246
                     $new = [];
247 247
                     foreach ($v as $kk => $vv) {
248 248
                         $new[strtoupper($kk)] = $vv;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
                     ->query(
261 261
                         "SELECT COLUMN_NAME FROM all_cons_columns
262 262
                          WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
263
-                        [ $owner, current($data['keymap']) ]
263
+                        [$owner, current($data['keymap'])]
264 264
                     ))
265
-                    ->map(function ($v) {
265
+                    ->map(function($v) {
266 266
                         $new = [];
267 267
                         foreach ($v as $kk => $vv) {
268 268
                             $new[strtoupper($kk)] = $vv;
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
                 $relname = $data['table'];
278 278
                 $cntr = 1;
279 279
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
280
-                    $relname = $data['table'] . '_' . (++ $cntr);
280
+                    $relname = $data['table'].'_'.(++$cntr);
281 281
                 }
282 282
                 $definition->addRelation(
283 283
                     new TableRelation(
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?",
299 299
                 [$this->connection['name']]
300 300
             ))
301
-            ->map(function ($v) {
301
+            ->map(function($v) {
302 302
                 $new = [];
303 303
                 foreach ($v as $kk => $vv) {
304 304
                     $new[strtoupper($kk)] = $vv;
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
                 return $new;
307 307
             })
308 308
             ->pluck('TABLE_NAME')
309
-            ->map(function ($v) {
309
+            ->map(function($v) {
310 310
                 return $this->table($v);
311 311
             })
312 312
             ->toArray();
Please login to merge, or discard this patch.
src/driver/postgre/Schema.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
                         kc.table_schema = ? AND
48 48
                         kc.table_name IS NOT NULL AND
49 49
                         kc.position_in_unique_constraint IS NOT NULL",
50
-                    [ $this->connection['opts']['schema'] ?? $this->connection['name'] ]
50
+                    [$this->connection['opts']['schema'] ?? $this->connection['name']]
51 51
                 )
52 52
             )->toArray();
53 53
             foreach ($col as $row) {
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
         $columns = Collection::from($this
60 60
             ->query(
61 61
                 "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ?",
62
-                [ $table, $this->connection['opts']['schema'] ?? $this->connection['name'] ]
62
+                [$table, $this->connection['opts']['schema'] ?? $this->connection['name']]
63 63
             ))
64
-            ->mapKey(function ($v) {
64
+            ->mapKey(function($v) {
65 65
                 return $v['column_name'];
66 66
             })
67
-            ->map(function ($v) {
67
+            ->map(function($v) {
68 68
                 $v['length'] = null;
69 69
                 if (!isset($v['data_type'])) {
70 70
                     return $v;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
                 switch ($v['data_type']) {
73 73
                     case 'character':
74 74
                     case 'character varying':
75
-                        $v['length'] = (int)$v['character_maximum_length'];
75
+                        $v['length'] = (int) $v['character_maximum_length'];
76 76
                         break;
77 77
                 }
78 78
                 return $v;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             ->query(
86 86
                 "SELECT constraint_name FROM information_schema.table_constraints
87 87
                 WHERE table_name = ? AND constraint_type = ? AND table_schema = ?",
88
-                [ $table, 'PRIMARY KEY', $this->connection['opts']['schema'] ?? $this->connection['name'] ]
88
+                [$table, 'PRIMARY KEY', $this->connection['opts']['schema'] ?? $this->connection['name']]
89 89
             ))
90 90
             ->pluck('constraint_name')
91 91
             ->value();
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
                 ->query(
96 96
                     "SELECT column_name FROM information_schema.constraint_column_usage
97 97
                      WHERE table_name = ? AND constraint_name = ? AND table_schema = ?",
98
-                    [ $table, $pkname, $this->connection['opts']['schema'] ?? $this->connection['name'] ]
98
+                    [$table, $pkname, $this->connection['opts']['schema'] ?? $this->connection['name']]
99 99
                 ))
100 100
                 ->pluck('column_name')
101 101
                 ->toArray();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                 $usedcol = [];
128 128
                 if (count($columns)) {
129 129
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
130
-                        ->filter(function ($v) use ($columns) {
130
+                        ->filter(function($v) use ($columns) {
131 131
                             return in_array($v['column_name'], $columns);
132 132
                         }) as $relation
133 133
                     ) {
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                     $relname = $foreign['table'];
143 143
                     $cntr = 1;
144 144
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
145
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
145
+                        $relname = $foreign['table'].'_'.(++$cntr);
146 146
                     }
147 147
                     $definition->addRelation(
148 148
                         new TableRelation(
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
                     $relname = $data['table'];
159 159
                     $cntr = 1;
160 160
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
161
-                        $relname = $data['table'] . '_' . (++ $cntr);
161
+                        $relname = $data['table'].'_'.(++$cntr);
162 162
                     }
163 163
                     $definition->addRelation(
164 164
                         new TableRelation(
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
                 $relname = $data['table'];
184 184
                 $cntr = 1;
185 185
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
186
-                    $relname = $data['table'] . '_' . (++ $cntr);
186
+                    $relname = $data['table'].'_'.(++$cntr);
187 187
                 }
188 188
                 $definition->addRelation(
189 189
                     new TableRelation(
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
         return Collection::from($this
203 203
             ->query(
204 204
                 "SELECT table_name FROM information_schema.tables where table_schema = ?",
205
-                [ $this->connection['opts']['schema'] ?? $this->connection['name'] ]
205
+                [$this->connection['opts']['schema'] ?? $this->connection['name']]
206 206
             ))
207 207
             ->pluck('table_name')
208
-            ->map(function ($v) {
208
+            ->map(function($v) {
209 209
                 return $this->table($v);
210 210
             })
211 211
             ->toArray();
Please login to merge, or discard this patch.
src/driver/mysql/Schema.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@  discard block
 block discarded – undo
28 28
             $comments = Collection::from(
29 29
                 $this->query(
30 30
                     "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?",
31
-                    [ $this->connection['opts']['schema'] ?? $this->connection['name'] ]
31
+                    [$this->connection['opts']['schema'] ?? $this->connection['name']]
32 32
                 )
33 33
             )
34
-            ->mapKey(function ($v) {
34
+            ->mapKey(function($v) {
35 35
                 return $v['TABLE_NAME'];
36 36
             })
37 37
             ->pluck('TABLE_COMMENT')
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
             ->addColumns(
72 72
                 $columns
73 73
                     ->clone()
74
-                    ->mapKey(function ($v) {
74
+                    ->mapKey(function($v) {
75 75
                         return $v['Field'];
76 76
                     })
77
-                    ->map(function ($v) {
77
+                    ->map(function($v) {
78 78
                         $v['length'] = null;
79 79
                         if (!isset($v['Type'])) {
80 80
                             return $v;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
                             default:
97 97
                                 if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
98 98
                                     // extract length from varchar
99
-                                    $v['length'] = (int)explode(')', explode('(', $type)[1])[0];
99
+                                    $v['length'] = (int) explode(')', explode('(', $type)[1])[0];
100 100
                                     $v['length'] = $v['length'] > 0 ? $v['length'] : null;
101 101
                                 }
102 102
                                 break;
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
             ->setPrimaryKey(
109 109
                 $columns
110 110
                     ->clone()
111
-                    ->filter(function ($v) {
111
+                    ->filter(function($v) {
112 112
                         return $v['Key'] === 'PRI';
113 113
                     })
114 114
                     ->pluck('Field')
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
                 $usedcol = [];
139 139
                 if (count($columns)) {
140 140
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
141
-                        ->filter(function ($v) use ($columns) {
141
+                        ->filter(function($v) use ($columns) {
142 142
                             return in_array($v['COLUMN_NAME'], $columns);
143 143
                         })
144
-                        ->map(function ($v) {
144
+                        ->map(function($v) {
145 145
                             $new = [];
146 146
                             foreach ($v as $kk => $vv) {
147 147
                                 $new[strtoupper($kk)] = $vv;
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                     $relname = $foreign['table'];
161 161
                     $cntr = 1;
162 162
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
163
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
163
+                        $relname = $foreign['table'].'_'.(++$cntr);
164 164
                     }
165 165
                     $definition->addRelation(
166 166
                         new TableRelation(
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
                     $relname = $data['table'];
177 177
                     $cntr = 1;
178 178
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
179
-                        $relname = $data['table'] . '_' . (++ $cntr);
179
+                        $relname = $data['table'].'_'.(++$cntr);
180 180
                     }
181 181
                     $definition->addRelation(
182 182
                         new TableRelation(
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
             // resulting in a "belongsTo" relationship
194 194
             $relations = [];
195 195
             foreach (Collection::from($relationsT[$table] ?? [])
196
-                ->map(function ($v) {
196
+                ->map(function($v) {
197 197
                     $new = [];
198 198
                     foreach ($v as $kk => $vv) {
199 199
                         $new[strtoupper($kk)] = $vv;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
                 $relname = $data['table'];
210 210
                 $cntr = 1;
211 211
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
212
-                    $relname = $data['table'] . '_' . (++ $cntr);
212
+                    $relname = $data['table'].'_'.(++$cntr);
213 213
                 }
214 214
                 $definition->addRelation(
215 215
                     new TableRelation(
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                 "SELECT table_name FROM information_schema.tables where table_schema = ?",
231 231
                 [$this->connection['opts']['schema'] ?? $this->connection['name']]
232 232
             ))
233
-            ->map(function ($v) {
233
+            ->map(function($v) {
234 234
                 $new = [];
235 235
                 foreach ($v as $kk => $vv) {
236 236
                     $new[strtoupper($kk)] = $vv;
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
                 return $new;
239 239
             })
240 240
             ->pluck('TABLE_NAME')
241
-            ->map(function ($v) {
241
+            ->map(function($v) {
242 242
                 return $this->table($v);
243 243
             })
244 244
             ->toArray();
Please login to merge, or discard this patch.
src/driver/mysql/Result.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
                 if ($temp) {
30 30
                     $temp = $temp->fetch_fields();
31 31
                     if ($temp) {
32
-                        $columns = array_map(function ($v) {
32
+                        $columns = array_map(function($v) {
33 33
                             return $v->name;
34 34
                         }, $temp);
35 35
                     }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
     }
71 71
     public function current()
72 72
     {
73
-        return $this->nativeDriver ? $this->last : array_map(function ($v) {
73
+        return $this->nativeDriver ? $this->last : array_map(function($v) {
74 74
             return $v;
75 75
         }, $this->row);
76 76
     }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     }
90 90
     public function next()
91 91
     {
92
-        $this->fetched ++;
92
+        $this->fetched++;
93 93
         $this->last = $this->nativeDriver ? $this->result->fetch_assoc() : $this->statement->fetch();
94 94
     }
95 95
     public function valid()
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +14 added lines, -17 removed lines patch added patch discarded remove patch
@@ -76,8 +76,7 @@  discard block
 block discarded – undo
76 76
             $connection['name'] = $path;
77 77
         }
78 78
         $connection['type'] = isset($aliases[$connection['type']]) ?
79
-            $aliases[$connection['type']] :
80
-            $connection['type'];
79
+            $aliases[$connection['type']] : $connection['type'];
81 80
         $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver';
82 81
         return new $tmp($connection);
83 82
     }
@@ -106,7 +105,7 @@  discard block
 block discarded – undo
106 105
         $new = '';
107 106
         $par = array_values($par);
108 107
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
109
-            $par = [ $par ];
108
+            $par = [$par];
110 109
         }
111 110
         $parts = explode('??', $sql);
112 111
         $index = 0;
@@ -116,7 +115,7 @@  discard block
 block discarded – undo
116 115
             $index += count($tmp) - 1;
117 116
             if (isset($par[$index])) {
118 117
                 if (!is_array($par[$index])) {
119
-                    $par[$index] = [ $par[$index] ];
118
+                    $par[$index] = [$par[$index]];
120 119
                 }
121 120
                 $params = $par[$index];
122 121
                 array_splice($par, $index, 1, $params);
@@ -124,7 +123,7 @@  discard block
 block discarded – undo
124 123
                 $new .= implode(',', array_fill(0, count($params), '?'));
125 124
             }
126 125
         }
127
-        return [ $new, $par ];
126
+        return [$new, $par];
128 127
     }
129 128
     /**
130 129
      * Run a query (prepare & execute).
@@ -156,7 +155,7 @@  discard block
 block discarded – undo
156 155
     {
157 156
         $coll = Collection::from($this->query($sql, $par));
158 157
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
159
-            $coll->map(function ($v) use ($keys) {
158
+            $coll->map(function($v) use ($keys) {
160 159
                 $new = [];
161 160
                 foreach ($v as $k => $vv) {
162 161
                     $new[call_user_func($keys, $k)] = $vv;
@@ -165,18 +164,18 @@  discard block
 block discarded – undo
165 164
             });
166 165
         }
167 166
         if ($key !== null) {
168
-            $coll->mapKey(function ($v) use ($key) {
167
+            $coll->mapKey(function($v) use ($key) {
169 168
                 return $v[$key];
170 169
             });
171 170
         }
172 171
         if ($skip) {
173
-            $coll->map(function ($v) use ($key) {
172
+            $coll->map(function($v) use ($key) {
174 173
                 unset($v[$key]);
175 174
                 return $v;
176 175
             });
177 176
         }
178 177
         if ($opti) {
179
-            $coll->map(function ($v) {
178
+            $coll->map(function($v) {
180 179
                 return count($v) === 1 ? current($v) : $v;
181 180
             });
182 181
         }
@@ -262,8 +261,7 @@  discard block
 block discarded – undo
262 261
     public function definition(string $table, bool $detectRelations = true) : Table
263 262
     {
264 263
         return isset($this->tables[$table]) ?
265
-            $this->tables[$table] :
266
-            $this->driver->table($table, $detectRelations);
264
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
267 265
     }
268 266
     /**
269 267
      * Parse all tables from the database.
@@ -280,12 +278,12 @@  discard block
 block discarded – undo
280 278
      */
281 279
     public function getSchema($asPlainArray = true)
282 280
     {
283
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
281
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
284 282
             return [
285 283
                 'name' => $table->getName(),
286 284
                 'pkey' => $table->getPrimaryKey(),
287 285
                 'comment' => $table->getComment(),
288
-                'columns' => array_map(function ($column) {
286
+                'columns' => array_map(function($column) {
289 287
                     return [
290 288
                         'name' => $column->getName(),
291 289
                         'type' => $column->getType(),
@@ -296,9 +294,9 @@  discard block
 block discarded – undo
296 294
                         'nullable' => $column->isNullable()
297 295
                     ];
298 296
                 }, $table->getFullColumns()),
299
-                'relations' => array_map(function ($rel) {
297
+                'relations' => array_map(function($rel) {
300 298
                     $relation = clone $rel;
301
-                    $relation = (array)$relation;
299
+                    $relation = (array) $relation;
302 300
                     $relation['table'] = $rel->table->getName();
303 301
                     if ($rel->pivot) {
304 302
                         $relation['pivot'] = $rel->pivot->getName();
@@ -351,8 +349,7 @@  discard block
 block discarded – undo
351 349
     public function table($table, bool $mapped = false)
352 350
     {
353 351
         return $mapped ?
354
-            new TableQueryMapped($this, $this->definition($table)) :
355
-            new TableQuery($this, $this->definition($table));
352
+            new TableQueryMapped($this, $this->definition($table)) : new TableQuery($this, $this->definition($table));
356 353
     }
357 354
     public function __call($method, $args)
358 355
     {
Please login to merge, or discard this patch.
src/schema/Mapper.php 1 patch
Spacing   +7 added lines, -9 removed lines patch added patch discarded remove patch
@@ -80,8 +80,7 @@  discard block
 block discarded – undo
80 80
                 if (isset($this->definition->getRelations()[$method])) {
81 81
                     if (array_key_exists($method, $this->fetched)) {
82 82
                         return is_callable($this->fetched[$method]) ?
83
-                            $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) :
84
-                            $this->fetched[$method];
83
+                            $this->fetched[$method] = call_user_func($this->fetched[$method], $args[0] ?? null) : $this->fetched[$method];
85 84
                     }
86 85
                 }
87 86
                 return null;
@@ -165,7 +164,7 @@  discard block
 block discarded – undo
165 164
     public function collection(TableQueryIterator $iterator, Table $definition) : Collection
166 165
     {
167 166
         return Collection::from($iterator)
168
-            ->map(function ($v) use ($definition) {
167
+            ->map(function($v) use ($definition) {
169 168
                 return $this->entity($definition, $v);
170 169
             });
171 170
     }
@@ -240,7 +239,7 @@  discard block
 block discarded – undo
240 239
         $definition = $entity->definition();
241 240
         foreach ($definition->getColumns() as $column) {
242 241
             if (!array_key_exists($column, $data)) {
243
-                $entity->__lazyProperty($column, function () use ($definition, $primary, $column) {
242
+                $entity->__lazyProperty($column, function() use ($definition, $primary, $column) {
244 243
                     $query = $this->db->table($definition->getName());
245 244
                     foreach ($primary as $k => $v) {
246 245
                         $query->filter($k, $v);
@@ -254,12 +253,12 @@  discard block
 block discarded – undo
254 253
                 $name,
255 254
                 array_key_exists($name, $data) && isset($data[$name]) ?
256 255
                     ($relation->many ?
257
-                        array_map(function ($v) use ($relation) {
256
+                        array_map(function($v) use ($relation) {
258 257
                             return $this->entity($relation->table, $v);
259 258
                         }, $data[$name]) :
260 259
                         $this->entity($relation->table, $data[$name])
261 260
                     ) :
262
-                    function (array $columns = null) use ($entity, $definition, $relation, $data) {
261
+                    function(array $columns = null) use ($entity, $definition, $relation, $data) {
263 262
                         $query = $this->db->table($relation->table->getName(), true);
264 263
                         if ($columns !== null) {
265 264
                             $query->columns($columns);
@@ -285,7 +284,7 @@  discard block
 block discarded – undo
285 284
                                 );
286 285
                             }
287 286
                             foreach ($definition->getPrimaryKey() as $v) {
288
-                                $query->filter($nm . '.' . $v, $data[$v] ?? null);
287
+                                $query->filter($nm.'.'.$v, $data[$v] ?? null);
289 288
                             }
290 289
                         } else {
291 290
                             foreach ($relation->keymap as $k => $v) {
@@ -293,8 +292,7 @@  discard block
 block discarded – undo
293 292
                             }
294 293
                         }
295 294
                         return $relation->many ?
296
-                            $query->iterator() :
297
-                            $query[0];
295
+                            $query->iterator() : $query[0];
298 296
                     }
299 297
             );
300 298
         }
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +184 added lines, -188 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     /**
45 45
      * @var int[]
46 46
      */
47
-    protected $li_of = [0,0,0];
47
+    protected $li_of = [0, 0, 0];
48 48
     /**
49 49
      * @var array
50 50
      */
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public function __construct(DBInterface $db, $table)
75 75
     {
76 76
         $this->db = $db;
77
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
77
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
78 78
         $primary = $this->definition->getPrimaryKey();
79 79
         $columns = $this->definition->getColumns();
80 80
         $this->pkey = count($primary) ? $primary : $columns;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $column = explode('.', $column);
99 99
         if (count($column) === 1) {
100
-            $column = [ $this->definition->getName(), $column[0] ];
100
+            $column = [$this->definition->getName(), $column[0]];
101 101
             $col = $this->definition->getColumn($column[1]);
102 102
             if (!$col) {
103 103
                 throw new DBException('Invalid column name in own table');
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                         throw new DBException('Invalid column name in related table');
121 121
                     }
122 122
                 } else {
123
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
123
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
124 124
                 }
125 125
             }
126 126
         } else {
@@ -129,19 +129,19 @@  discard block
 block discarded – undo
129 129
             $table = $this->definition;
130 130
             $table = array_reduce(
131 131
                 $column,
132
-                function ($carry, $item) use (&$table) {
132
+                function($carry, $item) use (&$table) {
133 133
                     $table = $table->getRelation($item)->table;
134 134
                     return $table;
135 135
                 }
136 136
             );
137 137
             $col = $table->getColumn($name);
138
-            $column = [ implode(static::SEP, $column), $name ];
138
+            $column = [implode(static::SEP, $column), $name];
139 139
         }
140
-        return [ 'name' => implode('.', $column), 'data' => $col ];
140
+        return ['name' => implode('.', $column), 'data' => $col];
141 141
     }
142 142
     protected function normalizeValue(TableColumn $col, $value)
143 143
     {
144
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
144
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
145 145
         if ($value === null && $col->isNullable()) {
146 146
             return null;
147 147
         }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                     $temp = strtotime($value);
152 152
                     if (!$temp) {
153 153
                         if ($strict) {
154
-                            throw new DBException('Invalid value for date column ' . $col->getName());
154
+                            throw new DBException('Invalid value for date column '.$col->getName());
155 155
                         }
156 156
                         return null;
157 157
                     }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                     return $value->format('Y-m-d');
165 165
                 }
166 166
                 if ($strict) {
167
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
167
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
168 168
                 }
169 169
                 return $value;
170 170
             case 'datetime':
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
                     $temp = strtotime($value);
173 173
                     if (!$temp) {
174 174
                         if ($strict) {
175
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
175
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
176 176
                         }
177 177
                         return null;
178 178
                     }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                     return $value->format('Y-m-d H:i:s');
186 186
                 }
187 187
                 if ($strict) {
188
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
188
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
189 189
                 }
190 190
                 return $value;
191 191
             case 'enum':
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                 if (is_int($value)) {
194 194
                     if (!isset($values[$value])) {
195 195
                         if ($strict) {
196
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
196
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
197 197
                         }
198 198
                         return $value;
199 199
                     }
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
                 }
202 202
                 if (!in_array($value, $col->getValues())) {
203 203
                     if ($strict) {
204
-                        throw new DBException('Invalid value for enum ' . $col->getName());
204
+                        throw new DBException('Invalid value for enum '.$col->getName());
205 205
                     }
206 206
                     return 0;
207 207
                 }
208 208
                 return $value;
209 209
             case 'int':
210
-                return (int)preg_replace('([^+\-0-9]+)', '', $value);
210
+                return (int) preg_replace('([^+\-0-9]+)', '', $value);
211 211
             case 'float':
212
-                return (float)preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
212
+                return (float) preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
213 213
             case 'text':
214 214
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
215 215
                 // because the polyfill is quite slow
216 216
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
217 217
                     if ($strict) {
218
-                        throw new DBException('Invalid value for text column ' . $col->getName());
218
+                        throw new DBException('Invalid value for text column '.$col->getName());
219 219
                     }
220 220
                     return mb_substr($value, 0, $col->getLength());
221 221
                 }
@@ -237,35 +237,32 @@  discard block
 block discarded – undo
237 237
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
238 238
             return $negate ?
239 239
                 [
240
-                    $name . ' NOT LIKE ?',
241
-                    [ $this->normalizeValue($column, $value) ]
242
-                ] :
243
-                [
244
-                    $name . ' LIKE ?',
245
-                    [ $this->normalizeValue($column, $value) ]
240
+                    $name.' NOT LIKE ?',
241
+                    [$this->normalizeValue($column, $value)]
242
+                ] : [
243
+                    $name.' LIKE ?',
244
+                    [$this->normalizeValue($column, $value)]
246 245
                 ];
247 246
         }
248 247
         if (is_null($value)) {
249 248
             return $negate ?
250
-                [ $name . ' IS NOT NULL', [] ]:
251
-                [ $name . ' IS NULL', [] ];
249
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
252 250
         }
253 251
         if (!is_array($value)) {
254 252
             return $negate ?
255 253
                 [
256
-                    $name . ' <> ?',
257
-                    [ $this->normalizeValue($column, $value) ]
258
-                ] :
259
-                [
260
-                    $name . ' = ?',
261
-                    [ $this->normalizeValue($column, $value) ]
254
+                    $name.' <> ?',
255
+                    [$this->normalizeValue($column, $value)]
256
+                ] : [
257
+                    $name.' = ?',
258
+                    [$this->normalizeValue($column, $value)]
262 259
                 ];
263 260
         }
264 261
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
265
-            $value = [ 'gte' => $value['beg'] ];
262
+            $value = ['gte' => $value['beg']];
266 263
         }
267 264
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
268
-            $value = [ 'lte' => $value['end'] ];
265
+            $value = ['lte' => $value['end']];
269 266
         }
270 267
         if (isset($value['beg']) && isset($value['end'])) {
271 268
             return $negate ?
@@ -275,8 +272,7 @@  discard block
 block discarded – undo
275 272
                         $this->normalizeValue($column, $value['beg']),
276 273
                         $this->normalizeValue($column, $value['end'])
277 274
                     ]
278
-                ] :
279
-                [
275
+                ] : [
280 276
                     $name.' BETWEEN ? AND ?',
281 277
                     [
282 278
                         $this->normalizeValue($column, $value['beg']),
@@ -288,38 +284,38 @@  discard block
 block discarded – undo
288 284
             $sql = [];
289 285
             $par = [];
290 286
             if (isset($value['gt'])) {
291
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
287
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
292 288
                 $par[] = $this->normalizeValue($column, $value['gt']);
293 289
             }
294 290
             if (isset($value['gte'])) {
295
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
291
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
296 292
                 $par[] = $this->normalizeValue($column, $value['gte']);
297 293
             }
298 294
             if (isset($value['lt'])) {
299
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
295
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
300 296
                 $par[] = $this->normalizeValue($column, $value['lt']);
301 297
             }
302 298
             if (isset($value['lte'])) {
303
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
299
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
304 300
                 $par[] = $this->normalizeValue($column, $value['lte']);
305 301
             }
306 302
             return [
307
-                '(' . implode(' AND ', $sql) . ')',
303
+                '('.implode(' AND ', $sql).')',
308 304
                 $par
309 305
             ];
310 306
         }
311 307
         return $negate ?
312 308
             [
313
-                $name . ' NOT IN (??)',
314
-                [ array_map(function ($v) use ($column) {
309
+                $name.' NOT IN (??)',
310
+                [array_map(function($v) use ($column) {
315 311
                     return $this->normalizeValue($column, $v);
316
-                }, $value) ]
312
+                }, $value)]
317 313
             ] :
318 314
             [
319
-                $name . ' IN (??)',
320
-                [ array_map(function ($v) use ($column) {
315
+                $name.' IN (??)',
316
+                [array_map(function($v) use ($column) {
321 317
                     return $this->normalizeValue($column, $v);
322
-                }, $value) ]
318
+                }, $value)]
323 319
             ];
324 320
     }
325 321
     /**
@@ -350,7 +346,7 @@  discard block
 block discarded – undo
350 346
                 $par = array_merge($par, $temp[1]);
351 347
             }
352 348
         }
353
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
349
+        return $this->where('('.implode(' OR ', $sql).')', $par);
354 350
     }
355 351
     /**
356 352
      * Filter the results matching all of the criteria
@@ -368,7 +364,7 @@  discard block
 block discarded – undo
368 364
                 $par = array_merge($par, $temp[1]);
369 365
             }
370 366
         }
371
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
367
+        return $this->where('('.implode(' AND ', $sql).')', $par);
372 368
     }
373 369
     /**
374 370
      * Sort by a column
@@ -378,7 +374,7 @@  discard block
 block discarded – undo
378 374
      */
379 375
     public function sort(string $column, bool $desc = false) : self
380 376
     {
381
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
377
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
382 378
     }
383 379
     /**
384 380
      * Group by a column (or columns)
@@ -388,7 +384,7 @@  discard block
 block discarded – undo
388 384
     public function group($column) : self
389 385
     {
390 386
         if (!is_array($column)) {
391
-            $column = [ $column ];
387
+            $column = [$column];
392 388
         }
393 389
         foreach ($column as $k => $v) {
394 390
             $column[$k] = $this->getColumn($v)['name'];
@@ -430,7 +426,7 @@  discard block
 block discarded – undo
430 426
         $this->order = [];
431 427
         $this->having = [];
432 428
         $this->aliases = [];
433
-        $this->li_of = [0,0,0];
429
+        $this->li_of = [0, 0, 0];
434 430
         $this->qiterator = null;
435 431
         return $this;
436 432
     }
@@ -443,7 +439,7 @@  discard block
 block discarded – undo
443 439
     public function groupBy(string $sql, array $params = []) : self
444 440
     {
445 441
         $this->qiterator = null;
446
-        $this->group = [ $sql, $params ];
442
+        $this->group = [$sql, $params];
447 443
         return $this;
448 444
     }
449 445
     /**
@@ -456,7 +452,7 @@  discard block
 block discarded – undo
456 452
      */
457 453
     public function join($table, array $fields, string $name = null, bool $multiple = true)
458 454
     {
459
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
455
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
460 456
         $name = $name ?? $table->getName();
461 457
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
462 458
             throw new DBException('Alias / table name already in use');
@@ -465,7 +461,7 @@  discard block
 block discarded – undo
465 461
         foreach ($fields as $k => $v) {
466 462
             $k = explode('.', $k, 2);
467 463
             $k = count($k) == 2 ? $k[1] : $k[0];
468
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
464
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
469 465
         }
470 466
         return $this;
471 467
     }
@@ -478,7 +474,7 @@  discard block
 block discarded – undo
478 474
     public function where(string $sql, array $params = []) : self
479 475
     {
480 476
         $this->qiterator = null;
481
-        $this->where[] = [ $sql, $params ];
477
+        $this->where[] = [$sql, $params];
482 478
         return $this;
483 479
     }
484 480
     /**
@@ -490,7 +486,7 @@  discard block
 block discarded – undo
490 486
     public function having(string $sql, array $params = []) : self
491 487
     {
492 488
         $this->qiterator = null;
493
-        $this->having[] = [ $sql, $params ];
489
+        $this->having[] = [$sql, $params];
494 490
         return $this;
495 491
     }
496 492
     /**
@@ -511,7 +507,7 @@  discard block
 block discarded – undo
511 507
                 $name = null;
512 508
             }
513 509
         }
514
-        $this->order = [ $sql, $params, $name ];
510
+        $this->order = [$sql, $params, $name];
515 511
         return $this;
516 512
     }
517 513
     /**
@@ -523,7 +519,7 @@  discard block
 block discarded – undo
523 519
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
524 520
     {
525 521
         $this->qiterator = null;
526
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
522
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
527 523
         return $this;
528 524
     }
529 525
     /**
@@ -533,9 +529,9 @@  discard block
 block discarded – undo
533 529
     public function count() : int
534 530
     {
535 531
         $aliases = [];
536
-        $getAlias = function ($name) use (&$aliases) {
532
+        $getAlias = function($name) use (&$aliases) {
537 533
             // to bypass use: return $name;
538
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
534
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
539 535
         };
540 536
         $table = $this->definition->getName();
541 537
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -549,47 +545,47 @@  discard block
 block discarded – undo
549 545
         $h = $this->having;
550 546
         $o = $this->order;
551 547
         $g = $this->group;
552
-        $j = array_map(function ($v) {
548
+        $j = array_map(function($v) {
553 549
             return clone $v;
554 550
         }, $this->joins);
555 551
         foreach ($this->definition->getRelations() as $k => $v) {
556 552
             foreach ($w as $kk => $vv) {
557
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
558
-                    $relations[$k] = [ $v, $table ];
559
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
553
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
554
+                    $relations[$k] = [$v, $table];
555
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
560 556
                 }
561 557
             }
562
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
563
-                $relations[$k] = [ $v, $table ];
558
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
559
+                $relations[$k] = [$v, $table];
564 560
             }
565 561
             foreach ($h as $kk => $vv) {
566
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
567
-                    $relations[$k] = [ $v, $table ];
568
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
562
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
563
+                    $relations[$k] = [$v, $table];
564
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
569 565
                 }
570 566
             }
571
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
572
-                $relations[$k] = [ $v, $table ];
573
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
567
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
568
+                $relations[$k] = [$v, $table];
569
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
574 570
             }
575 571
             foreach ($j as $kk => $vv) {
576 572
                 foreach ($vv->keymap as $kkk => $vvv) {
577
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
578
-                        $relations[$k] = [ $v, $table ];
573
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
574
+                        $relations[$k] = [$v, $table];
579 575
                         $j[$kk]->keymap[$kkk] =
580
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
576
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
581 577
                     }
582 578
                 }
583 579
             }
584 580
         }
585 581
 
586 582
         foreach ($j as $k => $v) {
587
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
583
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
588 584
             $tmp = [];
589 585
             foreach ($v->keymap as $kk => $vv) {
590 586
                 $tmp[] = $kk.' = '.$vv;
591 587
             }
592
-            $sql .= implode(' AND ', $tmp) . ' ';
588
+            $sql .= implode(' AND ', $tmp).' ';
593 589
         }
594 590
         foreach ($relations as $k => $v) {
595 591
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -601,13 +597,13 @@  discard block
 block discarded – undo
601 597
                 foreach ($v->keymap as $kk => $vv) {
602 598
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
603 599
                 }
604
-                $sql .= implode(' AND ', $tmp) . ' ';
600
+                $sql .= implode(' AND ', $tmp).' ';
605 601
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
606 602
                 $tmp = [];
607 603
                 foreach ($v->pivot_keymap as $kk => $vv) {
608 604
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
609 605
                 }
610
-                $sql .= implode(' AND ', $tmp) . ' ';
606
+                $sql .= implode(' AND ', $tmp).' ';
611 607
             } else {
612 608
                 $alias = $getAlias($k);
613 609
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -616,30 +612,30 @@  discard block
 block discarded – undo
616 612
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
617 613
                 }
618 614
                 if ($v->sql) {
619
-                    $tmp[] = $v->sql . ' ';
615
+                    $tmp[] = $v->sql.' ';
620 616
                     $par = array_merge($par, $v->par ?? []);
621 617
                 }
622
-                $sql .= implode(' AND ', $tmp) . ' ';
618
+                $sql .= implode(' AND ', $tmp).' ';
623 619
             }
624 620
         }
625 621
         if (count($w)) {
626 622
             $sql .= 'WHERE ';
627 623
             $tmp = [];
628 624
             foreach ($w as $v) {
629
-                $tmp[] = '(' . $v[0] . ')';
625
+                $tmp[] = '('.$v[0].')';
630 626
                 $par = array_merge($par, $v[1]);
631 627
             }
632 628
             $sql .= implode(' AND ', $tmp).' ';
633 629
         }
634 630
         if (count($g)) {
635
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
631
+            $sql .= 'GROUP BY '.$g[0].' ';
636 632
             $par = array_merge($par, $g[1]);
637 633
         }
638 634
         if (count($h)) {
639 635
             $sql .= 'HAVING ';
640 636
             $tmp = [];
641 637
             foreach ($h as $v) {
642
-                $tmp[] = '(' . $v[0] . ')';
638
+                $tmp[] = '('.$v[0].')';
643 639
                 $par = array_merge($par, $v[1]);
644 640
             }
645 641
             $sql .= implode(' AND ', $tmp).' ';
@@ -673,7 +669,7 @@  discard block
 block discarded – undo
673 669
                     $this->with(implode('.', $temp));
674 670
                     $table = array_reduce(
675 671
                         $temp,
676
-                        function ($carry, $item) use (&$table) {
672
+                        function($carry, $item) use (&$table) {
677 673
                             return $table->getRelation($item)->table;
678 674
                         }
679 675
                     );
@@ -682,7 +678,7 @@  discard block
 block discarded – undo
682 678
                 }
683 679
                 unset($fields[$k]);
684 680
                 foreach ($cols as $col) {
685
-                    $fields[] = $table . '.' . $col;
681
+                    $fields[] = $table.'.'.$col;
686 682
                 }
687 683
             }
688 684
         }
@@ -714,9 +710,9 @@  discard block
 block discarded – undo
714 710
             return $this->qiterator;
715 711
         }
716 712
         $aliases = [];
717
-        $getAlias = function ($name) use (&$aliases) {
713
+        $getAlias = function($name) use (&$aliases) {
718 714
             // to bypass use: return $name;
719
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
715
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
720 716
         };
721 717
         $table = $this->definition->getName();
722 718
         if ($fields !== null) {
@@ -732,7 +728,7 @@  discard block
 block discarded – undo
732 728
         $h = $this->having;
733 729
         $o = $this->order;
734 730
         $g = $this->group;
735
-        $j = array_map(function ($v) {
731
+        $j = array_map(function($v) {
736 732
             return clone $v;
737 733
         }, $this->joins);
738 734
 
@@ -743,47 +739,47 @@  discard block
 block discarded – undo
743 739
 
744 740
         foreach ($this->definition->getRelations() as $k => $relation) {
745 741
             foreach ($f as $kk => $field) {
746
-                if (strpos($field, $k . '.') === 0) {
747
-                    $relations[$k] = [ $relation, $table ];
748
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
742
+                if (strpos($field, $k.'.') === 0) {
743
+                    $relations[$k] = [$relation, $table];
744
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
749 745
                 }
750 746
             }
751 747
             foreach ($w as $kk => $v) {
752
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
753
-                    $relations[$k] = [ $relation, $table ];
754
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
748
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
749
+                    $relations[$k] = [$relation, $table];
750
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
755 751
                 }
756 752
             }
757 753
             foreach ($h as $kk => $v) {
758
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
759
-                    $relations[$k] = [ $relation, $table ];
760
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
754
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
755
+                    $relations[$k] = [$relation, $table];
756
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
761 757
                 }
762 758
             }
763
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
764
-                $relations[$k] = [ $relation, $table ];
765
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
759
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
760
+                $relations[$k] = [$relation, $table];
761
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
766 762
             }
767
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
768
-                $relations[$k] = [ $relation, $table ];
769
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
763
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
764
+                $relations[$k] = [$relation, $table];
765
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
770 766
             }
771 767
             foreach ($j as $kk => $v) {
772 768
                 foreach ($v->keymap as $kkk => $vv) {
773
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
774
-                        $relations[$k] = [ $relation, $table ];
775
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
769
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
770
+                        $relations[$k] = [$relation, $table];
771
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
776 772
                     }
777 773
                 }
778 774
             }
779 775
         }
780 776
         $select = [];
781 777
         foreach ($f as $k => $field) {
782
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
778
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
783 779
         }
784 780
         foreach ($this->withr as $name => $relation) {
785 781
             foreach ($relation[0]->table->getColumns() as $column) {
786
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
782
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
787 783
             }
788 784
         }
789 785
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
@@ -793,12 +789,12 @@  discard block
 block discarded – undo
793 789
             if ($v->many) {
794 790
                 $many = true;
795 791
             }
796
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
792
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
797 793
             $tmp = [];
798 794
             foreach ($v->keymap as $kk => $vv) {
799 795
                 $tmp[] = $kk.' = '.$vv;
800 796
             }
801
-            $sql .= implode(' AND ', $tmp) . ' ';
797
+            $sql .= implode(' AND ', $tmp).' ';
802 798
         }
803 799
         foreach ($relations as $relation => $v) {
804 800
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -813,13 +809,13 @@  discard block
 block discarded – undo
813 809
                 foreach ($v->keymap as $kk => $vv) {
814 810
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
815 811
                 }
816
-                $sql .= implode(' AND ', $tmp) . ' ';
812
+                $sql .= implode(' AND ', $tmp).' ';
817 813
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($relation).' ON ';
818 814
                 $tmp = [];
819 815
                 foreach ($v->pivot_keymap as $kk => $vv) {
820 816
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
821 817
                 }
822
-                $sql .= implode(' AND ', $tmp) . ' ';
818
+                $sql .= implode(' AND ', $tmp).' ';
823 819
             } else {
824 820
                 $alias = $getAlias($relation);
825 821
 
@@ -829,10 +825,10 @@  discard block
 block discarded – undo
829 825
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
830 826
                 }
831 827
                 if ($v->sql) {
832
-                    $tmp[] = $v->sql . ' ';
828
+                    $tmp[] = $v->sql.' ';
833 829
                     $par = array_merge($par, $v->par ?? []);
834 830
                 }
835
-                $sql .= implode(' AND ', $tmp) . ' ';
831
+                $sql .= implode(' AND ', $tmp).' ';
836 832
             }
837 833
         }
838 834
 
@@ -842,9 +838,9 @@  discard block
 block discarded – undo
842 838
                 if (count($porder) > 1) {
843 839
                     $pkw = [];
844 840
                     foreach ($porder as $name) {
845
-                        $pkw[] = $name . ' = ?';
841
+                        $pkw[] = $name.' = ?';
846 842
                     }
847
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
843
+                    $pkw = '('.implode(' AND ', $pkw).')';
848 844
                     $pkp = [];
849 845
                     foreach ($ids as $id) {
850 846
                         foreach ($id as $p) {
@@ -856,51 +852,51 @@  discard block
 block discarded – undo
856 852
                         $pkp
857 853
                     ];
858 854
                 } else {
859
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
855
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
860 856
                 }
861 857
             } else {
862
-                $w[] = [ '1=0', [] ];
858
+                $w[] = ['1=0', []];
863 859
             }
864 860
         }
865 861
         if (count($w)) {
866 862
             $sql .= 'WHERE ';
867 863
             $tmp = [];
868 864
             foreach ($w as $v) {
869
-                $tmp[] = '(' . $v[0] . ')';
865
+                $tmp[] = '('.$v[0].')';
870 866
                 $par = array_merge($par, $v[1]);
871 867
             }
872 868
             $sql .= implode(' AND ', $tmp).' ';
873 869
         }
874 870
         if (count($g)) {
875
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
871
+            $sql .= 'GROUP BY '.$g[0].' ';
876 872
             $par = array_merge($par, $g[1]);
877 873
         }
878 874
         if (count($h)) {
879 875
             $sql .= 'HAVING ';
880 876
             $tmp = [];
881 877
             foreach ($h as $v) {
882
-                $tmp[] = '(' . $v[0] . ')';
878
+                $tmp[] = '('.$v[0].')';
883 879
                 $par = array_merge($par, $v[1]);
884 880
             }
885 881
             $sql .= implode(' AND ', $tmp).' ';
886 882
         }
887 883
         if (count($o)) {
888
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
884
+            $sql .= 'ORDER BY '.$o[0].' ';
889 885
             $par = array_merge($par, $o[1]);
890 886
         }
891 887
         if (count($porder)) {
892 888
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
893
-            $porder = array_map(function ($v) use ($pdir) {
894
-                return $v . ' ' . $pdir;
889
+            $porder = array_map(function($v) use ($pdir) {
890
+                return $v.' '.$pdir;
895 891
             }, $porder);
896
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
892
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
897 893
         }
898 894
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
899 895
             if ($this->db->driverName() === 'oracle') {
900
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
901
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
896
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
897
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
902 898
                 } else {
903
-                    $f = array_map(function ($v) {
899
+                    $f = array_map(function($v) {
904 900
                         $v = explode(' ', trim($v), 2);
905 901
                         if (count($v) === 2) {
906 902
                             return $v[1];
@@ -908,16 +904,16 @@  discard block
 block discarded – undo
908 904
                         $v = explode('.', $v[0], 2);
909 905
                         return count($v) === 2 ? $v[1] : $v[0];
910 906
                     }, $select);
911
-                    $sql = "SELECT " . implode(', ', $f) . " 
907
+                    $sql = "SELECT ".implode(', ', $f)." 
912 908
                             FROM (
913 909
                                 SELECT tbl__.*, rownum rnum__ FROM (
914
-                                    " . $sql . "
910
+                                    " . $sql."
915 911
                                 ) tbl__ 
916
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
912
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
917 913
                             ) WHERE rnum__ > " . $this->li_of[1];
918 914
                 }
919 915
             } else {
920
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
916
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
921 917
             }
922 918
         }
923 919
         return $this->qiterator = new TableQueryIterator(
@@ -967,8 +963,8 @@  discard block
 block discarded – undo
967 963
                 $ret[$k] = str_repeat(' ', 255);
968 964
                 $par[] = &$ret[$k];
969 965
             }
970
-            $sql .= ' RETURNING ' . implode(',', $primary) .
971
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
966
+            $sql .= ' RETURNING '.implode(',', $primary).
967
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
972 968
             $this->db->query($sql, $par);
973 969
             return $ret;
974 970
         } else {
@@ -1000,9 +996,9 @@  discard block
 block discarded – undo
1000 996
         }
1001 997
         $sql = 'UPDATE '.$table.' SET ';
1002 998
         $par = [];
1003
-        $sql .= implode(', ', array_map(function ($v) {
1004
-            return $v . ' = ?';
1005
-        }, array_keys($update))) . ' ';
999
+        $sql .= implode(', ', array_map(function($v) {
1000
+            return $v.' = ?';
1001
+        }, array_keys($update))).' ';
1006 1002
         $par = array_merge($par, array_values($update));
1007 1003
         if (count($this->where)) {
1008 1004
             $sql .= 'WHERE ';
@@ -1011,7 +1007,7 @@  discard block
 block discarded – undo
1011 1007
                 $tmp[] = $v[0];
1012 1008
                 $par = array_merge($par, $v[1]);
1013 1009
             }
1014
-            $sql .= implode(' AND ', $tmp) . ' ';
1010
+            $sql .= implode(' AND ', $tmp).' ';
1015 1011
         }
1016 1012
         if (count($this->order)) {
1017 1013
             $sql .= $this->order[0];
@@ -1035,7 +1031,7 @@  discard block
 block discarded – undo
1035 1031
                 $tmp[] = $v[0];
1036 1032
                 $par = array_merge($par, $v[1]);
1037 1033
             }
1038
-            $sql .= implode(' AND ', $tmp) . ' ';
1034
+            $sql .= implode(' AND ', $tmp).' ';
1039 1035
         }
1040 1036
         if (count($this->order)) {
1041 1037
             $sql .= $this->order[0];
@@ -1055,13 +1051,13 @@  discard block
 block discarded – undo
1055 1051
         $table = $this->definition;
1056 1052
         array_reduce(
1057 1053
             $parts,
1058
-            function ($carry, $item) use (&$table) {
1054
+            function($carry, $item) use (&$table) {
1059 1055
                 $relation = $table->getRelation($item);
1060 1056
                 if (!$relation) {
1061 1057
                     throw new DBException('Invalid relation name');
1062 1058
                 }
1063
-                $name = $carry ? $carry . static::SEP . $item : $item;
1064
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
1059
+                $name = $carry ? $carry.static::SEP.$item : $item;
1060
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
1065 1061
                 $table = $relation->table;
1066 1062
                 return $name;
1067 1063
             }
@@ -1106,9 +1102,9 @@  discard block
 block discarded – undo
1106 1102
         }
1107 1103
 
1108 1104
         $aliases = [];
1109
-        $getAlias = function ($name) use (&$aliases) {
1105
+        $getAlias = function($name) use (&$aliases) {
1110 1106
             // to bypass use: return $name;
1111
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1107
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1112 1108
         };
1113 1109
         
1114 1110
         $table = $this->definition->getName();
@@ -1120,70 +1116,70 @@  discard block
 block discarded – undo
1120 1116
         $h = $this->having;
1121 1117
         $o = $this->order;
1122 1118
         $g = $this->group;
1123
-        $j = array_map(function ($v) {
1119
+        $j = array_map(function($v) {
1124 1120
             return clone $v;
1125 1121
         }, $this->joins);
1126 1122
         foreach ($this->definition->getRelations() as $k => $v) {
1127 1123
             foreach ($w as $kk => $vv) {
1128
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1129
-                    $relations[$k] = [ $v, $table ];
1130
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1124
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1125
+                    $relations[$k] = [$v, $table];
1126
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1131 1127
                 }
1132 1128
             }
1133
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1134
-                $relations[$k] = [ $v, $table ];
1135
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1136
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1129
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1130
+                $relations[$k] = [$v, $table];
1131
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1132
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1137 1133
             }
1138 1134
             foreach ($h as $kk => $vv) {
1139
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1140
-                    $relations[$k] = [ $v, $table ];
1141
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1135
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1136
+                    $relations[$k] = [$v, $table];
1137
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1142 1138
                 }
1143 1139
             }
1144
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1145
-                $relations[$k] = [ $v, $table ];
1146
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1140
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1141
+                $relations[$k] = [$v, $table];
1142
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1147 1143
             }
1148 1144
             foreach ($j as $kk => $vv) {
1149 1145
                 foreach ($vv->keymap as $kkk => $vvv) {
1150
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1151
-                        $relations[$k] = [ $v, $table ];
1146
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1147
+                        $relations[$k] = [$v, $table];
1152 1148
                         $j[$kk]->keymap[$kkk] =
1153
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1149
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1154 1150
                     }
1155 1151
                 }
1156 1152
             }
1157 1153
         }
1158 1154
 
1159
-        $key = array_map(function ($v) use ($table) {
1160
-            return $table . '.' . $v;
1155
+        $key = array_map(function($v) use ($table) {
1156
+            return $table.'.'.$v;
1161 1157
         }, $this->pkey);
1162 1158
         $own = false;
1163 1159
         $dir = 'ASC';
1164 1160
         if (count($o)) {
1165 1161
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1166
-            $own = strpos($o[2], $table . '.') === 0;
1162
+            $own = strpos($o[2], $table.'.') === 0;
1167 1163
         }
1168 1164
 
1169 1165
         $dst = $key;
1170 1166
         if ($own) {
1171 1167
             // if using own table - do not use max/min in order - that will prevent index usage
1172
-            $dst[] = $o[2] . ' orderbyfix___';
1168
+            $dst[] = $o[2].' orderbyfix___';
1173 1169
         } else {
1174
-            $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1170
+            $dst[] = 'MAX('.$o[2].') orderbyfix___';
1175 1171
         }
1176 1172
         $dst = array_unique($dst);
1177 1173
 
1178 1174
         $par = [];
1179
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1175
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1180 1176
         foreach ($j as $k => $v) {
1181
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1177
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1182 1178
             $tmp = [];
1183 1179
             foreach ($v->keymap as $kk => $vv) {
1184 1180
                 $tmp[] = $kk.' = '.$vv;
1185 1181
             }
1186
-            $sql .= implode(' AND ', $tmp) . ' ';
1182
+            $sql .= implode(' AND ', $tmp).' ';
1187 1183
         }
1188 1184
         foreach ($relations as $k => $v) {
1189 1185
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -1195,13 +1191,13 @@  discard block
 block discarded – undo
1195 1191
                 foreach ($v->keymap as $kk => $vv) {
1196 1192
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1197 1193
                 }
1198
-                $sql .= implode(' AND ', $tmp) . ' ';
1194
+                $sql .= implode(' AND ', $tmp).' ';
1199 1195
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1200 1196
                 $tmp = [];
1201 1197
                 foreach ($v->pivot_keymap as $kk => $vv) {
1202 1198
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1203 1199
                 }
1204
-                $sql .= implode(' AND ', $tmp) . ' ';
1200
+                $sql .= implode(' AND ', $tmp).' ';
1205 1201
             } else {
1206 1202
                 $alias = $getAlias($k);
1207 1203
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1210,29 +1206,29 @@  discard block
 block discarded – undo
1210 1206
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1211 1207
                 }
1212 1208
                 if ($v->sql) {
1213
-                    $tmp[] = $v->sql . ' ';
1209
+                    $tmp[] = $v->sql.' ';
1214 1210
                     $par = array_merge($par, $v->par ?? []);
1215 1211
                 }
1216
-                $sql .= implode(' AND ', $tmp) . ' ';
1212
+                $sql .= implode(' AND ', $tmp).' ';
1217 1213
             }
1218 1214
         }
1219 1215
         if (count($w)) {
1220 1216
             $sql .= 'WHERE ';
1221 1217
             $tmp = [];
1222 1218
             foreach ($w as $v) {
1223
-                $tmp[] = '(' . $v[0] . ')';
1219
+                $tmp[] = '('.$v[0].')';
1224 1220
                 $par = array_merge($par, $v[1]);
1225 1221
             }
1226 1222
             $sql .= implode(' AND ', $tmp).' ';
1227 1223
         }
1228 1224
         if (!$own) {
1229
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1225
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1230 1226
         }
1231 1227
         if (count($h)) {
1232 1228
             $sql .= 'HAVING ';
1233 1229
             $tmp = [];
1234 1230
             foreach ($h as $v) {
1235
-                $tmp[] = '(' . $v[0] . ')';
1231
+                $tmp[] = '('.$v[0].')';
1236 1232
                 $par = array_merge($par, $v[1]);
1237 1233
             }
1238 1234
             $sql .= implode(' AND ', $tmp).' ';
@@ -1240,38 +1236,38 @@  discard block
 block discarded – undo
1240 1236
         if (count($o)) {
1241 1237
             $sql .= 'ORDER BY ';
1242 1238
             if ($own) {
1243
-                $sql .= $o[2] . ' ' . $dir;
1239
+                $sql .= $o[2].' '.$dir;
1244 1240
             } else {
1245
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1241
+                $sql .= 'MAX('.$o[2].') '.$dir;
1246 1242
             }
1247 1243
         }
1248 1244
         $porder = [];
1249 1245
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1250 1246
         foreach ($this->definition->getPrimaryKey() as $field) {
1251
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1247
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1252 1248
         }
1253 1249
         if (count($porder)) {
1254
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1250
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1255 1251
         }
1256 1252
 
1257 1253
         if ($this->li_of[0]) {
1258 1254
             if ($this->db->driverName() === 'oracle') {
1259
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1260
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1255
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1256
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1261 1257
                 } else {
1262
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1258
+                    $sql = "SELECT ".implode(', ', $dst)." 
1263 1259
                             FROM (
1264 1260
                                 SELECT tbl__.*, rownum rnum__ FROM (
1265
-                                    " . $sql . "
1261
+                                    " . $sql."
1266 1262
                                 ) tbl__ 
1267
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1263
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1268 1264
                             ) WHERE rnum__ > " . $this->li_of[1];
1269 1265
                 }
1270 1266
             } else {
1271
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1267
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1272 1268
             }
1273 1269
         }
1274
-        return array_map(function ($v) {
1270
+        return array_map(function($v) {
1275 1271
             if (isset($v['orderbyfix___'])) {
1276 1272
                 unset($v['orderbyfix___']);
1277 1273
             }
Please login to merge, or discard this patch.