Completed
Push — master ( 41bcf8...3bf301 )
by Ivan
11:14
created
src/DB.php 1 patch
Spacing   +16 added lines, -18 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         $connection['pass'] = isset($temp['pass']) && strlen($temp['pass']) ? $temp['pass'] : null;
75 75
         $connection['host'] = isset($temp['host']) && strlen($temp['host']) ? $temp['host'] : null;
76 76
         $connection['name'] = isset($temp['path']) && strlen($temp['path']) ? trim($temp['path'], '/') : null;
77
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
77
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
78 78
         if (isset($temp['query']) && strlen($temp['query'])) {
79 79
             parse_str($temp['query'], $connection['opts']);
80 80
         }
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
         $new = '';
118 118
         $par = array_values($par);
119 119
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
120
-            $par = [ $par ];
120
+            $par = [$par];
121 121
         }
122 122
         $parts = explode('??', $sql);
123 123
         $index = 0;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             $index += count($tmp) - 1;
128 128
             if (isset($par[$index])) {
129 129
                 if (!is_array($par[$index])) {
130
-                    $par[$index] = [ $par[$index] ];
130
+                    $par[$index] = [$par[$index]];
131 131
                 }
132 132
                 $params = $par[$index];
133 133
                 array_splice($par, $index, 1, $params);
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                 $new .= implode(',', array_fill(0, count($params), '?'));
136 136
             }
137 137
         }
138
-        return [ $new, $par ];
138
+        return [$new, $par];
139 139
     }
140 140
     /**
141 141
      * Run a query (prepare & execute).
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
     ): Collection {
185 185
         $coll = Collection::from($this->query($sql, $par, $buff));
186 186
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
187
-            $coll->map(function ($v) use ($keys) {
187
+            $coll->map(function($v) use ($keys) {
188 188
                 $new = [];
189 189
                 foreach ($v as $k => $vv) {
190 190
                     $new[call_user_func($keys, $k)] = $vv;
@@ -193,18 +193,18 @@  discard block
 block discarded – undo
193 193
             });
194 194
         }
195 195
         if ($key !== null) {
196
-            $coll->mapKey(function ($v) use ($key) {
196
+            $coll->mapKey(function($v) use ($key) {
197 197
                 return $v[$key];
198 198
             });
199 199
         }
200 200
         if ($skip) {
201
-            $coll->map(function ($v) use ($key) {
201
+            $coll->map(function($v) use ($key) {
202 202
                 unset($v[$key]);
203 203
                 return $v;
204 204
             });
205 205
         }
206 206
         if ($opti) {
207
-            $coll->map(function ($v) {
207
+            $coll->map(function($v) {
208 208
                 return count($v) === 1 ? current($v) : $v;
209 209
             });
210 210
         }
@@ -299,8 +299,7 @@  discard block
 block discarded – undo
299 299
     public function definition(string $table, bool $detectRelations = true) : Table
300 300
     {
301 301
         return isset($this->tables[$table]) ?
302
-            $this->tables[$table] :
303
-            $this->driver->table($table, $detectRelations);
302
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
304 303
     }
305 304
     /**
306 305
      * Parse all tables from the database.
@@ -317,13 +316,13 @@  discard block
 block discarded – undo
317 316
      */
318 317
     public function getSchema($asPlainArray = true)
319 318
     {
320
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
319
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
321 320
             return [
322 321
                 'name' => $table->getName(),
323 322
                 'schema' => $table->getSchema(),
324 323
                 'pkey' => $table->getPrimaryKey(),
325 324
                 'comment' => $table->getComment(),
326
-                'columns' => array_map(function ($column) {
325
+                'columns' => array_map(function($column) {
327 326
                     return [
328 327
                         'name' => $column->getName(),
329 328
                         'type' => $column->getType(),
@@ -334,9 +333,9 @@  discard block
 block discarded – undo
334 333
                         'nullable' => $column->isNullable()
335 334
                     ];
336 335
                 }, $table->getFullColumns()),
337
-                'relations' => array_map(function ($rel) {
336
+                'relations' => array_map(function($rel) {
338 337
                     $relation = clone $rel;
339
-                    $relation = (array)$relation;
338
+                    $relation = (array) $relation;
340 339
                     $relation['table'] = $rel->table->getName();
341 340
                     if ($rel->pivot) {
342 341
                         $relation['pivot'] = $rel->pivot->getName();
@@ -393,8 +392,7 @@  discard block
 block discarded – undo
393 392
     public function table(string $table, bool $mapped = false)
394 393
     {
395 394
         return $mapped ?
396
-            new TableQueryMapped($this, $this->definition($table)) :
397
-            new TableQuery($this, $this->definition($table));
395
+            new TableQueryMapped($this, $this->definition($table)) : new TableQuery($this, $this->definition($table));
398 396
     }
399 397
     public function __call($method, $args)
400 398
     {
@@ -428,12 +426,12 @@  discard block
 block discarded – undo
428 426
                     $relations[$t] = $w;
429 427
                 }
430 428
                 if (!isset($schema[$name])) {
431
-                    $schema[$name] = [ 'edges' => [] ];
429
+                    $schema[$name] = ['edges' => []];
432 430
                 }
433 431
                 foreach ($relations as $t => $w) {
434 432
                     $schema[$name]['edges'][$t] = $w;
435 433
                     if (!isset($schema[$t])) {
436
-                        $schema[$t] = [ 'edges' => [] ];
434
+                        $schema[$t] = ['edges' => []];
437 435
                     }
438 436
                     $schema[$t]['edges'][$name] = $w;
439 437
                 }
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +234 added lines, -238 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     /**
46 46
      * @var int[]
47 47
      */
48
-    protected $li_of = [0,0,0];
48
+    protected $li_of = [0, 0, 0];
49 49
     /**
50 50
      * @var array
51 51
      */
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     public function __construct(DBInterface $db, $table)
76 76
     {
77 77
         $this->db = $db;
78
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
78
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
79 79
         $primary = $this->definition->getPrimaryKey();
80 80
         $columns = $this->definition->getColumns();
81 81
         $this->pkey = count($primary) ? $primary : $columns;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     {
99 99
         $column = explode('.', $column);
100 100
         if (count($column) === 1) {
101
-            $column = [ $this->definition->getFullName(), $column[0] ];
101
+            $column = [$this->definition->getFullName(), $column[0]];
102 102
             $col = $this->definition->getColumn($column[1]);
103 103
             if (!$col) {
104 104
                 throw new DBException('Invalid column name in own table');
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                     if (!$col) {
135 135
                         $path = $this->db->findRelation($this->definition->getName(), $column[0]);
136 136
                         if (!count($path)) {
137
-                            throw new DBException('Invalid foreign table / column name: ' . implode(',', $column));
137
+                            throw new DBException('Invalid foreign table / column name: '.implode(',', $column));
138 138
                         }
139 139
                         unset($path[0]);
140 140
                         $this->with(implode('.', $path), false);
@@ -147,26 +147,26 @@  discard block
 block discarded – undo
147 147
             if ($this->definition->hasRelation(implode('.', $column))) {
148 148
                 $this->with(implode('.', $column), false);
149 149
                 $col = $this->definition->getRelation(implode('.', $column))->table->getColumn($name);
150
-                $column = [ implode('.', $column), $name ];
150
+                $column = [implode('.', $column), $name];
151 151
             } else {
152 152
                 $this->with(implode('.', $column), false);
153 153
                 $table = $this->definition;
154 154
                 $table = array_reduce(
155 155
                     $column,
156
-                    function ($carry, $item) use (&$table) {
156
+                    function($carry, $item) use (&$table) {
157 157
                         $table = $table->getRelation($item)->table;
158 158
                         return $table;
159 159
                     }
160 160
                 );
161 161
                 $col = $table->getColumn($name);
162
-                $column = [ implode(static::SEP, $column), $name ];
162
+                $column = [implode(static::SEP, $column), $name];
163 163
             }
164 164
         }
165
-        return [ 'name' => implode('.', $column), 'data' => $col ];
165
+        return ['name' => implode('.', $column), 'data' => $col];
166 166
     }
167 167
     protected function normalizeValue(TableColumn $col, $value)
168 168
     {
169
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
169
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
170 170
         if ($value === null && $col->isNullable()) {
171 171
             return null;
172 172
         }
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
                     $temp = strtotime($value);
177 177
                     if (!$temp) {
178 178
                         if ($strict) {
179
-                            throw new DBException('Invalid value for date column ' . $col->getName());
179
+                            throw new DBException('Invalid value for date column '.$col->getName());
180 180
                         }
181 181
                         return null;
182 182
                     }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                     return $value->format('Y-m-d');
190 190
                 }
191 191
                 if ($strict) {
192
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
192
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
193 193
                 }
194 194
                 return $value;
195 195
             case 'datetime':
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
                     $temp = strtotime($value);
198 198
                     if (!$temp) {
199 199
                         if ($strict) {
200
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
200
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
201 201
                         }
202 202
                         return null;
203 203
                     }
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
                     return $value->format('Y-m-d H:i:s');
211 211
                 }
212 212
                 if ($strict) {
213
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
213
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
214 214
                 }
215 215
                 return $value;
216 216
             case 'enum':
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                 if (is_int($value)) {
219 219
                     if (!isset($values[$value])) {
220 220
                         if ($strict) {
221
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
221
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
222 222
                         }
223 223
                         return $value;
224 224
                     }
@@ -226,23 +226,23 @@  discard block
 block discarded – undo
226 226
                 }
227 227
                 if (!in_array($value, $col->getValues())) {
228 228
                     if ($strict) {
229
-                        throw new DBException('Invalid value for enum ' . $col->getName());
229
+                        throw new DBException('Invalid value for enum '.$col->getName());
230 230
                     }
231 231
                     return 0;
232 232
                 }
233 233
                 return $value;
234 234
             case 'int':
235 235
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
236
-                return is_string($temp) ? (int)$temp : 0;
236
+                return is_string($temp) ? (int) $temp : 0;
237 237
             case 'float':
238 238
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
239
-                return is_string($temp) ? (float)$temp : 0;
239
+                return is_string($temp) ? (float) $temp : 0;
240 240
             case 'text':
241 241
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
242 242
                 // because the polyfill is quite slow
243 243
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
244 244
                     if ($strict) {
245
-                        throw new DBException('Invalid value for text column ' . $col->getName());
245
+                        throw new DBException('Invalid value for text column '.$col->getName());
246 246
                     }
247 247
                     return mb_substr($value, 0, $col->getLength());
248 248
                 }
@@ -264,35 +264,32 @@  discard block
 block discarded – undo
264 264
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
265 265
             return $negate ?
266 266
                 [
267
-                    $name . ' NOT LIKE ?',
268
-                    [ $this->normalizeValue($column, $value) ]
269
-                ] :
270
-                [
271
-                    $name . ' LIKE ?',
272
-                    [ $this->normalizeValue($column, $value) ]
267
+                    $name.' NOT LIKE ?',
268
+                    [$this->normalizeValue($column, $value)]
269
+                ] : [
270
+                    $name.' LIKE ?',
271
+                    [$this->normalizeValue($column, $value)]
273 272
                 ];
274 273
         }
275 274
         if (is_null($value)) {
276 275
             return $negate ?
277
-                [ $name . ' IS NOT NULL', [] ]:
278
-                [ $name . ' IS NULL', [] ];
276
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
279 277
         }
280 278
         if (!is_array($value)) {
281 279
             return $negate ?
282 280
                 [
283
-                    $name . ' <> ?',
284
-                    [ $this->normalizeValue($column, $value) ]
285
-                ] :
286
-                [
287
-                    $name . ' = ?',
288
-                    [ $this->normalizeValue($column, $value) ]
281
+                    $name.' <> ?',
282
+                    [$this->normalizeValue($column, $value)]
283
+                ] : [
284
+                    $name.' = ?',
285
+                    [$this->normalizeValue($column, $value)]
289 286
                 ];
290 287
         }
291 288
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
292
-            $value = [ 'gte' => $value['beg'] ];
289
+            $value = ['gte' => $value['beg']];
293 290
         }
294 291
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
295
-            $value = [ 'lte' => $value['end'] ];
292
+            $value = ['lte' => $value['end']];
296 293
         }
297 294
         if (isset($value['beg']) && isset($value['end'])) {
298 295
             return $negate ?
@@ -302,8 +299,7 @@  discard block
 block discarded – undo
302 299
                         $this->normalizeValue($column, $value['beg']),
303 300
                         $this->normalizeValue($column, $value['end'])
304 301
                     ]
305
-                ] :
306
-                [
302
+                ] : [
307 303
                     $name.' BETWEEN ? AND ?',
308 304
                     [
309 305
                         $this->normalizeValue($column, $value['beg']),
@@ -315,42 +311,42 @@  discard block
 block discarded – undo
315 311
             $sql = [];
316 312
             $par = [];
317 313
             if (isset($value['gt'])) {
318
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
314
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
319 315
                 $par[] = $this->normalizeValue($column, $value['gt']);
320 316
             }
321 317
             if (isset($value['gte'])) {
322
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
318
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
323 319
                 $par[] = $this->normalizeValue($column, $value['gte']);
324 320
             }
325 321
             if (isset($value['lt'])) {
326
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
322
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
327 323
                 $par[] = $this->normalizeValue($column, $value['lt']);
328 324
             }
329 325
             if (isset($value['lte'])) {
330
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
326
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
331 327
                 $par[] = $this->normalizeValue($column, $value['lte']);
332 328
             }
333 329
             return [
334
-                '(' . implode(' AND ', $sql) . ')',
330
+                '('.implode(' AND ', $sql).')',
335 331
                 $par
336 332
             ];
337 333
         }
338 334
 
339
-        $value = array_values(array_map(function ($v) use ($column) {
335
+        $value = array_values(array_map(function($v) use ($column) {
340 336
             return $this->normalizeValue($column, $v);
341 337
         }, $value));
342 338
         if ($this->db->driverName() === 'oracle') {
343 339
             $sql = [];
344 340
             $par = [];
345 341
             for ($i = 0; $i < count($value); $i += 500) {
346
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
342
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
347 343
                 $par[] = array_slice($value, $i, 500);
348 344
             }
349
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
350
-            return [ $sql, [$par] ];
345
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
346
+            return [$sql, [$par]];
351 347
         }
352 348
         return [
353
-            $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)',
349
+            $negate ? $name.' NOT IN (??)' : $name.' IN (??)',
354 350
             [$value]
355 351
         ];
356 352
     }
@@ -382,7 +378,7 @@  discard block
 block discarded – undo
382 378
                 $par = array_merge($par, $temp[1]);
383 379
             }
384 380
         }
385
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
381
+        return $this->where('('.implode(' OR ', $sql).')', $par);
386 382
     }
387 383
     /**
388 384
      * Filter the results matching all of the criteria
@@ -400,7 +396,7 @@  discard block
 block discarded – undo
400 396
                 $par = array_merge($par, $temp[1]);
401 397
             }
402 398
         }
403
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
399
+        return $this->where('('.implode(' AND ', $sql).')', $par);
404 400
     }
405 401
     /**
406 402
      * Sort by a column
@@ -415,7 +411,7 @@  discard block
 block discarded – undo
415 411
         } catch (DBException $e) {
416 412
             throw new DBException('Invalid sort column');
417 413
         }
418
-        return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC'));
414
+        return $this->order($column.' '.($desc ? 'DESC' : 'ASC'));
419 415
     }
420 416
     /**
421 417
      * Group by a column (or columns)
@@ -425,7 +421,7 @@  discard block
 block discarded – undo
425 421
     public function group($column) : self
426 422
     {
427 423
         if (!is_array($column)) {
428
-            $column = [ $column ];
424
+            $column = [$column];
429 425
         }
430 426
         foreach ($column as $k => $v) {
431 427
             $column[$k] = $this->getColumn($v)['name'];
@@ -467,7 +463,7 @@  discard block
 block discarded – undo
467 463
         $this->order = [];
468 464
         $this->having = [];
469 465
         $this->aliases = [];
470
-        $this->li_of = [0,0,0];
466
+        $this->li_of = [0, 0, 0];
471 467
         $this->qiterator = null;
472 468
         return $this;
473 469
     }
@@ -480,7 +476,7 @@  discard block
 block discarded – undo
480 476
     public function groupBy(string $sql, array $params = []) : self
481 477
     {
482 478
         $this->qiterator = null;
483
-        $this->group = [ $sql, $params ];
479
+        $this->group = [$sql, $params];
484 480
         return $this;
485 481
     }
486 482
     /**
@@ -493,7 +489,7 @@  discard block
 block discarded – undo
493 489
      */
494 490
     public function join($table, array $fields, string $name = null, bool $multiple = true)
495 491
     {
496
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
492
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
497 493
         $name = $name ?? $table->getName();
498 494
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
499 495
             throw new DBException('Alias / table name already in use');
@@ -502,7 +498,7 @@  discard block
 block discarded – undo
502 498
         foreach ($fields as $k => $v) {
503 499
             $k = explode('.', $k, 2);
504 500
             $k = count($k) == 2 ? $k[1] : $k[0];
505
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
501
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
506 502
         }
507 503
         return $this;
508 504
     }
@@ -515,7 +511,7 @@  discard block
 block discarded – undo
515 511
     public function where(string $sql, array $params = []) : self
516 512
     {
517 513
         $this->qiterator = null;
518
-        $this->where[] = [ $sql, $params ];
514
+        $this->where[] = [$sql, $params];
519 515
         return $this;
520 516
     }
521 517
     /**
@@ -527,7 +523,7 @@  discard block
 block discarded – undo
527 523
     public function having(string $sql, array $params = []) : self
528 524
     {
529 525
         $this->qiterator = null;
530
-        $this->having[] = [ $sql, $params ];
526
+        $this->having[] = [$sql, $params];
531 527
         return $this;
532 528
     }
533 529
     /**
@@ -547,12 +543,12 @@  discard block
 block discarded – undo
547 543
                     throw new \Exception();
548 544
                 }
549 545
                 $name = $this->getColumn(trim($name))['name'];
550
-                $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
546
+                $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
551 547
             } catch (\Exception $e) {
552 548
                 $name = null;
553 549
             }
554 550
         }
555
-        $this->order = [ $sql, $params, $name ];
551
+        $this->order = [$sql, $params, $name];
556 552
         return $this;
557 553
     }
558 554
     /**
@@ -564,7 +560,7 @@  discard block
 block discarded – undo
564 560
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
565 561
     {
566 562
         $this->qiterator = null;
567
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
563
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
568 564
         return $this;
569 565
     }
570 566
     /**
@@ -575,9 +571,9 @@  discard block
 block discarded – undo
575 571
     {
576 572
         $aliases = [];
577 573
         $aliases_ext = [];
578
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
574
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
579 575
             // to bypass use: return $name;
580
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
576
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
581 577
             $temp = explode(static::SEP, $name);
582 578
             $temp = $temp[count($temp) - 1];
583 579
             if (!isset($aliases[$temp])) {
@@ -597,7 +593,7 @@  discard block
 block discarded – undo
597 593
         $h = $this->having;
598 594
         $o = $this->order;
599 595
         $g = $this->group;
600
-        $j = array_map(function ($v) {
596
+        $j = array_map(function($v) {
601 597
             return clone $v;
602 598
         }, $this->joins);
603 599
 
@@ -607,28 +603,28 @@  discard block
 block discarded – undo
607 603
                 continue;
608 604
             }
609 605
             foreach ($w as $kk => $v) {
610
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
606
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
611 607
                     $used_relations[] = $k;
612
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
608
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
613 609
                 }
614 610
             }
615 611
             foreach ($h as $kk => $v) {
616
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
612
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
617 613
                     $used_relations[] = $k;
618
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
614
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
619 615
                 }
620 616
             }
621
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
617
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
622 618
                 $used_relations[] = $k;
623
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
619
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
624 620
             }
625 621
             foreach ($j as $kk => $v) {
626 622
                 foreach ($v->keymap as $kkk => $vv) {
627
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
623
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
628 624
                         $used_relations[] = $k;
629 625
                         $j[$kk]->keymap[$kkk] = preg_replace(
630
-                            '(\b'.preg_quote($k . '.'). ')i',
631
-                            $getAlias($k) . '.',
626
+                            '(\b'.preg_quote($k.'.').')i',
627
+                            $getAlias($k).'.',
632 628
                             $vv
633 629
                         );
634 630
                     }
@@ -637,65 +633,65 @@  discard block
 block discarded – undo
637 633
         }
638 634
         foreach ($this->definition->getRelations() as $k => $v) {
639 635
             foreach ($w as $kk => $vv) {
640
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
641
-                    $relations[$k] = [ $v, $table ];
636
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
637
+                    $relations[$k] = [$v, $table];
642 638
                     $used_relations[] = $k;
643
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
639
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
644 640
                 }
645 641
             }
646
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
647
-                $relations[$k] = [ $v, $table ];
642
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
643
+                $relations[$k] = [$v, $table];
648 644
             }
649 645
             foreach ($h as $kk => $vv) {
650
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
651
-                    $relations[$k] = [ $v, $table ];
646
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
647
+                    $relations[$k] = [$v, $table];
652 648
                     $used_relations[] = $k;
653
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
649
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
654 650
                 }
655 651
             }
656
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
657
-                $relations[$k] = [ $v, $table ];
652
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
653
+                $relations[$k] = [$v, $table];
658 654
                 $used_relations[] = $k;
659
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
655
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
660 656
             }
661 657
             foreach ($j as $kk => $vv) {
662 658
                 foreach ($vv->keymap as $kkk => $vvv) {
663
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
664
-                        $relations[$k] = [ $v, $table ];
659
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
660
+                        $relations[$k] = [$v, $table];
665 661
                         $used_relations[] = $k;
666 662
                         $j[$kk]->keymap[$kkk] =
667
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
663
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
668 664
                     }
669 665
                 }
670 666
             }
671 667
         }
672 668
         foreach ($aliases_ext as $k => $alias) {
673 669
             foreach ($w as $kk => $v) {
674
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
675
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
670
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
671
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
676 672
                     $used_relations[] = $k;
677 673
                 }
678 674
             }
679 675
             foreach ($h as $kk => $v) {
680
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
681
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
676
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
677
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
682 678
                     $used_relations[] = $k;
683 679
                 }
684 680
             }
685
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
681
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
686 682
                 $used_relations[] = $k;
687 683
             }
688
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
689
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
684
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
685
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
690 686
                 $used_relations[] = $k;
691 687
             }
692 688
             foreach ($j as $kk => $v) {
693 689
                 foreach ($v->keymap as $kkk => $vv) {
694
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
690
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
695 691
                         $used_relations[] = $k;
696 692
                         $j[$kk]->keymap[$kkk] = preg_replace(
697
-                            '(\b'.preg_quote($k . '.'). ')i',
698
-                            $alias . '.',
693
+                            '(\b'.preg_quote($k.'.').')i',
694
+                            $alias.'.',
699 695
                             $vv
700 696
                         );
701 697
                     }
@@ -713,13 +709,13 @@  discard block
 block discarded – undo
713 709
                     foreach ($v->keymap as $kk => $vv) {
714 710
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
715 711
                     }
716
-                    $sql .= implode(' AND ', $tmp) . ' ';
712
+                    $sql .= implode(' AND ', $tmp).' ';
717 713
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
718 714
                     $tmp = [];
719 715
                     foreach ($v->pivot_keymap as $kk => $vv) {
720 716
                         $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
721 717
                     }
722
-                    $sql .= implode(' AND ', $tmp) . ' ';
718
+                    $sql .= implode(' AND ', $tmp).' ';
723 719
                 } else {
724 720
                     $alias = $getAlias($k);
725 721
                     $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -728,19 +724,19 @@  discard block
 block discarded – undo
728 724
                         $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
729 725
                     }
730 726
                     if ($v->sql) {
731
-                        $tmp[] = $v->sql . ' ';
727
+                        $tmp[] = $v->sql.' ';
732 728
                         $par = array_merge($par, $v->par ?? []);
733 729
                     }
734
-                    $sql .= implode(' AND ', $tmp) . ' ';
730
+                    $sql .= implode(' AND ', $tmp).' ';
735 731
                 }
736 732
             }
737 733
             foreach ($j as $k => $v) {
738
-                $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
734
+                $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
739 735
                 $tmp = [];
740 736
                 foreach ($v->keymap as $kk => $vv) {
741 737
                     $tmp[] = $kk.' = '.$vv;
742 738
                 }
743
-                $sql .= implode(' AND ', $tmp) . ' ';
739
+                $sql .= implode(' AND ', $tmp).' ';
744 740
             }
745 741
         } else {
746 742
             $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql);
@@ -749,20 +745,20 @@  discard block
 block discarded – undo
749 745
             $sql .= 'WHERE ';
750 746
             $tmp = [];
751 747
             foreach ($w as $v) {
752
-                $tmp[] = '(' . $v[0] . ')';
748
+                $tmp[] = '('.$v[0].')';
753 749
                 $par = array_merge($par, $v[1]);
754 750
             }
755 751
             $sql .= implode(' AND ', $tmp).' ';
756 752
         }
757 753
         if (count($g)) {
758
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
754
+            $sql .= 'GROUP BY '.$g[0].' ';
759 755
             $par = array_merge($par, $g[1]);
760 756
         }
761 757
         if (count($h)) {
762 758
             $sql .= 'HAVING ';
763 759
             $tmp = [];
764 760
             foreach ($h as $v) {
765
-                $tmp[] = '(' . $v[0] . ')';
761
+                $tmp[] = '('.$v[0].')';
766 762
                 $par = array_merge($par, $v[1]);
767 763
             }
768 764
             $sql .= implode(' AND ', $tmp).' ';
@@ -796,7 +792,7 @@  discard block
 block discarded – undo
796 792
                     $this->with(implode('.', $temp));
797 793
                     $table = array_reduce(
798 794
                         $temp,
799
-                        function ($carry, $item) use (&$table) {
795
+                        function($carry, $item) use (&$table) {
800 796
                             return $table->getRelation($item)->table;
801 797
                         }
802 798
                     );
@@ -805,7 +801,7 @@  discard block
 block discarded – undo
805 801
                 }
806 802
                 unset($fields[$k]);
807 803
                 foreach ($cols as $col) {
808
-                    $fields[] = $table . '.' . $col;
804
+                    $fields[] = $table.'.'.$col;
809 805
                 }
810 806
             }
811 807
         }
@@ -840,9 +836,9 @@  discard block
 block discarded – undo
840 836
         }
841 837
         $aliases = [];
842 838
         $aliases_ext = [];
843
-        $getAlias = function ($name) use (&$aliases, &$aliases_ext) {
839
+        $getAlias = function($name) use (&$aliases, &$aliases_ext) {
844 840
             // to bypass use: return $name;
845
-            $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
841
+            $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
846 842
             $temp = explode(static::SEP, $name);
847 843
             $temp = $temp[count($temp) - 1];
848 844
             if (!isset($aliases[$temp])) {
@@ -864,7 +860,7 @@  discard block
 block discarded – undo
864 860
         $h = $this->having;
865 861
         $o = $this->order;
866 862
         $g = $this->group;
867
-        $j = array_map(function ($v) {
863
+        $j = array_map(function($v) {
868 864
             return clone $v;
869 865
         }, $this->joins);
870 866
 
@@ -878,32 +874,32 @@  discard block
 block discarded – undo
878 874
                 continue;
879 875
             }
880 876
             foreach ($f as $kk => $field) {
881
-                if (strpos($field, $k . '.') === 0) {
882
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
877
+                if (strpos($field, $k.'.') === 0) {
878
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
883 879
                 }
884 880
             }
885 881
             foreach ($w as $kk => $v) {
886
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
887
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
882
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
883
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
888 884
                 }
889 885
             }
890 886
             foreach ($h as $kk => $v) {
891
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
892
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
887
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
888
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
893 889
                 }
894 890
             }
895
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
896
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
891
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
892
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
897 893
             }
898
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
899
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
894
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
895
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
900 896
             }
901 897
             foreach ($j as $kk => $v) {
902 898
                 foreach ($v->keymap as $kkk => $vv) {
903
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
899
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
904 900
                         $j[$kk]->keymap[$kkk] = preg_replace(
905
-                            '(\b'.preg_quote($k . '.'). ')i',
906
-                            $getAlias($k) . '.',
901
+                            '(\b'.preg_quote($k.'.').')i',
902
+                            $getAlias($k).'.',
907 903
                             $vv
908 904
                         );
909 905
                     }
@@ -912,38 +908,38 @@  discard block
 block discarded – undo
912 908
         }
913 909
         foreach ($this->definition->getRelations() as $k => $relation) {
914 910
             foreach ($f as $kk => $field) {
915
-                if (strpos($field, $k . '.') === 0) {
916
-                    $relations[$k] = [ $relation, $table ];
917
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
911
+                if (strpos($field, $k.'.') === 0) {
912
+                    $relations[$k] = [$relation, $table];
913
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
918 914
                 }
919 915
             }
920 916
             foreach ($w as $kk => $v) {
921
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
922
-                    $relations[$k] = [ $relation, $table ];
923
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
917
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
918
+                    $relations[$k] = [$relation, $table];
919
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
924 920
                 }
925 921
             }
926 922
             foreach ($h as $kk => $v) {
927
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
928
-                    $relations[$k] = [ $relation, $table ];
929
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
923
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
924
+                    $relations[$k] = [$relation, $table];
925
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
930 926
                 }
931 927
             }
932
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
933
-                $relations[$k] = [ $relation, $table ];
934
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
928
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
929
+                $relations[$k] = [$relation, $table];
930
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
935 931
             }
936
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
937
-                $relations[$k] = [ $relation, $table ];
938
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
932
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
933
+                $relations[$k] = [$relation, $table];
934
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
939 935
             }
940 936
             foreach ($j as $kk => $v) {
941 937
                 foreach ($v->keymap as $kkk => $vv) {
942
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
943
-                        $relations[$k] = [ $relation, $table ];
938
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
939
+                        $relations[$k] = [$relation, $table];
944 940
                         $j[$kk]->keymap[$kkk] = preg_replace(
945
-                            '(\b'.preg_quote($k . '.'). ')i',
946
-                            $getAlias($k) . '.',
941
+                            '(\b'.preg_quote($k.'.').')i',
942
+                            $getAlias($k).'.',
947 943
                             $vv
948 944
                         );
949 945
                     }
@@ -952,32 +948,32 @@  discard block
 block discarded – undo
952 948
         }
953 949
         foreach ($aliases_ext as $k => $alias) {
954 950
             foreach ($f as $kk => $field) {
955
-                if (strpos($field, $k . '.') === 0) {
956
-                    $f[$kk] = str_replace($k . '.', $alias . '.', $field);
951
+                if (strpos($field, $k.'.') === 0) {
952
+                    $f[$kk] = str_replace($k.'.', $alias.'.', $field);
957 953
                 }
958 954
             }
959 955
             foreach ($w as $kk => $v) {
960
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
961
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
956
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
957
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
962 958
                 }
963 959
             }
964 960
             foreach ($h as $kk => $v) {
965
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
966
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]);
961
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
962
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]);
967 963
                 }
968 964
             }
969
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
970
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]);
965
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
966
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]);
971 967
             }
972
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
973
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]);
968
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
969
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]);
974 970
             }
975 971
             foreach ($j as $kk => $v) {
976 972
                 foreach ($v->keymap as $kkk => $vv) {
977
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
973
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
978 974
                         $j[$kk]->keymap[$kkk] = preg_replace(
979
-                            '(\b'.preg_quote($k . '.'). ')i',
980
-                            $alias . '.',
975
+                            '(\b'.preg_quote($k.'.').')i',
976
+                            $alias.'.',
981 977
                             $vv
982 978
                         );
983 979
                     }
@@ -986,12 +982,12 @@  discard block
 block discarded – undo
986 982
         }
987 983
         $select = [];
988 984
         foreach ($f as $k => $field) {
989
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
985
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
990 986
         }
991 987
         foreach ($this->withr as $name => $relation) {
992 988
             if ($relation[2]) {
993 989
                 foreach ($relation[0]->table->getColumns() as $column) {
994
-                    $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
990
+                    $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
995 991
                 }
996 992
             }
997 993
         }
@@ -1011,13 +1007,13 @@  discard block
 block discarded – undo
1011 1007
                 foreach ($v->keymap as $kk => $vv) {
1012 1008
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1013 1009
                 }
1014
-                $sql .= implode(' AND ', $tmp) . ' ';
1010
+                $sql .= implode(' AND ', $tmp).' ';
1015 1011
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
1016 1012
                 $tmp = [];
1017 1013
                 foreach ($v->pivot_keymap as $kk => $vv) {
1018 1014
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1019 1015
                 }
1020
-                $sql .= implode(' AND ', $tmp) . ' ';
1016
+                $sql .= implode(' AND ', $tmp).' ';
1021 1017
             } else {
1022 1018
                 $alias = $getAlias($relation);
1023 1019
 
@@ -1027,22 +1023,22 @@  discard block
 block discarded – undo
1027 1023
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1028 1024
                 }
1029 1025
                 if ($v->sql) {
1030
-                    $tmp[] = $v->sql . ' ';
1026
+                    $tmp[] = $v->sql.' ';
1031 1027
                     $par = array_merge($par, $v->par ?? []);
1032 1028
                 }
1033
-                $sql .= implode(' AND ', $tmp) . ' ';
1029
+                $sql .= implode(' AND ', $tmp).' ';
1034 1030
             }
1035 1031
         }
1036 1032
         foreach ($j as $k => $v) {
1037 1033
             if ($v->many) {
1038 1034
                 $many = true;
1039 1035
             }
1040
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1036
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1041 1037
             $tmp = [];
1042 1038
             foreach ($v->keymap as $kk => $vv) {
1043 1039
                 $tmp[] = $kk.' = '.$vv;
1044 1040
             }
1045
-            $sql .= implode(' AND ', $tmp) . ' ';
1041
+            $sql .= implode(' AND ', $tmp).' ';
1046 1042
         }
1047 1043
         if ($many && count($porder) && $this->li_of[2] === 1) {
1048 1044
             $ids = $this->ids();
@@ -1050,9 +1046,9 @@  discard block
 block discarded – undo
1050 1046
                 if (count($porder) > 1) {
1051 1047
                     $pkw = [];
1052 1048
                     foreach ($porder as $name) {
1053
-                        $pkw[] = $name . ' = ?';
1049
+                        $pkw[] = $name.' = ?';
1054 1050
                     }
1055
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
1051
+                    $pkw = '('.implode(' AND ', $pkw).')';
1056 1052
                     $pkp = [];
1057 1053
                     foreach ($ids as $id) {
1058 1054
                         foreach ($id as $p) {
@@ -1064,60 +1060,60 @@  discard block
 block discarded – undo
1064 1060
                         $pkp
1065 1061
                     ];
1066 1062
                 } else {
1067
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
1063
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
1068 1064
                 }
1069 1065
             } else {
1070
-                $w[] = [ '1=0', [] ];
1066
+                $w[] = ['1=0', []];
1071 1067
             }
1072 1068
         }
1073 1069
         if (count($w)) {
1074 1070
             $sql .= 'WHERE ';
1075 1071
             $tmp = [];
1076 1072
             foreach ($w as $v) {
1077
-                $tmp[] = '(' . $v[0] . ')';
1073
+                $tmp[] = '('.$v[0].')';
1078 1074
                 $par = array_merge($par, $v[1]);
1079 1075
             }
1080 1076
             $sql .= implode(' AND ', $tmp).' ';
1081 1077
         }
1082 1078
         if (count($g)) {
1083
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1079
+            $sql .= 'GROUP BY '.$g[0].' ';
1084 1080
             $par = array_merge($par, $g[1]);
1085 1081
         }
1086 1082
         if (count($h)) {
1087 1083
             $sql .= 'HAVING ';
1088 1084
             $tmp = [];
1089 1085
             foreach ($h as $v) {
1090
-                $tmp[] = '(' . $v[0] . ')';
1086
+                $tmp[] = '('.$v[0].')';
1091 1087
                 $par = array_merge($par, $v[1]);
1092 1088
             }
1093 1089
             $sql .= implode(' AND ', $tmp).' ';
1094 1090
         }
1095 1091
         $ordered = false;
1096 1092
         if (count($o)) {
1097
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1093
+            $sql .= 'ORDER BY '.$o[0].' ';
1098 1094
             $par = array_merge($par, $o[1]);
1099 1095
             $ordered = true;
1100 1096
         }
1101 1097
         if (!count($g) && count($porder)) {
1102 1098
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1103
-            $porder = array_map(function ($v) use ($pdir) {
1104
-                return $v . ' ' . $pdir;
1099
+            $porder = array_map(function($v) use ($pdir) {
1100
+                return $v.' '.$pdir;
1105 1101
             }, $porder);
1106
-            $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1102
+            $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1107 1103
             $ordered = true;
1108 1104
         }
1109 1105
         foreach ($this->withr as $k => $v) {
1110 1106
             if (isset($v[3])) {
1111
-                $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC');
1107
+                $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC');
1112 1108
                 $ordered = true;
1113 1109
             }
1114 1110
         }
1115 1111
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
1116 1112
             if ($this->db->driverName() === 'oracle') {
1117
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1118
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1113
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1114
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1119 1115
                 } else {
1120
-                    $f = array_map(function ($v) {
1116
+                    $f = array_map(function($v) {
1121 1117
                         $v = explode(' ', trim($v), 2);
1122 1118
                         if (count($v) === 2) {
1123 1119
                             return $v[1];
@@ -1125,16 +1121,16 @@  discard block
 block discarded – undo
1125 1121
                         $v = explode('.', $v[0], 2);
1126 1122
                         return count($v) === 2 ? $v[1] : $v[0];
1127 1123
                     }, $select);
1128
-                    $sql = "SELECT " . implode(', ', $f) . " 
1124
+                    $sql = "SELECT ".implode(', ', $f)." 
1129 1125
                             FROM (
1130 1126
                                 SELECT tbl__.*, rownum rnum__ FROM (
1131
-                                    " . $sql . "
1127
+                                    " . $sql."
1132 1128
                                 ) tbl__ 
1133
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1129
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1134 1130
                             ) WHERE rnum__ > " . $this->li_of[1];
1135 1131
                 }
1136 1132
             } else {
1137
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1133
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1138 1134
             }
1139 1135
         }
1140 1136
         return $this->qiterator = new TableQueryIterator(
@@ -1184,12 +1180,12 @@  discard block
 block discarded – undo
1184 1180
                 $ret[$k] = str_repeat(' ', 255);
1185 1181
                 $par[] = &$ret[$k];
1186 1182
             }
1187
-            $sql .= ' RETURNING ' . implode(',', $primary) .
1188
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
1183
+            $sql .= ' RETURNING '.implode(',', $primary).
1184
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
1189 1185
             $this->db->query($sql, $par);
1190 1186
             return $ret;
1191 1187
         } elseif ($this->db->driverName() === 'postgre') {
1192
-            $sql .= ' RETURNING ' . implode(',', $primary);
1188
+            $sql .= ' RETURNING '.implode(',', $primary);
1193 1189
             return $this->db->one($sql, $par, false);
1194 1190
         } else {
1195 1191
             $ret = [];
@@ -1220,9 +1216,9 @@  discard block
 block discarded – undo
1220 1216
         }
1221 1217
         $sql = 'UPDATE '.$table.' SET ';
1222 1218
         $par = [];
1223
-        $sql .= implode(', ', array_map(function ($v) {
1224
-            return $v . ' = ?';
1225
-        }, array_keys($update))) . ' ';
1219
+        $sql .= implode(', ', array_map(function($v) {
1220
+            return $v.' = ?';
1221
+        }, array_keys($update))).' ';
1226 1222
         $par = array_merge($par, array_values($update));
1227 1223
         if (count($this->where)) {
1228 1224
             $sql .= 'WHERE ';
@@ -1231,7 +1227,7 @@  discard block
 block discarded – undo
1231 1227
                 $tmp[] = $v[0];
1232 1228
                 $par = array_merge($par, $v[1]);
1233 1229
             }
1234
-            $sql .= implode(' AND ', $tmp) . ' ';
1230
+            $sql .= implode(' AND ', $tmp).' ';
1235 1231
         }
1236 1232
         if (count($this->order)) {
1237 1233
             $sql .= $this->order[0];
@@ -1255,7 +1251,7 @@  discard block
 block discarded – undo
1255 1251
                 $tmp[] = $v[0];
1256 1252
                 $par = array_merge($par, $v[1]);
1257 1253
             }
1258
-            $sql .= implode(' AND ', $tmp) . ' ';
1254
+            $sql .= implode(' AND ', $tmp).' ';
1259 1255
         }
1260 1256
         if (count($this->order)) {
1261 1257
             $sql .= $this->order[0];
@@ -1274,18 +1270,18 @@  discard block
 block discarded – undo
1274 1270
         $table = $this->definition;
1275 1271
         if ($table->hasRelation($relation)) {
1276 1272
             $temp = $table->getRelation($relation);
1277
-            $this->withr[$relation] = [ $temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc ];
1273
+            $this->withr[$relation] = [$temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc];
1278 1274
         } else {
1279 1275
             $parts = explode('.', $relation);
1280 1276
             try {
1281 1277
                 $name = array_reduce(
1282 1278
                     $parts,
1283
-                    function ($carry, $item) use (&$table, $select) {
1279
+                    function($carry, $item) use (&$table, $select) {
1284 1280
                         if (!$table->hasRelation($item)) {
1285
-                            throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1281
+                            throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1286 1282
                         }
1287 1283
                         $relation = $table->getRelation($item);
1288
-                        $name = $carry ? $carry . static::SEP . $item : $item;
1284
+                        $name = $carry ? $carry.static::SEP.$item : $item;
1289 1285
                         $this->withr[$name] = [
1290 1286
                             $relation,
1291 1287
                             $carry ?? $table->getName(),
@@ -1349,9 +1345,9 @@  discard block
 block discarded – undo
1349 1345
         }
1350 1346
 
1351 1347
         $aliases = [];
1352
-        $getAlias = function ($name) use (&$aliases) {
1348
+        $getAlias = function($name) use (&$aliases) {
1353 1349
             // to bypass use: return $name;
1354
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1350
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1355 1351
         };
1356 1352
         
1357 1353
         $table = $this->definition->getName();
@@ -1363,65 +1359,65 @@  discard block
 block discarded – undo
1363 1359
         $h = $this->having;
1364 1360
         $o = $this->order;
1365 1361
         $g = $this->group;
1366
-        $j = array_map(function ($v) {
1362
+        $j = array_map(function($v) {
1367 1363
             return clone $v;
1368 1364
         }, $this->joins);
1369 1365
         foreach ($this->definition->getRelations() as $k => $v) {
1370 1366
             foreach ($w as $kk => $vv) {
1371
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1372
-                    $relations[$k] = [ $v, $table ];
1373
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1367
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1368
+                    $relations[$k] = [$v, $table];
1369
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1374 1370
                 }
1375 1371
             }
1376
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1377
-                $relations[$k] = [ $v, $table ];
1378
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1379
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1372
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1373
+                $relations[$k] = [$v, $table];
1374
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1375
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1380 1376
             }
1381 1377
             foreach ($h as $kk => $vv) {
1382
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1383
-                    $relations[$k] = [ $v, $table ];
1384
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1378
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1379
+                    $relations[$k] = [$v, $table];
1380
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1385 1381
                 }
1386 1382
             }
1387
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1388
-                $relations[$k] = [ $v, $table ];
1389
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1383
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1384
+                $relations[$k] = [$v, $table];
1385
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1390 1386
             }
1391 1387
             foreach ($j as $kk => $vv) {
1392 1388
                 foreach ($vv->keymap as $kkk => $vvv) {
1393
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1394
-                        $relations[$k] = [ $v, $table ];
1389
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1390
+                        $relations[$k] = [$v, $table];
1395 1391
                         $j[$kk]->keymap[$kkk] =
1396
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1392
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1397 1393
                     }
1398 1394
                 }
1399 1395
             }
1400 1396
         }
1401 1397
 
1402
-        $key = array_map(function ($v) use ($table) {
1403
-            return $table . '.' . $v;
1398
+        $key = array_map(function($v) use ($table) {
1399
+            return $table.'.'.$v;
1404 1400
         }, $this->pkey);
1405 1401
         $own = false;
1406 1402
         $dir = 'ASC';
1407 1403
         if (count($o)) {
1408 1404
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1409
-            $own = strpos($o[2], $table . '.') === 0;
1405
+            $own = strpos($o[2], $table.'.') === 0;
1410 1406
         }
1411 1407
 
1412 1408
         $dst = $key;
1413 1409
         if (count($o)) {
1414 1410
             if ($own) {
1415 1411
                 // if using own table - do not use max/min in order - that will prevent index usage
1416
-                $dst[] = $o[2] . ' orderbyfix___';
1412
+                $dst[] = $o[2].' orderbyfix___';
1417 1413
             } else {
1418
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1414
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1419 1415
             }
1420 1416
         }
1421 1417
         $dst = array_unique($dst);
1422 1418
 
1423 1419
         $par = [];
1424
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1420
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1425 1421
         foreach ($relations as $k => $v) {
1426 1422
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1427 1423
             $v = $v[0];
@@ -1432,13 +1428,13 @@  discard block
 block discarded – undo
1432 1428
                 foreach ($v->keymap as $kk => $vv) {
1433 1429
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1434 1430
                 }
1435
-                $sql .= implode(' AND ', $tmp) . ' ';
1431
+                $sql .= implode(' AND ', $tmp).' ';
1436 1432
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1437 1433
                 $tmp = [];
1438 1434
                 foreach ($v->pivot_keymap as $kk => $vv) {
1439 1435
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1440 1436
                 }
1441
-                $sql .= implode(' AND ', $tmp) . ' ';
1437
+                $sql .= implode(' AND ', $tmp).' ';
1442 1438
             } else {
1443 1439
                 $alias = $getAlias($k);
1444 1440
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1447,37 +1443,37 @@  discard block
 block discarded – undo
1447 1443
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1448 1444
                 }
1449 1445
                 if ($v->sql) {
1450
-                    $tmp[] = $v->sql . ' ';
1446
+                    $tmp[] = $v->sql.' ';
1451 1447
                     $par = array_merge($par, $v->par ?? []);
1452 1448
                 }
1453
-                $sql .= implode(' AND ', $tmp) . ' ';
1449
+                $sql .= implode(' AND ', $tmp).' ';
1454 1450
             }
1455 1451
         }
1456 1452
         foreach ($j as $k => $v) {
1457
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1453
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1458 1454
             $tmp = [];
1459 1455
             foreach ($v->keymap as $kk => $vv) {
1460 1456
                 $tmp[] = $kk.' = '.$vv;
1461 1457
             }
1462
-            $sql .= implode(' AND ', $tmp) . ' ';
1458
+            $sql .= implode(' AND ', $tmp).' ';
1463 1459
         }
1464 1460
         if (count($w)) {
1465 1461
             $sql .= 'WHERE ';
1466 1462
             $tmp = [];
1467 1463
             foreach ($w as $v) {
1468
-                $tmp[] = '(' . $v[0] . ')';
1464
+                $tmp[] = '('.$v[0].')';
1469 1465
                 $par = array_merge($par, $v[1]);
1470 1466
             }
1471 1467
             $sql .= implode(' AND ', $tmp).' ';
1472 1468
         }
1473 1469
         if (!$own) {
1474
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1470
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1475 1471
         }
1476 1472
         if (count($h)) {
1477 1473
             $sql .= 'HAVING ';
1478 1474
             $tmp = [];
1479 1475
             foreach ($h as $v) {
1480
-                $tmp[] = '(' . $v[0] . ')';
1476
+                $tmp[] = '('.$v[0].')';
1481 1477
                 $par = array_merge($par, $v[1]);
1482 1478
             }
1483 1479
             $sql .= implode(' AND ', $tmp).' ';
@@ -1485,38 +1481,38 @@  discard block
 block discarded – undo
1485 1481
         if (count($o)) {
1486 1482
             $sql .= 'ORDER BY ';
1487 1483
             if ($own) {
1488
-                $sql .= $o[2] . ' ' . $dir;
1484
+                $sql .= $o[2].' '.$dir;
1489 1485
             } else {
1490
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1486
+                $sql .= 'MAX('.$o[2].') '.$dir;
1491 1487
             }
1492 1488
         }
1493 1489
         $porder = [];
1494 1490
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1495 1491
         foreach ($this->definition->getPrimaryKey() as $field) {
1496
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1492
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1497 1493
         }
1498 1494
         if (count($porder)) {
1499
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1495
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1500 1496
         }
1501 1497
 
1502 1498
         if ($this->li_of[0]) {
1503 1499
             if ($this->db->driverName() === 'oracle') {
1504
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1505
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1500
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1501
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1506 1502
                 } else {
1507
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1503
+                    $sql = "SELECT ".implode(', ', $dst)." 
1508 1504
                             FROM (
1509 1505
                                 SELECT tbl__.*, rownum rnum__ FROM (
1510
-                                    " . $sql . "
1506
+                                    " . $sql."
1511 1507
                                 ) tbl__ 
1512
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1508
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1513 1509
                             ) WHERE rnum__ > " . $this->li_of[1];
1514 1510
                 }
1515 1511
             } else {
1516
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1512
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1517 1513
             }
1518 1514
         }
1519
-        return array_map(function ($v) {
1515
+        return array_map(function($v) {
1520 1516
             if (array_key_exists('orderbyfix___', $v)) {
1521 1517
                 unset($v['orderbyfix___']);
1522 1518
             }
Please login to merge, or discard this patch.