Completed
Push — master ( 56d969...e6de36 )
by Ivan
11:25
created
src/driver/postgre/Statement.php 1 patch
Spacing   +13 added lines, -15 removed lines patch added patch discarded remove patch
@@ -25,17 +25,17 @@  discard block
 block discarded – undo
25 25
         if (strpos(strtolower($statement), 'prepare') === 0) {
26 26
             $this->drv->raw($this->statement);
27 27
             if (!isset($this->name)) {
28
-                $this->name = trim((preg_split('(\s+)', trim($this->statement))?:[])[1]??'', '"');
28
+                $this->name = trim((preg_split('(\s+)', trim($this->statement)) ?: [])[1] ?? '', '"');
29 29
             }
30 30
         } elseif ($this->name !== null) {
31 31
             $temp = \pg_prepare($this->driver, $this->name, $this->statement);
32 32
             if (!$temp) {
33 33
                 $log = $this->drv->option('log_file');
34
-                if ($log && (int)$this->drv->option('log_errors', 1)) {
34
+                if ($log && (int) $this->drv->option('log_errors', 1)) {
35 35
                     @file_put_contents(
36 36
                         $log,
37
-                        '--' . date('Y-m-d H:i:s') . ' ERROR PREPARING: ' . \pg_last_error($this->driver) . "\r\n" .
38
-                        $this->statement . "\r\n" .
37
+                        '--'.date('Y-m-d H:i:s').' ERROR PREPARING: '.\pg_last_error($this->driver)."\r\n".
38
+                        $this->statement."\r\n".
39 39
                         "\r\n",
40 40
                         FILE_APPEND
41 41
                     );
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         if (isset($this->map)) {
58 58
             $par = [];
59 59
             foreach ($this->map as $key) {
60
-                $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key);
60
+                $par[] = $data[$key] ?? throw new DBException('Missing param '.$key);
61 61
             }
62 62
             $data = $par;
63 63
         }
@@ -68,22 +68,20 @@  discard block
 block discarded – undo
68 68
         try {
69 69
             if ($this->name !== null) {
70 70
                 $temp = (count($data)) ?
71
-                    \pg_execute($this->driver, $this->name, $data) :
72
-                    \pg_execute($this->driver, $this->name, array());
71
+                    \pg_execute($this->driver, $this->name, $data) : \pg_execute($this->driver, $this->name, array());
73 72
             } else {
74 73
                 $temp = (count($data)) ?
75
-                    \pg_query_params($this->driver, $this->statement, $data) :
76
-                    \pg_query_params($this->driver, $this->statement, array());
74
+                    \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array());
77 75
             }
78 76
         } catch (\Exception $e) {
79 77
             $temp = false;
80 78
         }
81 79
         if (!$temp) {
82
-            if ($log && (int)$this->drv->option('log_errors', 1)) {
80
+            if ($log && (int) $this->drv->option('log_errors', 1)) {
83 81
                 @file_put_contents(
84 82
                     $log,
85
-                    '--' . date('Y-m-d H:i:s') . ' ERROR: ' . \pg_last_error($this->driver) . "\r\n" .
86
-                    $this->statement . "\r\n" .
83
+                    '--'.date('Y-m-d H:i:s').' ERROR: '.\pg_last_error($this->driver)."\r\n".
84
+                    $this->statement."\r\n".
87 85
                     "\r\n",
88 86
                     FILE_APPEND
89 87
                 );
@@ -92,11 +90,11 @@  discard block
 block discarded – undo
92 90
         }
93 91
         if ($log) {
94 92
             $tm = microtime(true) - $tm;
95
-            if ($tm >= (float)$this->drv->option('log_slow', 0)) {
93
+            if ($tm >= (float) $this->drv->option('log_slow', 0)) {
96 94
                 @file_put_contents(
97 95
                     $log,
98
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
99
-                    $this->statement . "\r\n" .
96
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
97
+                    $this->statement."\r\n".
100 98
                     "\r\n",
101 99
                     FILE_APPEND
102 100
                 );
Please login to merge, or discard this patch.
src/driver/oracle/Statement.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         if (isset($this->map)) {
27 27
             $par = [];
28 28
             foreach ($this->map as $key) {
29
-                $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key);
29
+                $par[] = $data[$key] ?? throw new DBException('Missing param '.$key);
30 30
             }
31 31
             $data = $par;
32 32
         }
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
             if (!is_array($err)) {
74 74
                 $err = [];
75 75
             }
76
-            if ($log && (int)$this->driver->option('log_errors', 1)) {
76
+            if ($log && (int) $this->driver->option('log_errors', 1)) {
77 77
                 @file_put_contents(
78 78
                     $log,
79
-                    '--' . date('Y-m-d H:i:s') . ' ERROR: ' . implode(',', $err) . "\r\n" .
80
-                    $this->sql . "\r\n" .
79
+                    '--'.date('Y-m-d H:i:s').' ERROR: '.implode(',', $err)."\r\n".
80
+                    $this->sql."\r\n".
81 81
                     "\r\n",
82 82
                     FILE_APPEND
83 83
                 );
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
         }
87 87
         if ($log) {
88 88
             $tm = microtime(true) - $tm;
89
-            if ($tm >= (float)$this->driver->option('log_slow', 0)) {
89
+            if ($tm >= (float) $this->driver->option('log_slow', 0)) {
90 90
                 @file_put_contents(
91 91
                     $log,
92
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
93
-                    $this->sql . "\r\n" .
92
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
93
+                    $this->sql."\r\n".
94 94
                     "\r\n",
95 95
                     FILE_APPEND
96 96
                 );
Please login to merge, or discard this patch.
src/driver/sqlite/Statement.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
         if (isset($this->map)) {
37 37
             $par = [];
38 38
             foreach ($this->map as $key) {
39
-                $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key);
39
+                $par[] = $data[$key] ?? throw new DBException('Missing param '.$key);
40 40
             }
41 41
             $data = $par;
42 42
         }
Please login to merge, or discard this patch.
src/driver/ibase/Statement.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
         if (isset($this->map)) {
37 37
             $par = [];
38 38
             foreach ($this->map as $key) {
39
-                $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key);
39
+                $par[] = $data[$key] ?? throw new DBException('Missing param '.$key);
40 40
             }
41 41
             $data = $par;
42 42
         }
Please login to merge, or discard this patch.
src/DBInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param class-string<T>|Table|string $table
119 119
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
120 120
      */
121
-    public function getMapper(Table|string $table): MapperInterface;
121
+    public function getMapper(Table | string $table): MapperInterface;
122 122
     /*
123 123
      * @template T of Entity
124 124
      * @param Table|string $table
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @param null|class-string<T> $class
127 127
      * @return static
128 128
      */
129
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static;
129
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static;
130 130
     public function clearMappers(): static;
131 131
     public function tableMapped(
132 132
         string $table,
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +273 added lines, -276 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];
25
+    protected array $li_of = [0, 0];
26 26
     protected bool $li_mt = false;
27 27
     protected array $fields = [];
28 28
     protected array $withr = [];
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
      * @param  Table|string   $table           the name or definition of the main table in the query
40 40
      * @param  bool           $findRelations   should the query builder try to find missing joins
41 41
      */
42
-    public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false)
42
+    public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false)
43 43
     {
44 44
         $this->db = $db;
45 45
         $this->findRelations = $findRelations;
46
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
46
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
47 47
         $primary = $this->definition->getPrimaryKey();
48 48
         $columns = $this->definition->getColumns();
49 49
         $this->pkey = count($primary) ? $primary : $columns;
@@ -67,27 +67,27 @@  discard block
 block discarded – undo
67 67
     {
68 68
         $column = explode('.', $column);
69 69
         if (count($column) === 1) {
70
-            $column = [ $this->definition->getFullName(), $column[0] ];
70
+            $column = [$this->definition->getFullName(), $column[0]];
71 71
             $col = $this->definition->getColumn($column[1]);
72 72
             if (!$col) {
73
-                throw new DBException('Invalid column name in main table: ' . $column[1]);
73
+                throw new DBException('Invalid column name in main table: '.$column[1]);
74 74
             }
75 75
         } elseif (count($column) === 2) {
76 76
             if ($column[0] === $this->definition->getName()) {
77 77
                 $col = $this->definition->getColumn($column[1]);
78 78
                 if (!$col) {
79
-                    throw new DBException('Invalid column name in main table: ' . $column[1]);
79
+                    throw new DBException('Invalid column name in main table: '.$column[1]);
80 80
                 }
81 81
             } else {
82 82
                 if ($this->definition->hasRelation($column[0])) {
83 83
                     $col = $this->definition->getRelation($column[0])?->table?->getColumn($column[1]);
84 84
                     if (!$col) {
85
-                        throw new DBException('Invalid column name in related table: ' . $column[1]);
85
+                        throw new DBException('Invalid column name in related table: '.$column[1]);
86 86
                     }
87 87
                 } elseif (isset($this->joins[$column[0]])) {
88 88
                     $col = $this->joins[$column[0]]->table->getColumn($column[1]);
89 89
                     if (!$col) {
90
-                        throw new DBException('Invalid column name in related table: ' . $column[1]);
90
+                        throw new DBException('Invalid column name in related table: '.$column[1]);
91 91
                     }
92 92
                 } else {
93 93
                     $col = null;
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                             $path = $this->db->findRelation($this->definition->getName(), $column[0]);
107 107
                         }
108 108
                         if (!count($path)) {
109
-                            throw new DBException('Invalid foreign table / column name: ' . implode(',', $column));
109
+                            throw new DBException('Invalid foreign table / column name: '.implode(',', $column));
110 110
                         }
111 111
                         unset($path[0]);
112 112
                         $this->with(implode('.', $path), false);
@@ -119,26 +119,26 @@  discard block
 block discarded – undo
119 119
             if ($this->definition->hasRelation(implode('.', $column))) {
120 120
                 $this->with(implode('.', $column), false);
121 121
                 $col = $this->definition->getRelation(implode('.', $column))?->table?->getColumn($name);
122
-                $column = [ implode('.', $column), $name ];
122
+                $column = [implode('.', $column), $name];
123 123
             } else {
124 124
                 $this->with(implode('.', $column), false);
125 125
                 $table = $this->definition;
126 126
                 $table = array_reduce(
127 127
                     $column,
128
-                    function ($carry, $item) use (&$table) {
128
+                    function($carry, $item) use (&$table) {
129 129
                         $table = $table->getRelation($item)->table;
130 130
                         return $table;
131 131
                     }
132 132
                 );
133 133
                 $col = $table->getColumn($name);
134
-                $column = [ implode(static::SEP, $column), $name ];
134
+                $column = [implode(static::SEP, $column), $name];
135 135
             }
136 136
         }
137
-        return [ 'name' => implode('.', $column), 'data' => $col ];
137
+        return ['name' => implode('.', $column), 'data' => $col];
138 138
     }
139 139
     protected function normalizeValue(TableColumn $col, mixed $value): mixed
140 140
     {
141
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
141
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
142 142
         if ($value === null && $col->isNullable()) {
143 143
             return null;
144 144
         }
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
                     $temp = strtotime($value);
149 149
                     if (!$temp) {
150 150
                         if ($strict) {
151
-                            throw new DBException('Invalid value for date column: ' . $col->getName());
151
+                            throw new DBException('Invalid value for date column: '.$col->getName());
152 152
                         }
153 153
                         return null;
154 154
                     }
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
                     return $value->format('Y-m-d');
162 162
                 }
163 163
                 if ($strict) {
164
-                    throw new DBException('Invalid value (unknown data type) for date column: ' . $col->getName());
164
+                    throw new DBException('Invalid value (unknown data type) for date column: '.$col->getName());
165 165
                 }
166 166
                 return $value;
167 167
             case 'datetime':
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                     $temp = strtotime($value);
170 170
                     if (!$temp) {
171 171
                         if ($strict) {
172
-                            throw new DBException('Invalid value for datetime column: ' . $col->getName());
172
+                            throw new DBException('Invalid value for datetime column: '.$col->getName());
173 173
                         }
174 174
                         return null;
175 175
                     }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
                     return $value->format('Y-m-d H:i:s');
183 183
                 }
184 184
                 if ($strict) {
185
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
185
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
186 186
                 }
187 187
                 return $value;
188 188
             case 'enum':
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
                 if (is_int($value)) {
191 191
                     if (!isset($values[$value])) {
192 192
                         if ($strict) {
193
-                            throw new DBException('Invalid value (using integer) for enum: ' . $col->getName());
193
+                            throw new DBException('Invalid value (using integer) for enum: '.$col->getName());
194 194
                         }
195 195
                         return $value;
196 196
                     }
@@ -198,23 +198,23 @@  discard block
 block discarded – undo
198 198
                 }
199 199
                 if (!in_array($value, $col->getValues())) {
200 200
                     if ($strict) {
201
-                        throw new DBException('Invalid value for enum: ' . $col->getName());
201
+                        throw new DBException('Invalid value for enum: '.$col->getName());
202 202
                     }
203 203
                     return 0;
204 204
                 }
205 205
                 return $value;
206 206
             case 'int':
207
-                $temp = preg_replace('([^+\-0-9]+)', '', (string)$value);
208
-                return is_string($temp) ? (int)$temp : 0;
207
+                $temp = preg_replace('([^+\-0-9]+)', '', (string) $value);
208
+                return is_string($temp) ? (int) $temp : 0;
209 209
             case 'float':
210
-                $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', (string)$value));
211
-                return is_string($temp) ? (float)$temp : 0;
210
+                $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', (string) $value));
211
+                return is_string($temp) ? (float) $temp : 0;
212 212
             case 'text':
213 213
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
214 214
                 // because the polyfill is quite slow
215 215
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
216 216
                     if ($strict) {
217
-                        throw new DBException('Invalid value for text column: ' . $col->getName());
217
+                        throw new DBException('Invalid value for text column: '.$col->getName());
218 218
                     }
219 219
                     return mb_substr($value, 0, $col->getLength());
220 220
                 }
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
                     $sqls[] = $temp[0];
248 248
                     $pars = array_merge($pars, $temp[1]);
249 249
                     unset($value[$k]);
250
-                } elseif (in_array($k, ['like','ilike','contains','icontains','ends','iends'])) {
250
+                } elseif (in_array($k, ['like', 'ilike', 'contains', 'icontains', 'ends', 'iends'])) {
251 251
                     if ($column->getBasicType() !== 'text') {
252 252
                         switch ($this->db->driverName()) {
253 253
                             case 'oracle':
254
-                                $name = 'CAST(' . $name . ' AS NVARCHAR(500))';
254
+                                $name = 'CAST('.$name.' AS NVARCHAR(500))';
255 255
                                 break;
256 256
                             case 'postgre':
257 257
                                 $name = $name.'::text';
@@ -266,25 +266,25 @@  discard block
 block discarded – undo
266 266
                     $sql = [];
267 267
                     $par = [];
268 268
                     foreach ($values as $v) {
269
-                        $v = str_replace(['%', '_'], ['\\%','\\_'], $v) . '%';
269
+                        $v = str_replace(['%', '_'], ['\\%', '\\_'], $v).'%';
270 270
                         if ($mode === 'contains' || $mode === 'icontains') {
271
-                            $v = '%' . $v;
271
+                            $v = '%'.$v;
272 272
                         }
273 273
                         if ($mode === 'ends' || $mode === 'iends') {
274
-                            $v = '%' . rtrim($v, '%');
274
+                            $v = '%'.rtrim($v, '%');
275 275
                         }
276 276
                         if ($mode === 'icontains' || $mode === 'ilike' || $mode === 'iends') {
277 277
                             $v = mb_strtoupper($v);
278
-                            $name = 'UPPER(' . $name . ')';
278
+                            $name = 'UPPER('.$name.')';
279 279
                         }
280
-                        $sql[] = $negate ? $name . ' NOT LIKE ?' : $name . ' LIKE ?';
280
+                        $sql[] = $negate ? $name.' NOT LIKE ?' : $name.' LIKE ?';
281 281
                         $par[] = $v;
282 282
                     }
283 283
                     if ($negate) {
284
-                        $sqls[] = '(' . implode(' AND ', $sql) . ')';
284
+                        $sqls[] = '('.implode(' AND ', $sql).')';
285 285
                         $pars = array_merge($pars, $par);
286 286
                     } else {
287
-                        $sqls[] = '(' . implode(' OR ', $sql) . ')';
287
+                        $sqls[] = '('.implode(' OR ', $sql).')';
288 288
                         $pars = array_merge($pars, $par);
289 289
                     }
290 290
                     unset($value[$k]);
@@ -292,38 +292,38 @@  discard block
 block discarded – undo
292 292
             }
293 293
             if (!count($value)) {
294 294
                 return [
295
-                    '(' . implode(' AND ', $sqls) . ')',
295
+                    '('.implode(' AND ', $sqls).')',
296 296
                     $pars
297 297
                 ];
298 298
             }
299 299
         }
300 300
         if (is_null($value)) {
301
-            $sqls[] = $negate ? $name . ' IS NOT NULL' : $name . ' IS NULL';
301
+            $sqls[] = $negate ? $name.' IS NOT NULL' : $name.' IS NULL';
302 302
             return [
303
-                '(' . implode(' AND ', $sqls) . ')',
303
+                '('.implode(' AND ', $sqls).')',
304 304
                 $pars
305 305
             ];
306 306
         }
307 307
         if (!is_array($value)) {
308
-            $sqls[] = $negate ? $name . ' <> ?' : $name . ' = ?';
308
+            $sqls[] = $negate ? $name.' <> ?' : $name.' = ?';
309 309
             $pars[] = $this->normalizeValue($column, $value);
310 310
             return [
311
-                '(' . implode(' AND ', $sqls) . ')',
311
+                '('.implode(' AND ', $sqls).')',
312 312
                 $pars
313 313
             ];
314 314
         }
315 315
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
316
-            $value = [ 'gte' => $value['beg'] ];
316
+            $value = ['gte' => $value['beg']];
317 317
         }
318 318
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
319
-            $value = [ 'lte' => $value['end'] ];
319
+            $value = ['lte' => $value['end']];
320 320
         }
321 321
         if (isset($value['beg']) && isset($value['end'])) {
322 322
             $sqls[] = $negate ? $name.' NOT BETWEEN ? AND ?' : $name.' BETWEEN ? AND ?';
323 323
             $pars[] = $this->normalizeValue($column, $value['beg']);
324 324
             $pars[] = $this->normalizeValue($column, $value['end']);
325 325
             return [
326
-                '(' . implode(' AND ', $sqls) . ')',
326
+                '('.implode(' AND ', $sqls).')',
327 327
                 $pars
328 328
             ];
329 329
         }
@@ -331,51 +331,51 @@  discard block
 block discarded – undo
331 331
             $sql = [];
332 332
             $par = [];
333 333
             if (isset($value['gt'])) {
334
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
334
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
335 335
                 $par[] = $this->normalizeValue($column, $value['gt']);
336 336
             }
337 337
             if (isset($value['gte'])) {
338
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
338
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
339 339
                 $par[] = $this->normalizeValue($column, $value['gte']);
340 340
             }
341 341
             if (isset($value['lt'])) {
342
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
342
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
343 343
                 $par[] = $this->normalizeValue($column, $value['lt']);
344 344
             }
345 345
             if (isset($value['lte'])) {
346
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
346
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
347 347
                 $par[] = $this->normalizeValue($column, $value['lte']);
348 348
             }
349
-            $sqls[] = '(' . implode(' AND ', $sql) . ')';
349
+            $sqls[] = '('.implode(' AND ', $sql).')';
350 350
             $pars = array_merge($pars, $par);
351 351
             return [
352
-                '(' . implode(' AND ', $sqls) . ')',
352
+                '('.implode(' AND ', $sqls).')',
353 353
                 $pars
354 354
             ];
355 355
         }
356 356
 
357
-        $value = array_values(array_map(function ($v) use ($column) {
357
+        $value = array_values(array_map(function($v) use ($column) {
358 358
             return $this->normalizeValue($column, $v);
359 359
         }, $value));
360 360
         if ($this->db->driverName() === 'oracle') {
361 361
             $sql = [];
362 362
             $par = [];
363 363
             for ($i = 0; $i < count($value); $i += 500) {
364
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
364
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
365 365
                 $par[] = array_slice($value, $i, 500);
366 366
             }
367
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
367
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
368 368
             $sqls[] = $sql;
369 369
             $pars = array_merge($pars, $par);
370 370
             return [
371
-                '(' . implode(' AND ', $sqls) . ')',
371
+                '('.implode(' AND ', $sqls).')',
372 372
                 $pars
373 373
             ];
374 374
         }
375
-        $sqls[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
375
+        $sqls[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
376 376
         $pars[] = $value;
377 377
         return [
378
-            '(' . implode(' AND ', $sqls) . ')',
378
+            '('.implode(' AND ', $sqls).')',
379 379
             $pars
380 380
         ];
381 381
     }
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
                 $par = array_merge($par, $temp[1]);
408 408
             }
409 409
         }
410
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
410
+        return $this->where('('.implode(' OR ', $sql).')', $par);
411 411
     }
412 412
     /**
413 413
      * Filter the results matching all of the criteria
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
                 $par = array_merge($par, $temp[1]);
426 426
             }
427 427
         }
428
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
428
+        return $this->where('('.implode(' AND ', $sql).')', $par);
429 429
     }
430 430
     /**
431 431
      * Sort by a column
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
         try {
439 439
             $this->getColumn($column);
440 440
         } catch (DBException $e) {
441
-            throw new DBException('Invalid sort column: ' . $column);
441
+            throw new DBException('Invalid sort column: '.$column);
442 442
         }
443
-        return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC'));
443
+        return $this->order($column.' '.($desc ? 'DESC' : 'ASC'));
444 444
     }
445 445
     /**
446 446
      * Group by a column (or columns)
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
     public function group($column) : static
451 451
     {
452 452
         if (!is_array($column)) {
453
-            $column = [ $column ];
453
+            $column = [$column];
454 454
         }
455 455
         foreach ($column as $k => $v) {
456 456
             $column[$k] = $this->getColumn($v)['name'];
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
         $this->order = [];
494 494
         $this->having = [];
495 495
         $this->aliases = [];
496
-        $this->li_of = [0,0];
496
+        $this->li_of = [0, 0];
497 497
         $this->li_mt = false;
498 498
         $this->qiterator = null;
499 499
         return $this;
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
     public function groupBy(string $sql, array $params = []) : static
508 508
     {
509 509
         $this->qiterator = null;
510
-        $this->group = [ $sql, $params ];
510
+        $this->group = [$sql, $params];
511 511
         return $this;
512 512
     }
513 513
     /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     public function join($table, array $fields, ?string $name = null, bool $multiple = true)
522 522
     {
523 523
         $this->qiterator = null;
524
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
524
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
525 525
         $name = $name ?? $table->getName();
526 526
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
527 527
             throw new DBException('Alias / table name already in use');
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
         foreach ($fields as $k => $v) {
531 531
             $k = explode('.', $k, 2);
532 532
             $k = count($k) == 2 ? $k[1] : $k[0];
533
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
533
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
534 534
         }
535 535
         return $this;
536 536
     }
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
     public function where(string $sql, array $params = []) : static
544 544
     {
545 545
         $this->qiterator = null;
546
-        $this->where[] = [ $sql, $params ];
546
+        $this->where[] = [$sql, $params];
547 547
         return $this;
548 548
     }
549 549
     /**
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
     public function having(string $sql, array $params = []) : static
556 556
     {
557 557
         $this->qiterator = null;
558
-        $this->having[] = [ $sql, $params ];
558
+        $this->having[] = [$sql, $params];
559 559
         return $this;
560 560
     }
561 561
     /**
@@ -575,12 +575,12 @@  discard block
 block discarded – undo
575 575
                     throw new \Exception();
576 576
                 }
577 577
                 $name = $this->getColumn(trim($name))['name'];
578
-                $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
578
+                $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
579 579
             } catch (\Exception $e) {
580 580
                 $name = null;
581 581
             }
582 582
         }
583
-        $this->order = [ $sql, $params, $name ];
583
+        $this->order = [$sql, $params, $name];
584 584
         return $this;
585 585
     }
586 586
     /**
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
     public function limit(int $limit, int $offset = 0, ?bool $limitOnMainTable = null) : static
593 593
     {
594 594
         $this->qiterator = null;
595
-        $this->li_of = [ $limit, $offset ];
595
+        $this->li_of = [$limit, $offset];
596 596
         if (isset($limitOnMainTable)) {
597 597
             $this->li_mt = $limitOnMainTable;
598 598
         }
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
     {
612 612
         $aliases = [];
613 613
         $aliases_ext = [];
614
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
614
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
615 615
             // to bypass use: return $name;
616
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
616
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
617 617
             if (isset($aliases_ext[$name])) {
618 618
                 unset($aliases_ext[$name]);
619 619
             }
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
         $h = $this->having;
637 637
         $o = $this->order;
638 638
         $g = $this->group;
639
-        $j = array_map(function ($v) {
639
+        $j = array_map(function($v) {
640 640
             return clone $v;
641 641
         }, $this->joins);
642 642
 
@@ -646,28 +646,28 @@  discard block
 block discarded – undo
646 646
                 continue;
647 647
             }
648 648
             foreach ($w as $kk => $v) {
649
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
649
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
650 650
                     $used_relations[] = $k;
651
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
651
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
652 652
                 }
653 653
             }
654 654
             foreach ($h as $kk => $v) {
655
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
655
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
656 656
                     $used_relations[] = $k;
657
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
657
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
658 658
                 }
659 659
             }
660
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
660
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
661 661
                 $used_relations[] = $k;
662
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
662
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
663 663
             }
664 664
             foreach ($j as $kk => $v) {
665 665
                 foreach ($v->keymap as $kkk => $vv) {
666
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
666
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
667 667
                         $used_relations[] = $k;
668 668
                         $j[$kk]->keymap[$kkk] = preg_replace(
669
-                            '(\b'.preg_quote($k . '.'). ')i',
670
-                            $getAlias($k) . '.',
669
+                            '(\b'.preg_quote($k.'.').')i',
670
+                            $getAlias($k).'.',
671 671
                             $vv
672 672
                         );
673 673
                     }
@@ -676,65 +676,65 @@  discard block
 block discarded – undo
676 676
         }
677 677
         foreach ($this->definition->getRelations() as $k => $v) {
678 678
             foreach ($w as $kk => $vv) {
679
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
680
-                    $relations[$k] = [ $v, $table ];
679
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
680
+                    $relations[$k] = [$v, $table];
681 681
                     $used_relations[] = $k;
682
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
682
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
683 683
                 }
684 684
             }
685
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
686
-                $relations[$k] = [ $v, $table ];
685
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
686
+                $relations[$k] = [$v, $table];
687 687
             }
688 688
             foreach ($h as $kk => $vv) {
689
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
690
-                    $relations[$k] = [ $v, $table ];
689
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
690
+                    $relations[$k] = [$v, $table];
691 691
                     $used_relations[] = $k;
692
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
692
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
693 693
                 }
694 694
             }
695
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
696
-                $relations[$k] = [ $v, $table ];
695
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
696
+                $relations[$k] = [$v, $table];
697 697
                 $used_relations[] = $k;
698
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
698
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
699 699
             }
700 700
             foreach ($j as $kk => $vv) {
701 701
                 foreach ($vv->keymap as $kkk => $vvv) {
702
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
703
-                        $relations[$k] = [ $v, $table ];
702
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
703
+                        $relations[$k] = [$v, $table];
704 704
                         $used_relations[] = $k;
705 705
                         $j[$kk]->keymap[$kkk] =
706
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
706
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
707 707
                     }
708 708
                 }
709 709
             }
710 710
         }
711 711
         foreach ($aliases_ext as $k => $alias) {
712 712
             foreach ($w as $kk => $v) {
713
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
714
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
713
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
714
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
715 715
                     $used_relations[] = $k;
716 716
                 }
717 717
             }
718 718
             foreach ($h as $kk => $v) {
719
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
720
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
719
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
720
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
721 721
                     $used_relations[] = $k;
722 722
                 }
723 723
             }
724
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
724
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
725 725
                 $used_relations[] = $k;
726 726
             }
727
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
728
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
727
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
728
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
729 729
                 $used_relations[] = $k;
730 730
             }
731 731
             foreach ($j as $kk => $v) {
732 732
                 foreach ($v->keymap as $kkk => $vv) {
733
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
733
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
734 734
                         $used_relations[] = $k;
735 735
                         $j[$kk]->keymap[$kkk] = preg_replace(
736
-                            '(\b'.preg_quote($k . '.'). ')i',
737
-                            $alias . '.',
736
+                            '(\b'.preg_quote($k.'.').')i',
737
+                            $alias.'.',
738 738
                             $vv
739 739
                         );
740 740
                     }
@@ -753,13 +753,13 @@  discard block
 block discarded – undo
753 753
                     foreach ($v->keymap as $kk => $vv) {
754 754
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
755 755
                     }
756
-                    $sql .= implode(' AND ', $tmp) . ' ';
756
+                    $sql .= implode(' AND ', $tmp).' ';
757 757
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
758 758
                     $tmp = [];
759 759
                     foreach ($v->pivot_keymap as $kk => $vv) {
760 760
                         $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
761 761
                     }
762
-                    $sql .= implode(' AND ', $tmp) . ' ';
762
+                    $sql .= implode(' AND ', $tmp).' ';
763 763
                 } else {
764 764
                     $alias = $getAlias($k);
765 765
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -768,10 +768,10 @@  discard block
 block discarded – undo
768 768
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
769 769
                     }
770 770
                     if ($v->sql) {
771
-                        $tmp[] = $v->sql . ' ';
771
+                        $tmp[] = $v->sql.' ';
772 772
                         $par = array_merge($par, $v->par ?? []);
773 773
                     }
774
-                    $sql .= implode(' AND ', $tmp) . ' ';
774
+                    $sql .= implode(' AND ', $tmp).' ';
775 775
                 }
776 776
             }
777 777
         }
@@ -780,12 +780,12 @@  discard block
 block discarded – undo
780 780
             if ($v->many) {
781 781
                 $jMany = true;
782 782
             }
783
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
783
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
784 784
             $tmp = [];
785 785
             foreach ($v->keymap as $kk => $vv) {
786 786
                 $tmp[] = $kk.' = '.$vv;
787 787
             }
788
-            $sql .= implode(' AND ', $tmp) . ' ';
788
+            $sql .= implode(' AND ', $tmp).' ';
789 789
         }
790 790
         if (!$jMany && !count($used_relations)) {
791 791
             $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql);
@@ -794,20 +794,20 @@  discard block
 block discarded – undo
794 794
             $sql .= 'WHERE ';
795 795
             $tmp = [];
796 796
             foreach ($w as $v) {
797
-                $tmp[] = '(' . $v[0] . ')';
797
+                $tmp[] = '('.$v[0].')';
798 798
                 $par = array_merge($par, $v[1]);
799 799
             }
800 800
             $sql .= implode(' AND ', $tmp).' ';
801 801
         }
802 802
         if (count($g)) {
803
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
803
+            $sql .= 'GROUP BY '.$g[0].' ';
804 804
             $par = array_merge($par, $g[1]);
805 805
         }
806 806
         if (count($h)) {
807 807
             $sql .= 'HAVING ';
808 808
             $tmp = [];
809 809
             foreach ($h as $v) {
810
-                $tmp[] = '(' . $v[0] . ')';
810
+                $tmp[] = '('.$v[0].')';
811 811
                 $par = array_merge($par, $v[1]);
812 812
             }
813 813
             $sql .= implode(' AND ', $tmp).' ';
@@ -837,14 +837,14 @@  discard block
 block discarded – undo
837 837
                     } elseif (isset($this->joins[$table])) {
838 838
                         $cols = $this->joins[$table]->table->getColumns();
839 839
                     } else {
840
-                        throw new DBException('Invalid foreign table name: ' . $table);
840
+                        throw new DBException('Invalid foreign table name: '.$table);
841 841
                     }
842 842
                 } else {
843 843
                     array_pop($temp);
844 844
                     $this->with(implode('.', $temp));
845 845
                     $table = array_reduce(
846 846
                         $temp,
847
-                        function ($carry, $item) use (&$table) {
847
+                        function($carry, $item) use (&$table) {
848 848
                             return $table->getRelation($item)->table;
849 849
                         }
850 850
                     );
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
                 }
854 854
                 unset($fields[$k]);
855 855
                 foreach ($cols as $col) {
856
-                    $fields[] = $table . '.' . $col;
856
+                    $fields[] = $table.'.'.$col;
857 857
                 }
858 858
             }
859 859
         }
@@ -887,11 +887,11 @@  discard block
 block discarded – undo
887 887
             if ($relation[2]) {
888 888
                 if (!$this->manualColumns) {
889 889
                     foreach ($relation[0]->table->getColumns() as $column) {
890
-                        $f[] = $name . '.' . $column;
890
+                        $f[] = $name.'.'.$column;
891 891
                     }
892 892
                 } else {
893 893
                     foreach ($relation[0]->table->getPrimaryKey() as $column) {
894
-                        $f[] = $name . '.' . $column;
894
+                        $f[] = $name.'.'.$column;
895 895
                     }
896 896
                 }
897 897
             }
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
                 continue;
912 912
             }
913 913
             if (count($temp) === 2 && $this->definition->hasRelation($temp[0]) && $this->definition->getRelation($temp[0])?->table->getColumn($temp[1])) {
914
-                $r[] = $temp[0] . '.' . $temp[1];
914
+                $r[] = $temp[0].'.'.$temp[1];
915 915
                 continue;
916 916
             }
917 917
             if (count($temp) === 3 && $temp[0] === $this->definition->getSchema() && $this->definition->hasRelation($temp[1])) {
918
-                $r[] = $temp[1] . '.' . $temp[2];
918
+                $r[] = $temp[1].'.'.$temp[2];
919 919
                 continue;
920 920
             }
921 921
         }
@@ -934,9 +934,9 @@  discard block
 block discarded – undo
934 934
         }
935 935
         $aliases = [];
936 936
         $aliases_ext = [];
937
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
937
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
938 938
             // to bypass use: return $name;
939
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
939
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
940 940
             if (isset($aliases_ext[$name])) {
941 941
                 unset($aliases_ext[$name]);
942 942
             }
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
         $h = $this->having;
962 962
         $o = $this->order;
963 963
         $g = $this->group;
964
-        $j = array_map(function ($v) {
964
+        $j = array_map(function($v) {
965 965
             return clone $v;
966 966
         }, $this->joins);
967 967
 
@@ -976,11 +976,10 @@  discard block
 block discarded – undo
976 976
             }
977 977
             $temp = [];
978 978
             foreach ($f as $kk => $field) {
979
-                if (strpos($field, $k . '.') === 0) {
980
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
979
+                if (strpos($field, $k.'.') === 0) {
980
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
981 981
                     $nk = $this->aliasColumns && is_numeric($kk) ?
982
-                        $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) :
983
-                        $kk;
982
+                        $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk;
984 983
                     $temp[$nk] = $f[$kk];
985 984
                 } else {
986 985
                     $temp[$kk] = $field;
@@ -988,27 +987,27 @@  discard block
 block discarded – undo
988 987
             }
989 988
             $f = $temp;
990 989
             foreach ($w as $kk => $v) {
991
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
992
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
990
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
991
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
993 992
                 }
994 993
             }
995 994
             foreach ($h as $kk => $v) {
996
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
997
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
995
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
996
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
998 997
                 }
999 998
             }
1000
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1001
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
999
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1000
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1002 1001
             }
1003
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1004
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1002
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1003
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1005 1004
             }
1006 1005
             foreach ($j as $kk => $v) {
1007 1006
                 foreach ($v->keymap as $kkk => $vv) {
1008
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1007
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1009 1008
                         $j[$kk]->keymap[$kkk] = preg_replace(
1010
-                            '(\b'.preg_quote($k . '.'). ')i',
1011
-                            $getAlias($k) . '.',
1009
+                            '(\b'.preg_quote($k.'.').')i',
1010
+                            $getAlias($k).'.',
1012 1011
                             $vv
1013 1012
                         );
1014 1013
                     }
@@ -1018,12 +1017,11 @@  discard block
 block discarded – undo
1018 1017
         foreach ($this->definition->getRelations() as $k => $relation) {
1019 1018
             $temp = [];
1020 1019
             foreach ($f as $kk => $field) {
1021
-                if (strpos($field, $k . '.') === 0) {
1022
-                    $relations[$k] = [ $relation, $table ];
1023
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
1020
+                if (strpos($field, $k.'.') === 0) {
1021
+                    $relations[$k] = [$relation, $table];
1022
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
1024 1023
                     $nk = $this->aliasColumns && is_numeric($kk) ?
1025
-                        $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) :
1026
-                        $kk;
1024
+                        $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk;
1027 1025
                     $temp[$nk] = $f[$kk];
1028 1026
                 } else {
1029 1027
                     $temp[$kk] = $field;
@@ -1031,32 +1029,32 @@  discard block
 block discarded – undo
1031 1029
             }
1032 1030
             $f = $temp;
1033 1031
             foreach ($w as $kk => $v) {
1034
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1035
-                    $relations[$k] = [ $relation, $table ];
1036
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1032
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1033
+                    $relations[$k] = [$relation, $table];
1034
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1037 1035
                 }
1038 1036
             }
1039 1037
             foreach ($h as $kk => $v) {
1040
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1041
-                    $relations[$k] = [ $relation, $table ];
1042
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1038
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1039
+                    $relations[$k] = [$relation, $table];
1040
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1043 1041
                 }
1044 1042
             }
1045
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1046
-                $relations[$k] = [ $relation, $table ];
1047
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1043
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1044
+                $relations[$k] = [$relation, $table];
1045
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1048 1046
             }
1049
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1050
-                $relations[$k] = [ $relation, $table ];
1051
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1047
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1048
+                $relations[$k] = [$relation, $table];
1049
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1052 1050
             }
1053 1051
             foreach ($j as $kk => $v) {
1054 1052
                 foreach ($v->keymap as $kkk => $vv) {
1055
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1056
-                        $relations[$k] = [ $relation, $table ];
1053
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1054
+                        $relations[$k] = [$relation, $table];
1057 1055
                         $j[$kk]->keymap[$kkk] = preg_replace(
1058
-                            '(\b'.preg_quote($k . '.'). ')i',
1059
-                            $getAlias($k) . '.',
1056
+                            '(\b'.preg_quote($k.'.').')i',
1057
+                            $getAlias($k).'.',
1060 1058
                             $vv
1061 1059
                         );
1062 1060
                     }
@@ -1066,11 +1064,10 @@  discard block
 block discarded – undo
1066 1064
         foreach ($aliases_ext as $k => $alias) {
1067 1065
             $temp = [];
1068 1066
             foreach ($f as $kk => $field) {
1069
-                if (strpos($field, $k . '.') === 0) {
1070
-                    $f[$kk] = str_replace($k . '.', $alias . '.', $field);
1067
+                if (strpos($field, $k.'.') === 0) {
1068
+                    $f[$kk] = str_replace($k.'.', $alias.'.', $field);
1071 1069
                     $nk = $this->aliasColumns && is_numeric($kk) ?
1072
-                        $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) :
1073
-                        $kk;
1070
+                        $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk;
1074 1071
                     $temp[$nk] = $f[$kk];
1075 1072
                 } else {
1076 1073
                     $temp[$kk] = $field;
@@ -1078,27 +1075,27 @@  discard block
 block discarded – undo
1078 1075
             }
1079 1076
             $f = $temp;
1080 1077
             foreach ($w as $kk => $v) {
1081
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1082
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1078
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1079
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1083 1080
                 }
1084 1081
             }
1085 1082
             foreach ($h as $kk => $v) {
1086
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1087
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1083
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1084
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1088 1085
                 }
1089 1086
             }
1090
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1091
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
1087
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1088
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
1092 1089
             }
1093
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1094
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
1090
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1091
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
1095 1092
             }
1096 1093
             foreach ($j as $kk => $v) {
1097 1094
                 foreach ($v->keymap as $kkk => $vv) {
1098
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1095
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1099 1096
                         $j[$kk]->keymap[$kkk] = preg_replace(
1100
-                            '(\b'.preg_quote($k . '.'). ')i',
1101
-                            $alias . '.',
1097
+                            '(\b'.preg_quote($k.'.').')i',
1098
+                            $alias.'.',
1102 1099
                             $vv
1103 1100
                         );
1104 1101
                     }
@@ -1109,14 +1106,14 @@  discard block
 block discarded – undo
1109 1106
             if ($relation[2]) {
1110 1107
                 if (!$this->manualColumns) {
1111 1108
                     foreach ($relation[0]->table->getColumns() as $column) {
1112
-                        if (!in_array($getAlias($name) . '.' . $column, $f)) {
1113
-                            $f[$getAlias($name . static::SEP . $column)] = $getAlias($name) . '.' . $column;
1109
+                        if (!in_array($getAlias($name).'.'.$column, $f)) {
1110
+                            $f[$getAlias($name.static::SEP.$column)] = $getAlias($name).'.'.$column;
1114 1111
                         }
1115 1112
                     }
1116 1113
                 } else {
1117 1114
                     foreach ($relation[0]->table->getPrimaryKey() as $column) {
1118
-                        if (!in_array($getAlias($name) . '.' . $column, $f)) {
1119
-                            $f[$getAlias($name . static::SEP . $column)] = $getAlias($name) . '.' . $column;
1115
+                        if (!in_array($getAlias($name).'.'.$column, $f)) {
1116
+                            $f[$getAlias($name.static::SEP.$column)] = $getAlias($name).'.'.$column;
1120 1117
                         }
1121 1118
                     }
1122 1119
                 }
@@ -1124,7 +1121,7 @@  discard block
 block discarded – undo
1124 1121
         }
1125 1122
         $select = [];
1126 1123
         foreach ($f as $k => $field) {
1127
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
1124
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
1128 1125
         }
1129 1126
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$this->definition->getFullName().' ';
1130 1127
         $par = [];
@@ -1143,13 +1140,13 @@  discard block
 block discarded – undo
1143 1140
                 foreach ($v->keymap as $kk => $vv) {
1144 1141
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1145 1142
                 }
1146
-                $sql .= implode(' AND ', $tmp) . ' ';
1143
+                $sql .= implode(' AND ', $tmp).' ';
1147 1144
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
1148 1145
                 $tmp = [];
1149 1146
                 foreach ($v->pivot_keymap as $kk => $vv) {
1150 1147
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1151 1148
                 }
1152
-                $sql .= implode(' AND ', $tmp) . ' ';
1149
+                $sql .= implode(' AND ', $tmp).' ';
1153 1150
             } else {
1154 1151
                 $alias = $getAlias($relation);
1155 1152
 
@@ -1159,22 +1156,22 @@  discard block
 block discarded – undo
1159 1156
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1160 1157
                 }
1161 1158
                 if ($v->sql) {
1162
-                    $tmp[] = $v->sql . ' ';
1159
+                    $tmp[] = $v->sql.' ';
1163 1160
                     $par = array_merge($par, $v->par ?? []);
1164 1161
                 }
1165
-                $sql .= implode(' AND ', $tmp) . ' ';
1162
+                $sql .= implode(' AND ', $tmp).' ';
1166 1163
             }
1167 1164
         }
1168 1165
         foreach ($j as $k => $v) {
1169 1166
             if ($v->many) {
1170 1167
                 $many = true;
1171 1168
             }
1172
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1169
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1173 1170
             $tmp = [];
1174 1171
             foreach ($v->keymap as $kk => $vv) {
1175 1172
                 $tmp[] = $kk.' = '.$vv;
1176 1173
             }
1177
-            $sql .= implode(' AND ', $tmp) . ' ';
1174
+            $sql .= implode(' AND ', $tmp).' ';
1178 1175
         }
1179 1176
         if ($many && count($porder) && $this->li_mt) {
1180 1177
             $ids = $this->ids();
@@ -1182,9 +1179,9 @@  discard block
 block discarded – undo
1182 1179
                 if (count($porder) > 1) {
1183 1180
                     $pkw = [];
1184 1181
                     foreach ($porder as $name) {
1185
-                        $pkw[] = $name . ' = ?';
1182
+                        $pkw[] = $name.' = ?';
1186 1183
                     }
1187
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
1184
+                    $pkw = '('.implode(' AND ', $pkw).')';
1188 1185
                     $pkp = [];
1189 1186
                     foreach ($ids as $id) {
1190 1187
                         foreach ($id as $p) {
@@ -1196,60 +1193,60 @@  discard block
 block discarded – undo
1196 1193
                         $pkp
1197 1194
                     ];
1198 1195
                 } else {
1199
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
1196
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
1200 1197
                 }
1201 1198
             } else {
1202
-                $w[] = [ '1=0', [] ];
1199
+                $w[] = ['1=0', []];
1203 1200
             }
1204 1201
         }
1205 1202
         if (count($w)) {
1206 1203
             $sql .= 'WHERE ';
1207 1204
             $tmp = [];
1208 1205
             foreach ($w as $v) {
1209
-                $tmp[] = '(' . $v[0] . ')';
1206
+                $tmp[] = '('.$v[0].')';
1210 1207
                 $par = array_merge($par, $v[1]);
1211 1208
             }
1212 1209
             $sql .= implode(' AND ', $tmp).' ';
1213 1210
         }
1214 1211
         if (count($g)) {
1215
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1212
+            $sql .= 'GROUP BY '.$g[0].' ';
1216 1213
             $par = array_merge($par, $g[1]);
1217 1214
         }
1218 1215
         if (count($h)) {
1219 1216
             $sql .= 'HAVING ';
1220 1217
             $tmp = [];
1221 1218
             foreach ($h as $v) {
1222
-                $tmp[] = '(' . $v[0] . ')';
1219
+                $tmp[] = '('.$v[0].')';
1223 1220
                 $par = array_merge($par, $v[1]);
1224 1221
             }
1225 1222
             $sql .= implode(' AND ', $tmp).' ';
1226 1223
         }
1227 1224
         $ordered = false;
1228 1225
         if (count($o)) {
1229
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1226
+            $sql .= 'ORDER BY '.$o[0].' ';
1230 1227
             $par = array_merge($par, $o[1]);
1231 1228
             $ordered = true;
1232 1229
         }
1233 1230
         if (!count($g) && count($porder)) {
1234 1231
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1235
-            $porder = array_map(function ($v) use ($pdir) {
1236
-                return $v . ' ' . $pdir;
1232
+            $porder = array_map(function($v) use ($pdir) {
1233
+                return $v.' '.$pdir;
1237 1234
             }, $porder);
1238
-            $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1235
+            $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1239 1236
             $ordered = true;
1240 1237
         }
1241 1238
         foreach ($this->withr as $k => $v) {
1242 1239
             if (isset($v[3])) {
1243
-                $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC');
1240
+                $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC');
1244 1241
                 $ordered = true;
1245 1242
             }
1246 1243
         }
1247 1244
         if ((!$many || !$this->li_mt || !count($porder)) && $this->li_of[0]) {
1248 1245
             if ($this->db->driverName() === 'oracle') {
1249
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1250
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1246
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1247
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1251 1248
                 } else {
1252
-                    $f = array_map(function ($v) {
1249
+                    $f = array_map(function($v) {
1253 1250
                         $v = explode(' ', trim($v), 2);
1254 1251
                         if (count($v) === 2) {
1255 1252
                             return $v[1];
@@ -1257,16 +1254,16 @@  discard block
 block discarded – undo
1257 1254
                         $v = explode('.', $v[0], 2);
1258 1255
                         return count($v) === 2 ? $v[1] : $v[0];
1259 1256
                     }, $select);
1260
-                    $sql = "SELECT " . implode(', ', $f) . "
1257
+                    $sql = "SELECT ".implode(', ', $f)."
1261 1258
                             FROM (
1262 1259
                                 SELECT tbl__.*, rownum rnum__ FROM (
1263
-                                    " . $sql . "
1260
+                                    " . $sql."
1264 1261
                                 ) tbl__
1265
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1262
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1266 1263
                             ) WHERE rnum__ > " . $this->li_of[1];
1267 1264
                 }
1268 1265
             } else {
1269
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1266
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1270 1267
             }
1271 1268
         }
1272 1269
         return $this->qiterator = new TableQueryIterator(
@@ -1316,12 +1313,12 @@  discard block
 block discarded – undo
1316 1313
                 $ret[$k] = str_repeat(' ', 255);
1317 1314
                 $par[] = &$ret[$k];
1318 1315
             }
1319
-            $sql .= ' RETURNING ' . implode(',', $primary) .
1320
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
1316
+            $sql .= ' RETURNING '.implode(',', $primary).
1317
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
1321 1318
             $this->db->query($sql, $par);
1322 1319
             return $ret;
1323 1320
         } elseif ($this->db->driverName() === 'postgre') {
1324
-            $sql .= ' RETURNING ' . implode(',', $primary);
1321
+            $sql .= ' RETURNING '.implode(',', $primary);
1325 1322
             return $this->db->one($sql, $par, false);
1326 1323
         } else {
1327 1324
             $ret = [];
@@ -1352,9 +1349,9 @@  discard block
 block discarded – undo
1352 1349
         }
1353 1350
         $sql = 'UPDATE '.$table.' SET ';
1354 1351
         $par = [];
1355
-        $sql .= implode(', ', array_map(function ($v) {
1356
-            return $v . ' = ?';
1357
-        }, array_keys($update))) . ' ';
1352
+        $sql .= implode(', ', array_map(function($v) {
1353
+            return $v.' = ?';
1354
+        }, array_keys($update))).' ';
1358 1355
         $par = array_merge($par, array_values($update));
1359 1356
         if (count($this->where)) {
1360 1357
             $sql .= 'WHERE ';
@@ -1363,7 +1360,7 @@  discard block
 block discarded – undo
1363 1360
                 $tmp[] = $v[0];
1364 1361
                 $par = array_merge($par, $v[1]);
1365 1362
             }
1366
-            $sql .= implode(' AND ', $tmp) . ' ';
1363
+            $sql .= implode(' AND ', $tmp).' ';
1367 1364
         }
1368 1365
         if (count($this->order)) {
1369 1366
             $sql .= $this->order[0];
@@ -1387,7 +1384,7 @@  discard block
 block discarded – undo
1387 1384
                 $tmp[] = $v[0];
1388 1385
                 $par = array_merge($par, $v[1]);
1389 1386
             }
1390
-            $sql .= implode(' AND ', $tmp) . ' ';
1387
+            $sql .= implode(' AND ', $tmp).' ';
1391 1388
         }
1392 1389
         if (count($this->order)) {
1393 1390
             $sql .= $this->order[0];
@@ -1418,15 +1415,15 @@  discard block
 block discarded – undo
1418 1415
             try {
1419 1416
                 $name = array_reduce(
1420 1417
                     $parts,
1421
-                    function ($carry, $item) use (&$table, $select) {
1418
+                    function($carry, $item) use (&$table, $select) {
1422 1419
                         if (!$table->hasRelation($item)) {
1423
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1420
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1424 1421
                         }
1425 1422
                         $relation = $table->getRelation($item);
1426 1423
                         if (!$relation) {
1427
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1424
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1428 1425
                         }
1429
-                        $name = $carry ? $carry . static::SEP . $item : $item;
1426
+                        $name = $carry ? $carry.static::SEP.$item : $item;
1430 1427
                         $this->withr[$name] = [
1431 1428
                             $relation,
1432 1429
                             $carry ?? $table->getName(),
@@ -1495,9 +1492,9 @@  discard block
 block discarded – undo
1495 1492
 
1496 1493
         $aliases = [];
1497 1494
         $aliases_ext = [];
1498
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
1495
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
1499 1496
             // to bypass use: return $name;
1500
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1497
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1501 1498
             if (isset($aliases_ext[$name])) {
1502 1499
                 unset($aliases_ext[$name]);
1503 1500
             }
@@ -1517,7 +1514,7 @@  discard block
 block discarded – undo
1517 1514
         $w = $this->where;
1518 1515
         $h = $this->having;
1519 1516
         $o = $this->order;
1520
-        $j = array_map(function ($v) {
1517
+        $j = array_map(function($v) {
1521 1518
             return clone $v;
1522 1519
         }, $this->joins);
1523 1520
 
@@ -1526,24 +1523,24 @@  discard block
 block discarded – undo
1526 1523
                 continue;
1527 1524
             }
1528 1525
             foreach ($w as $kk => $v) {
1529
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1530
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1526
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1527
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1531 1528
                 }
1532 1529
             }
1533 1530
             foreach ($h as $kk => $v) {
1534
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1535
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
1531
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1532
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
1536 1533
                 }
1537 1534
             }
1538
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1539
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1535
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1536
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1540 1537
             }
1541 1538
             foreach ($j as $kk => $v) {
1542 1539
                 foreach ($v->keymap as $kkk => $vv) {
1543
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1540
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1544 1541
                         $j[$kk]->keymap[$kkk] = preg_replace(
1545
-                            '(\b'.preg_quote($k . '.'). ')i',
1546
-                            $getAlias($k) . '.',
1542
+                            '(\b'.preg_quote($k.'.').')i',
1543
+                            $getAlias($k).'.',
1547 1544
                             $vv
1548 1545
                         );
1549 1546
                     }
@@ -1552,52 +1549,52 @@  discard block
 block discarded – undo
1552 1549
         }
1553 1550
         foreach ($this->definition->getRelations() as $k => $v) {
1554 1551
             foreach ($w as $kk => $vv) {
1555
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1556
-                    $relations[$k] = [ $v, $table ];
1557
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1552
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1553
+                    $relations[$k] = [$v, $table];
1554
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1558 1555
                 }
1559 1556
             }
1560
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1561
-                $relations[$k] = [ $v, $table ];
1562
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1563
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1557
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1558
+                $relations[$k] = [$v, $table];
1559
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1560
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1564 1561
             }
1565 1562
             foreach ($h as $kk => $vv) {
1566
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1567
-                    $relations[$k] = [ $v, $table ];
1568
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1563
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1564
+                    $relations[$k] = [$v, $table];
1565
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1569 1566
                 }
1570 1567
             }
1571 1568
             foreach ($j as $kk => $vv) {
1572 1569
                 foreach ($vv->keymap as $kkk => $vvv) {
1573
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1574
-                        $relations[$k] = [ $v, $table ];
1570
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1571
+                        $relations[$k] = [$v, $table];
1575 1572
                         $j[$kk]->keymap[$kkk] =
1576
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1573
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1577 1574
                     }
1578 1575
                 }
1579 1576
             }
1580 1577
         }
1581 1578
         foreach ($aliases_ext as $k => $alias) {
1582 1579
             foreach ($w as $kk => $v) {
1583
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1584
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1580
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1581
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1585 1582
                 }
1586 1583
             }
1587 1584
             foreach ($h as $kk => $v) {
1588
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
1589
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
1585
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
1586
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
1590 1587
                 }
1591 1588
             }
1592
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1593
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
1589
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1590
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
1594 1591
             }
1595 1592
             foreach ($j as $kk => $v) {
1596 1593
                 foreach ($v->keymap as $kkk => $vv) {
1597
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1594
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1598 1595
                         $j[$kk]->keymap[$kkk] = preg_replace(
1599
-                            '(\b'.preg_quote($k . '.'). ')i',
1600
-                            $alias . '.',
1596
+                            '(\b'.preg_quote($k.'.').')i',
1597
+                            $alias.'.',
1601 1598
                             $vv
1602 1599
                         );
1603 1600
                     }
@@ -1605,29 +1602,29 @@  discard block
 block discarded – undo
1605 1602
             }
1606 1603
         }
1607 1604
 
1608
-        $key = array_map(function ($v) use ($table) {
1609
-            return $table . '.' . $v;
1605
+        $key = array_map(function($v) use ($table) {
1606
+            return $table.'.'.$v;
1610 1607
         }, $this->pkey);
1611 1608
         $own = false;
1612 1609
         $dir = 'ASC';
1613 1610
         if (count($o)) {
1614 1611
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1615
-            $own = strpos($o[2], $table . '.') === 0;
1612
+            $own = strpos($o[2], $table.'.') === 0;
1616 1613
         }
1617 1614
 
1618 1615
         $dst = $key;
1619 1616
         if (count($o)) {
1620 1617
             if ($own) {
1621 1618
                 // if using own table - do not use max/min in order - that will prevent index usage
1622
-                $dst[] = $o[2] . ' orderbyfix___';
1619
+                $dst[] = $o[2].' orderbyfix___';
1623 1620
             } else {
1624
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1621
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1625 1622
             }
1626 1623
         }
1627 1624
         $dst = array_unique($dst);
1628 1625
 
1629 1626
         $par = [];
1630
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1627
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1631 1628
         foreach ($relations as $k => $v) {
1632 1629
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1633 1630
             $v = $v[0];
@@ -1638,13 +1635,13 @@  discard block
 block discarded – undo
1638 1635
                 foreach ($v->keymap as $kk => $vv) {
1639 1636
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1640 1637
                 }
1641
-                $sql .= implode(' AND ', $tmp) . ' ';
1638
+                $sql .= implode(' AND ', $tmp).' ';
1642 1639
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
1643 1640
                 $tmp = [];
1644 1641
                 foreach ($v->pivot_keymap as $kk => $vv) {
1645 1642
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1646 1643
                 }
1647
-                $sql .= implode(' AND ', $tmp) . ' ';
1644
+                $sql .= implode(' AND ', $tmp).' ';
1648 1645
             } else {
1649 1646
                 $alias = $getAlias($k);
1650 1647
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -1653,37 +1650,37 @@  discard block
 block discarded – undo
1653 1650
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1654 1651
                 }
1655 1652
                 if ($v->sql) {
1656
-                    $tmp[] = $v->sql . ' ';
1653
+                    $tmp[] = $v->sql.' ';
1657 1654
                     $par = array_merge($par, $v->par ?? []);
1658 1655
                 }
1659
-                $sql .= implode(' AND ', $tmp) . ' ';
1656
+                $sql .= implode(' AND ', $tmp).' ';
1660 1657
             }
1661 1658
         }
1662 1659
         foreach ($j as $k => $v) {
1663
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1660
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
1664 1661
             $tmp = [];
1665 1662
             foreach ($v->keymap as $kk => $vv) {
1666 1663
                 $tmp[] = $kk.' = '.$vv;
1667 1664
             }
1668
-            $sql .= implode(' AND ', $tmp) . ' ';
1665
+            $sql .= implode(' AND ', $tmp).' ';
1669 1666
         }
1670 1667
         if (count($w)) {
1671 1668
             $sql .= 'WHERE ';
1672 1669
             $tmp = [];
1673 1670
             foreach ($w as $v) {
1674
-                $tmp[] = '(' . $v[0] . ')';
1671
+                $tmp[] = '('.$v[0].')';
1675 1672
                 $par = array_merge($par, $v[1]);
1676 1673
             }
1677 1674
             $sql .= implode(' AND ', $tmp).' ';
1678 1675
         }
1679 1676
         if (!$own) {
1680
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1677
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1681 1678
         }
1682 1679
         if (count($h)) {
1683 1680
             $sql .= 'HAVING ';
1684 1681
             $tmp = [];
1685 1682
             foreach ($h as $v) {
1686
-                $tmp[] = '(' . $v[0] . ')';
1683
+                $tmp[] = '('.$v[0].')';
1687 1684
                 $par = array_merge($par, $v[1]);
1688 1685
             }
1689 1686
             $sql .= implode(' AND ', $tmp).' ';
@@ -1691,38 +1688,38 @@  discard block
 block discarded – undo
1691 1688
         if (count($o)) {
1692 1689
             $sql .= 'ORDER BY ';
1693 1690
             if ($own) {
1694
-                $sql .= $o[2] . ' ' . $dir;
1691
+                $sql .= $o[2].' '.$dir;
1695 1692
             } else {
1696
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1693
+                $sql .= 'MAX('.$o[2].') '.$dir;
1697 1694
             }
1698 1695
         }
1699 1696
         $porder = [];
1700 1697
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1701 1698
         foreach ($this->definition->getPrimaryKey() as $field) {
1702
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1699
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1703 1700
         }
1704 1701
         if (count($porder)) {
1705
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1702
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1706 1703
         }
1707 1704
 
1708 1705
         if ($this->li_of[0]) {
1709 1706
             if ($this->db->driverName() === 'oracle') {
1710
-                if ((int)$this->db->driverOption('version', 12) >= 12) {
1711
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1707
+                if ((int) $this->db->driverOption('version', 12) >= 12) {
1708
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1712 1709
                 } else {
1713
-                    $sql = "SELECT " . implode(', ', $dst) . "
1710
+                    $sql = "SELECT ".implode(', ', $dst)."
1714 1711
                             FROM (
1715 1712
                                 SELECT tbl__.*, rownum rnum__ FROM (
1716
-                                    " . $sql . "
1713
+                                    " . $sql."
1717 1714
                                 ) tbl__
1718
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1715
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1719 1716
                             ) WHERE rnum__ > " . $this->li_of[1];
1720 1717
                 }
1721 1718
             } else {
1722
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1719
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1723 1720
             }
1724 1721
         }
1725
-        return array_map(function ($v) {
1722
+        return array_map(function($v) {
1726 1723
             if (array_key_exists('orderbyfix___', $v)) {
1727 1724
                 unset($v['orderbyfix___']);
1728 1725
             }
Please login to merge, or discard this patch.
src/schema/Entity.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             }
97 97
             $this->cached[$method] = $rslt;
98 98
         } else {
99
-            throw new DBException('Invalid relation name: ' . $method);
99
+            throw new DBException('Invalid relation name: '.$method);
100 100
         }
101 101
         return $this->cached[$method] ?? null;
102 102
     }
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
     protected function relatedQuery(string $name): TableQueryMapped
108 108
     {
109 109
         if (!array_key_exists($name, $this->relations)) {
110
-            throw new DBException('Invalid relation name: ' . $name);
110
+            throw new DBException('Invalid relation name: '.$name);
111 111
         }
112 112
         return call_user_func_array($this->relations[$name], [$this, true]);
113 113
     }
114 114
     protected function relatedRow(string $name): mixed
115 115
     {
116 116
         if (!array_key_exists($name, $this->relations)) {
117
-            throw new DBException('Invalid relation name: ' . $name);
117
+            throw new DBException('Invalid relation name: '.$name);
118 118
         }
119 119
         return call_user_func_array($this->relations[$name], [$this]);
120 120
     }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
     protected function relatedRows(string $name): Collection
126 126
     {
127 127
         if (!array_key_exists($name, $this->relations)) {
128
-            throw new DBException('Invalid relation name: ' . $name);
128
+            throw new DBException('Invalid relation name: '.$name);
129 129
         }
130 130
         return call_user_func_array($this->relations[$name], [$this]);
131 131
     }
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $temp = $this->data;
135 135
         foreach ($this->relations as $name => $relation) {
136 136
             try {
137
-                $temp[$name] = call_user_func_array($relation, [ $this, false, true ]);
137
+                $temp[$name] = call_user_func_array($relation, [$this, false, true]);
138 138
             } catch (DBException $ignore) {}
139 139
         }
140 140
         return $temp;
Please login to merge, or discard this patch.
src/driver/sqlite/Schema.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
             $table = $temp[1];
30 30
         }
31 31
 
32
-        if (isset($tables[$schema . '.' . $table])) {
33
-            return $tables[$schema . '.' . $table];
32
+        if (isset($tables[$schema.'.'.$table])) {
33
+            return $tables[$schema.'.'.$table];
34 34
         }
35 35
 
36 36
         static $relationsT = null;
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
                             ]
54 54
                         )
55 55
                     );
56
-                    $relationsT['main.' . $row['table']][] = $row;
57
-                    $relationsR['main.' . $row['referenced_table']][] = $row;
56
+                    $relationsT['main.'.$row['table']][] = $row;
57
+                    $relationsR['main.'.$row['referenced_table']][] = $row;
58 58
                 }
59 59
             }
60 60
         }
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
          */
65 65
         $columns = Collection::from($this
66 66
             ->query("PRAGMA table_info(".$table.")"))
67
-            ->mapKey(function ($v): string {
67
+            ->mapKey(function($v): string {
68 68
                 return $v['name'];
69 69
             })
70
-            ->map(function ($v) {
70
+            ->map(function($v) {
71 71
                 $v['length'] = null;
72 72
                 if (!isset($v['type'])) {
73 73
                     return $v;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
                     default:
78 78
                         if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
79 79
                             // extract length from varchar
80
-                            $v['length'] = (int)explode(')', explode('(', $type)[1])[0];
80
+                            $v['length'] = (int) explode(')', explode('(', $type)[1])[0];
81 81
                             $v['length'] = $v['length'] > 0 ? $v['length'] : null;
82 82
                         }
83 83
                         break;
@@ -86,35 +86,35 @@  discard block
 block discarded – undo
86 86
             })
87 87
             ->toArray();
88 88
         if (!count($columns)) {
89
-            throw new DBException('Table not found by name: ' . implode('.', [$schema,$table]));
89
+            throw new DBException('Table not found by name: '.implode('.', [$schema, $table]));
90 90
         }
91 91
         $primary = [];
92 92
         foreach ($columns as $column) {
93
-            if ((int)$column['pk']) {
93
+            if ((int) $column['pk']) {
94 94
                 $primary[] = $column['name'];
95 95
             }
96 96
         }
97
-        $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema))
97
+        $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema))
98 98
             ->addColumns($columns)
99 99
             ->setPrimaryKey($primary)
100 100
             ->setComment('');
101 101
 
102 102
         if ($detectRelations) {
103 103
             $duplicated = [];
104
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
105
-                $t = 'main.' . $relation['referenced_table'];
104
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
105
+                $t = 'main.'.$relation['referenced_table'];
106 106
                 $duplicated[$t] = isset($duplicated[$t]);
107 107
             }
108
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) {
109
-                $t = 'main.' . $relation['table'];
108
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) {
109
+                $t = 'main.'.$relation['table'];
110 110
                 $duplicated[$t] = isset($duplicated[$t]);
111 111
             }
112 112
             // pivot relations where the current table is referenced
113 113
             // assuming current table is on the "one" end having "many" records in the referencing table
114 114
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
115 115
             $relations = [];
116
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
117
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
116
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
117
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
118 118
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
119 119
             }
120 120
             ksort($relations);
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
                 $usedcol = [];
131 131
                 if (count($columns)) {
132 132
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
133
-                        ->filter(function ($v) use ($columns) {
133
+                        ->filter(function($v) use ($columns) {
134 134
                             return in_array($v['from'], $columns);
135 135
                         }) as $relation
136 136
                     ) {
137
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
137
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
138 138
                             $relation['referenced_table'];
139 139
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
140 140
                         $usedcol[] = $relation['from'];
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                         $definition->getName() == $relname ||
154 154
                         $definition->getColumn($relname)
155 155
                     ) {
156
-                        $relname = $orig . '_' . (++ $cntr);
156
+                        $relname = $orig.'_'.(++$cntr);
157 157
                     }
158 158
                     $definition->addRelation(
159 159
                         new TableRelation(
@@ -175,8 +175,8 @@  discard block
 block discarded – undo
175 175
             // assuming current table is linked to "one" record in the referenced table
176 176
             // resulting in a "belongsTo" relationship
177 177
             $relations = [];
178
-            foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) {
179
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table'];
178
+            foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) {
179
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table'];
180 180
                 $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
181 181
             }
182 182
             ksort($relations);
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     $definition->getName() == $relname ||
192 192
                     $definition->getColumn($relname)
193 193
                 ) {
194
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
194
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
195 195
                 }
196 196
                 $orig = $relname;
197 197
                 $cntr = 1;
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     $definition->getName() == $relname ||
200 200
                     $definition->getColumn($relname)
201 201
                 ) {
202
-                    $relname = $orig . '_' . (++ $cntr);
202
+                    $relname = $orig.'_'.(++$cntr);
203 203
                 }
204 204
                 $definition->addRelation(
205 205
                     new TableRelation(
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
             // assuming current table is on the "one" end having "many" records in the referencing table
216 216
             // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected)
217 217
             $relations = [];
218
-            foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) {
219
-                $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table'];
218
+            foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) {
219
+                $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table'];
220 220
                 $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from'];
221 221
             }
222 222
             ksort($relations);
@@ -232,11 +232,11 @@  discard block
 block discarded – undo
232 232
                 $usedcol = [];
233 233
                 if (count($columns)) {
234 234
                     foreach (Collection::from($relationsT[$data['table']] ?? [])
235
-                        ->filter(function ($v) use ($columns) {
235
+                        ->filter(function($v) use ($columns) {
236 236
                             return in_array($v['from'], $columns);
237 237
                         }) as $relation
238 238
                     ) {
239
-                        $foreign[$relation['constraint_name']]['table'] = 'main.' .
239
+                        $foreign[$relation['constraint_name']]['table'] = 'main.'.
240 240
                             $relation['referenced_table'];
241 241
                         $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to'];
242 242
                         $usedcol[] = $relation['from'];
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
                         $definition->getName() == $relname ||
254 254
                         $definition->getColumn($relname)
255 255
                     ) {
256
-                        $relname .= '_' . array_values($data['keymap'])[0];
256
+                        $relname .= '_'.array_values($data['keymap'])[0];
257 257
                     }
258 258
                     $orig = $relname;
259 259
                     $cntr = 1;
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
                         $definition->getName() == $relname ||
262 262
                         $definition->getColumn($relname)
263 263
                     ) {
264
-                        $relname = $orig . '_' . (++ $cntr);
264
+                        $relname = $orig.'_'.(++$cntr);
265 265
                     }
266 266
                     $definition->addRelation(
267 267
                         new TableRelation(
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
                 "SELECT tbl_name
290 290
                  FROM sqlite_schema
291 291
                  WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';",
292
-                [ 'table', 'view' ]
292
+                ['table', 'view']
293 293
             ))
294
-            ->mapKey(function ($v) {
294
+            ->mapKey(function($v) {
295 295
                 return strtolower($v['tbl_name']);
296 296
             })
297 297
             ->pluck('tbl_name')
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
             $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase();
301 301
         }
302 302
         foreach (array_keys($tables) as $k) {
303
-            $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k];
303
+            $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k];
304 304
         }
305 305
         return $tables;
306 306
     }
Please login to merge, or discard this patch.
src/driver/oracle/Schema.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
         $columns = Collection::from($this
33 33
             ->query(
34 34
                 "SELECT * FROM user_tab_cols WHERE UPPER(table_name) = ?",
35
-                [ strtoupper($table) ]
35
+                [strtoupper($table)]
36 36
             ))
37
-            ->map(function ($v) {
37
+            ->map(function($v) {
38 38
                 $new = [];
39 39
                 foreach ($v as $kk => $vv) {
40 40
                     $new[strtoupper($kk)] = $vv;
41 41
                 }
42 42
                 return $new;
43 43
             })
44
-            ->mapKey(function ($v): string {
44
+            ->mapKey(function($v): string {
45 45
                 return $v['COLUMN_NAME'];
46 46
             })
47
-            ->map(function ($v) {
47
+            ->map(function($v) {
48 48
                 $v['length'] = null;
49 49
                 if (!isset($v['DATA_TYPE'])) {
50 50
                     return $v;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                     default:
57 57
                         if (strpos($type, 'char') !== false && strpos($type, '(') !== false) {
58 58
                             // extract length from varchar
59
-                            $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0];
59
+                            $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0];
60 60
                             $v['length'] = $v['length'] > 0 ? $v['length'] : null;
61 61
                         }
62 62
                         break;
@@ -73,9 +73,9 @@  discard block
 block discarded – undo
73 73
             ->query(
74 74
                 "SELECT constraint_name FROM user_constraints
75 75
                 WHERE table_name = ? AND constraint_type = ?",
76
-                [ strtoupper($table), 'P' ]
76
+                [strtoupper($table), 'P']
77 77
             ))
78
-            ->map(function ($v) {
78
+            ->map(function($v) {
79 79
                 $new = [];
80 80
                 foreach ($v as $kk => $vv) {
81 81
                     $new[strtoupper($kk)] = $vv;
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
                 ->query(
91 91
                     "SELECT column_name FROM user_cons_columns
92 92
                     WHERE table_name = ? AND constraint_name = ?",
93
-                    [ strtoupper($table), $pkname ]
93
+                    [strtoupper($table), $pkname]
94 94
                 ))
95
-                ->map(function ($v) {
95
+                ->map(function($v) {
96 96
                     $new = [];
97 97
                     foreach ($v as $kk => $vv) {
98 98
                         $new[strtoupper($kk)] = $vv;
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
                     LEFT JOIN user_cons_columns cc ON cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
121 121
                     WHERE ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
122 122
                     ORDER BY cc.POSITION",
123
-                    [ strtoupper($table), 'R' ]
123
+                    [strtoupper($table), 'R']
124 124
                 ))
125
-                ->map(function ($v) {
125
+                ->map(function($v) {
126 126
                     $new = [];
127 127
                     foreach ($v as $kk => $vv) {
128 128
                         $new[strtoupper($kk)] = $vv;
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
                     WHERE
139 139
                         ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
140 140
                     ORDER BY cc.POSITION",
141
-                    [ $pkname, 'R' ]
141
+                    [$pkname, 'R']
142 142
                 ))
143
-                ->map(function ($v) {
143
+                ->map(function($v) {
144 144
                     $new = [];
145 145
                     foreach ($v as $kk => $vv) {
146 146
                         $new[strtoupper($kk)] = $vv;
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             $relations = [];
164 164
             foreach ($relationsR as $relation) {
165 165
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
166
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
166
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
167 167
                     $relation['COLUMN_NAME'];
168 168
             }
169 169
             ksort($relations);
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
                                 ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
195 195
                                 cc.COLUMN_NAME IN (??)
196 196
                             ORDER BY POSITION",
197
-                            [ $data['table'], 'R', $columns ]
197
+                            [$data['table'], 'R', $columns]
198 198
                         ))
199
-                        ->map(function ($v) {
199
+                        ->map(function($v) {
200 200
                             $new = [];
201 201
                             foreach ($v as $kk => $vv) {
202 202
                                 $new[strtoupper($kk)] = $vv;
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
                         ->query(
217 217
                             "SELECT COLUMN_NAME FROM user_cons_columns
218 218
                             WHERE CONSTRAINT_NAME = ? ORDER BY POSITION",
219
-                            [ current($foreign['keymap']) ]
219
+                            [current($foreign['keymap'])]
220 220
                         ))
221
-                        ->map(function ($v) {
221
+                        ->map(function($v) {
222 222
                             $new = [];
223 223
                             foreach ($v as $kk => $vv) {
224 224
                                 $new[strtoupper($kk)] = $vv;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                     $relname = $foreign['table'];
234 234
                     $cntr = 1;
235 235
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
236
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
236
+                        $relname = $foreign['table'].'_'.(++$cntr);
237 237
                     }
238 238
                     $definition->addRelation(
239 239
                         new TableRelation(
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
                     ->query(
267 267
                         "SELECT COLUMN_NAME FROM user_cons_columns
268 268
                          WHERE CONSTRAINT_NAME = ? ORDER BY POSITION",
269
-                        [ current($data['keymap']) ]
269
+                        [current($data['keymap'])]
270 270
                     ))
271
-                    ->map(function ($v) {
271
+                    ->map(function($v) {
272 272
                         $new = [];
273 273
                         foreach ($v as $kk => $vv) {
274 274
                             $new[strtoupper($kk)] = $vv;
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                     $definition->getName() == $relname ||
287 287
                     $definition->getColumn($relname)
288 288
                 ) {
289
-                    $relname = array_keys($data['keymap'])[0] . '_' . $relname;
289
+                    $relname = array_keys($data['keymap'])[0].'_'.$relname;
290 290
                 }
291 291
                 $orig = $relname;
292 292
                 $cntr = 1;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                     $definition->getName() == $relname ||
296 296
                     $definition->getColumn($relname)
297 297
                 ) {
298
-                    $relname = $orig . '_' . (++ $cntr);
298
+                    $relname = $orig.'_'.(++$cntr);
299 299
                 }
300 300
                 $definition->addRelation(
301 301
                     new TableRelation(
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
             $relations = [];
314 314
             foreach ($relationsR as $relation) {
315 315
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
316
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] =
316
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] =
317 317
                     $relation['COLUMN_NAME'];
318 318
             }
319 319
             ksort($relations);
@@ -344,9 +344,9 @@  discard block
 block discarded – undo
344 344
                                 ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
345 345
                                 cc.COLUMN_NAME IN (??)
346 346
                             ORDER BY POSITION",
347
-                            [ $data['table'], 'R', $columns ]
347
+                            [$data['table'], 'R', $columns]
348 348
                         ))
349
-                        ->map(function ($v) {
349
+                        ->map(function($v) {
350 350
                             $new = [];
351 351
                             foreach ($v as $kk => $vv) {
352 352
                                 $new[strtoupper($kk)] = $vv;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                         $definition->getName() == $relname ||
368 368
                         $definition->getColumn($relname)
369 369
                     ) {
370
-                        $relname .= '_' . array_values($data['keymap'])[0];
370
+                        $relname .= '_'.array_values($data['keymap'])[0];
371 371
                     }
372 372
                     $orig = $relname;
373 373
                     $cntr = 1;
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
                         $definition->getName() == $relname ||
377 377
                         $definition->getColumn($relname)
378 378
                     ) {
379
-                        $relname = $orig . '_' . (++ $cntr);
379
+                        $relname = $orig.'_'.(++$cntr);
380 380
                     }
381 381
                     $definition->addRelation(
382 382
                         new TableRelation(
@@ -406,18 +406,18 @@  discard block
 block discarded – undo
406 406
                  SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS",
407 407
                 []
408 408
             ))
409
-            ->map(function ($v) {
409
+            ->map(function($v) {
410 410
                 $new = [];
411 411
                 foreach ($v as $kk => $vv) {
412 412
                     $new[strtoupper($kk)] = $vv;
413 413
                 }
414 414
                 return $new;
415 415
             })
416
-            ->mapKey(function ($v) {
416
+            ->mapKey(function($v) {
417 417
                 return strtolower($v['TABLE_NAME']);
418 418
             })
419 419
             ->pluck('TABLE_NAME')
420
-            ->map(function ($v) {
420
+            ->map(function($v) {
421 421
                 return $this->table($v)->toLowerCase();
422 422
             })
423 423
             ->toArray();
Please login to merge, or discard this patch.