Completed
Push — master ( 740836...6931a9 )
by Ivan
01:50
created
src/schema/TableQuery.php 1 patch
Spacing   +89 added lines, -92 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     /**
44 44
      * @var int[]
45 45
      */
46
-    protected $li_of = [0,0];
46
+    protected $li_of = [0, 0];
47 47
     /**
48 48
      * @var array
49 49
      */
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     public function __construct(DBInterface $db, $table)
74 74
     {
75 75
         $this->db = $db;
76
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
76
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
77 77
         $primary = $this->definition->getPrimaryKey();
78 78
         $columns = $this->definition->getColumns();
79 79
         $this->pkey = count($primary) ? $primary : $columns;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         $column = explode('.', $column);
98 98
         if (count($column) === 1) {
99
-            $column = [ $this->definition->getName(), $column[0] ];
99
+            $column = [$this->definition->getName(), $column[0]];
100 100
             $col = $this->definition->getColumn($column[1]);
101 101
             if (!$col) {
102 102
                 throw new DBException('Invalid column name in own table');
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                         throw new DBException('Invalid column name in related table');
120 120
                     }
121 121
                 } else {
122
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
122
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
123 123
                 }
124 124
             }
125 125
         } else {
@@ -128,15 +128,15 @@  discard block
 block discarded – undo
128 128
             $table = $this->definition;
129 129
             $table = array_reduce(
130 130
                 $column,
131
-                function ($carry, $item) use (&$table) {
131
+                function($carry, $item) use (&$table) {
132 132
                     $table = $table->getRelation($item)->table;
133 133
                     return $table;
134 134
                 }
135 135
             );
136 136
             $col = $table->getColumn($name);
137
-            $column = [ implode(static::SEP, $column), $name ];
137
+            $column = [implode(static::SEP, $column), $name];
138 138
         }
139
-        return [ 'name' => implode('.', $column), 'data' => $col ];
139
+        return ['name' => implode('.', $column), 'data' => $col];
140 140
     }
141 141
     protected function normalizeValue(TableColumn $col, $value)
142 142
     {
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
                 }
184 184
                 return $value;
185 185
             case 'int':
186
-                return (int)$value;
186
+                return (int) $value;
187 187
             default:
188 188
                 return $value;
189 189
         }
@@ -201,18 +201,16 @@  discard block
 block discarded – undo
201 201
         list($name, $column) = array_values($this->getColumn($column));
202 202
         if (is_null($value)) {
203 203
             return $negate ?
204
-                $this->where($name . ' IS NOT NULL') :
205
-                $this->where($name . ' IS NULL');
204
+                $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL');
206 205
         }
207 206
         if (!is_array($value)) {
208 207
             return $negate ?
209 208
                 $this->where(
210
-                    $name . ' <> ?',
211
-                    [ $this->normalizeValue($column, $value) ]
212
-                ) :
213
-                $this->where(
214
-                    $name . ' = ?',
215
-                    [ $this->normalizeValue($column, $value) ]
209
+                    $name.' <> ?',
210
+                    [$this->normalizeValue($column, $value)]
211
+                ) : $this->where(
212
+                    $name.' = ?',
213
+                    [$this->normalizeValue($column, $value)]
216 214
                 );
217 215
         }
218 216
         if (isset($value['beg']) && isset($value['end'])) {
@@ -223,8 +221,7 @@  discard block
 block discarded – undo
223 221
                         $this->normalizeValue($column, $value['beg']),
224 222
                         $this->normalizeValue($column, $value['end'])
225 223
                     ]
226
-                ) :
227
-                $this->where(
224
+                ) : $this->where(
228 225
                     $name.' BETWEEN ? AND ?',
229 226
                     [
230 227
                         $this->normalizeValue($column, $value['beg']),
@@ -235,38 +232,38 @@  discard block
 block discarded – undo
235 232
         if (isset($value['gt']) || isset($value['lt']) || isset($value['gte']) || isset($value['lte'])) {
236 233
             if (isset($value['gt'])) {
237 234
                 $this->where(
238
-                    $name. ' ' . ($negate ? '<=' : '>') . ' ?',
239
-                    [ $this->normalizeValue($column, $value['gt']) ]
235
+                    $name.' '.($negate ? '<=' : '>').' ?',
236
+                    [$this->normalizeValue($column, $value['gt'])]
240 237
                 );
241 238
             }
242 239
             if (isset($value['gte'])) {
243 240
                 $this->where(
244
-                    $name. ' ' . ($negate ? '<' : '>=') . ' ?',
245
-                    [ $this->normalizeValue($column, $value['gte']) ]
241
+                    $name.' '.($negate ? '<' : '>=').' ?',
242
+                    [$this->normalizeValue($column, $value['gte'])]
246 243
                 );
247 244
             }
248 245
             if (isset($value['lt'])) {
249 246
                 $this->where(
250
-                    $name. ' ' . ($negate ? '>=' : '<') . ' ?',
251
-                    [ $this->normalizeValue($column, $value['lt']) ]
247
+                    $name.' '.($negate ? '>=' : '<').' ?',
248
+                    [$this->normalizeValue($column, $value['lt'])]
252 249
                 );
253 250
             }
254 251
             if (isset($value['lte'])) {
255 252
                 $this->where(
256
-                    $name. ' ' . ($negate ? '>' : '<=') . ' ?',
257
-                    [ $this->normalizeValue($column, $value['lte']) ]
253
+                    $name.' '.($negate ? '>' : '<=').' ?',
254
+                    [$this->normalizeValue($column, $value['lte'])]
258 255
                 );
259 256
             }
260 257
             return $this;
261 258
         }
262 259
         return $negate ?
263 260
             $this->where(
264
-                $name . ' NOT IN (??)',
265
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
261
+                $name.' NOT IN (??)',
262
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
266 263
             ) :
267 264
             $this->where(
268
-                $name . ' IN (??)',
269
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
265
+                $name.' IN (??)',
266
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
270 267
             );
271 268
     }
272 269
     /**
@@ -277,7 +274,7 @@  discard block
 block discarded – undo
277 274
      */
278 275
     public function sort(string $column, bool $desc = false) : TableQuery
279 276
     {
280
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
277
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
281 278
     }
282 279
     /**
283 280
      * Group by a column (or columns)
@@ -287,7 +284,7 @@  discard block
 block discarded – undo
287 284
     public function group($column) : TableQuery
288 285
     {
289 286
         if (!is_array($column)) {
290
-            $column = [ $column ];
287
+            $column = [$column];
291 288
         }
292 289
         foreach ($column as $k => $v) {
293 290
             $column[$k] = $this->getColumn($v)['name'];
@@ -328,7 +325,7 @@  discard block
 block discarded – undo
328 325
         $this->withr = [];
329 326
         $this->order = [];
330 327
         $this->having = [];
331
-        $this->li_of = [0,0];
328
+        $this->li_of = [0, 0];
332 329
         $this->qiterator = null;
333 330
         return $this;
334 331
     }
@@ -341,7 +338,7 @@  discard block
 block discarded – undo
341 338
     public function groupBy(string $sql, array $params = []) : TableQuery
342 339
     {
343 340
         $this->qiterator = null;
344
-        $this->group = [ $sql, $params ];
341
+        $this->group = [$sql, $params];
345 342
         return $this;
346 343
     }
347 344
     /**
@@ -354,7 +351,7 @@  discard block
 block discarded – undo
354 351
      */
355 352
     public function join($table, array $fields, string $name = null, bool $multiple = true)
356 353
     {
357
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
354
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
358 355
         $name = $name ?? $table->getName();
359 356
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
360 357
             throw new DBException('Alias / table name already in use');
@@ -363,7 +360,7 @@  discard block
 block discarded – undo
363 360
         foreach ($fields as $k => $v) {
364 361
             $k = explode('.', $k, 2);
365 362
             $k = count($k) == 2 ? $k[1] : $k[0];
366
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
363
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
367 364
         }
368 365
         return $this;
369 366
     }
@@ -376,7 +373,7 @@  discard block
 block discarded – undo
376 373
     public function where(string $sql, array $params = []) : TableQuery
377 374
     {
378 375
         $this->qiterator = null;
379
-        $this->where[] = [ $sql, $params ];
376
+        $this->where[] = [$sql, $params];
380 377
         return $this;
381 378
     }
382 379
     /**
@@ -388,7 +385,7 @@  discard block
 block discarded – undo
388 385
     public function having(string $sql, array $params = []) : TableQuery
389 386
     {
390 387
         $this->qiterator = null;
391
-        $this->having[] = [ $sql, $params ];
388
+        $this->having[] = [$sql, $params];
392 389
         return $this;
393 390
     }
394 391
     /**
@@ -400,7 +397,7 @@  discard block
 block discarded – undo
400 397
     public function order(string $sql, array $params = []) : TableQuery
401 398
     {
402 399
         $this->qiterator = null;
403
-        $this->order = [ $sql, $params ];
400
+        $this->order = [$sql, $params];
404 401
         return $this;
405 402
     }
406 403
     /**
@@ -412,7 +409,7 @@  discard block
 block discarded – undo
412 409
     public function limit(int $limit, int $offset = 0) : TableQuery
413 410
     {
414 411
         $this->qiterator = null;
415
-        $this->li_of = [ $limit, $offset ];
412
+        $this->li_of = [$limit, $offset];
416 413
         return $this;
417 414
     }
418 415
     /**
@@ -428,22 +425,22 @@  discard block
 block discarded – undo
428 425
         $relations = $this->withr;
429 426
         foreach ($this->definition->getRelations() as $k => $v) {
430 427
             foreach ($this->where as $vv) {
431
-                if (strpos($vv[0], $k . '.') !== false) {
432
-                    $relations[$k] = [ $v, $table ];
428
+                if (strpos($vv[0], $k.'.') !== false) {
429
+                    $relations[$k] = [$v, $table];
433 430
                 }
434 431
             }
435
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
436
-                $relations[$k] = [ $v, $table ];
432
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
433
+                $relations[$k] = [$v, $table];
437 434
             }
438 435
         }
439 436
 
440 437
         foreach ($this->joins as $k => $v) {
441
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
438
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
442 439
             $tmp = [];
443 440
             foreach ($v->keymap as $kk => $vv) {
444 441
                 $tmp[] = $kk.' = '.$vv;
445 442
             }
446
-            $sql .= implode(' AND ', $tmp) . ' ';
443
+            $sql .= implode(' AND ', $tmp).' ';
447 444
         }
448 445
         foreach ($relations as $k => $v) {
449 446
             $table = $v[1];
@@ -454,13 +451,13 @@  discard block
 block discarded – undo
454 451
                 foreach ($v->keymap as $kk => $vv) {
455 452
                     $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' ';
456 453
                 }
457
-                $sql .= implode(' AND ', $tmp) . ' ';
454
+                $sql .= implode(' AND ', $tmp).' ';
458 455
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
459 456
                 $tmp = [];
460 457
                 foreach ($v->pivot_keymap as $kk => $vv) {
461 458
                     $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' ';
462 459
                 }
463
-                $sql .= implode(' AND ', $tmp) . ' ';
460
+                $sql .= implode(' AND ', $tmp).' ';
464 461
             } else {
465 462
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
466 463
                 $tmp = [];
@@ -468,30 +465,30 @@  discard block
 block discarded – undo
468 465
                     $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' ';
469 466
                 }
470 467
                 if ($v->sql) {
471
-                    $tmp[] = $v->sql . ' ';
468
+                    $tmp[] = $v->sql.' ';
472 469
                     $par = array_merge($par, $v->par ?? []);
473 470
                 }
474
-                $sql .= implode(' AND ', $tmp) . ' ';
471
+                $sql .= implode(' AND ', $tmp).' ';
475 472
             }
476 473
         }
477 474
         if (count($this->where)) {
478 475
             $sql .= 'WHERE ';
479 476
             $tmp = [];
480 477
             foreach ($this->where as $v) {
481
-                $tmp[] = '(' . $v[0] . ')';
478
+                $tmp[] = '('.$v[0].')';
482 479
                 $par = array_merge($par, $v[1]);
483 480
             }
484 481
             $sql .= implode(' AND ', $tmp).' ';
485 482
         }
486 483
         if (count($this->group)) {
487
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
484
+            $sql .= 'GROUP BY '.$this->group[0].' ';
488 485
             $par = array_merge($par, $this->group[1]);
489 486
         }
490 487
         if (count($this->having)) {
491 488
             $sql .= 'HAVING ';
492 489
             $tmp = [];
493 490
             foreach ($this->having as $v) {
494
-                $tmp[] = '(' . $v[0] . ')';
491
+                $tmp[] = '('.$v[0].')';
495 492
                 $par = array_merge($par, $v[1]);
496 493
             }
497 494
             $sql .= implode(' AND ', $tmp).' ';
@@ -525,7 +522,7 @@  discard block
 block discarded – undo
525 522
                     $this->with(implode('.', $temp));
526 523
                     $table = array_reduce(
527 524
                         $temp,
528
-                        function ($carry, $item) use (&$table) {
525
+                        function($carry, $item) use (&$table) {
529 526
                             return $table->getRelation($item)->table;
530 527
                         }
531 528
                     );
@@ -534,7 +531,7 @@  discard block
 block discarded – undo
534 531
                 }
535 532
                 unset($fields[$k]);
536 533
                 foreach ($cols as $col) {
537
-                    $fields[] = $table . '.' . $col;
534
+                    $fields[] = $table.'.'.$col;
538 535
                 }
539 536
             }
540 537
         }
@@ -575,40 +572,40 @@  discard block
 block discarded – undo
575 572
         }
576 573
         foreach ($this->definition->getRelations() as $k => $relation) {
577 574
             foreach ($this->fields as $kk => $field) {
578
-                if (strpos($field, $k . '.') === 0) {
579
-                    $relations[$k] = [ $relation, $table ];
580
-                    $this->fields[$kk] = str_replace($k . '.', $this->getAlias($k) . '.', $field);
575
+                if (strpos($field, $k.'.') === 0) {
576
+                    $relations[$k] = [$relation, $table];
577
+                    $this->fields[$kk] = str_replace($k.'.', $this->getAlias($k).'.', $field);
581 578
                 }
582 579
             }
583 580
             foreach ($this->where as $kk => $v) {
584
-                if (strpos($v[0], $k . '.') !== false) {
585
-                    $relations[$k] = [ $relation, $table ];
586
-                    $this->where[$kk] = str_replace($k . '.', $this->getAlias($k) . '.', $v);
581
+                if (strpos($v[0], $k.'.') !== false) {
582
+                    $relations[$k] = [$relation, $table];
583
+                    $this->where[$kk] = str_replace($k.'.', $this->getAlias($k).'.', $v);
587 584
                 }
588 585
             }
589
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
590
-                $relations[$k] = [ $relation, $table ];
591
-                $this->order[0] = str_replace($k . '.', $this->getAlias($k) . '.', $this->order[0]);
586
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
587
+                $relations[$k] = [$relation, $table];
588
+                $this->order[0] = str_replace($k.'.', $this->getAlias($k).'.', $this->order[0]);
592 589
             }
593 590
         }
594 591
         $select = [];
595 592
         foreach ($this->fields as $k => $field) {
596
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
593
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
597 594
         }
598 595
         foreach ($this->withr as $name => $relation) {
599 596
             foreach ($relation[0]->table->getColumns() as $column) {
600
-                $select[] = $this->getAlias($name) . '.' . $column . ' ' . $this->getAlias($name . static::SEP . $column);
597
+                $select[] = $this->getAlias($name).'.'.$column.' '.$this->getAlias($name.static::SEP.$column);
601 598
             }
602 599
         }
603 600
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
604 601
         $par = [];
605 602
         foreach ($this->joins as $k => $v) {
606
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
603
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
607 604
             $tmp = [];
608 605
             foreach ($v->keymap as $kk => $vv) {
609 606
                 $tmp[] = $kk.' = '.$vv;
610 607
             }
611
-            $sql .= implode(' AND ', $tmp) . ' ';
608
+            $sql .= implode(' AND ', $tmp).' ';
612 609
         }
613 610
         foreach ($relations as $relation => $v) {
614 611
             $table = $v[1] !== $this->definition->getName() ? $this->getAlias($v[1]) : $v[1];
@@ -620,13 +617,13 @@  discard block
 block discarded – undo
620 617
                 foreach ($v->keymap as $kk => $vv) {
621 618
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
622 619
                 }
623
-                $sql .= implode(' AND ', $tmp) . ' ';
620
+                $sql .= implode(' AND ', $tmp).' ';
624 621
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$this->getAlias($relation).' ON ';
625 622
                 $tmp = [];
626 623
                 foreach ($v->pivot_keymap as $kk => $vv) {
627 624
                     $tmp[] = $this->getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
628 625
                 }
629
-                $sql .= implode(' AND ', $tmp) . ' ';
626
+                $sql .= implode(' AND ', $tmp).' ';
630 627
             } else {
631 628
                 $alias = $this->getAlias($relation);
632 629
 
@@ -636,36 +633,36 @@  discard block
 block discarded – undo
636 633
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
637 634
                 }
638 635
                 if ($v->sql) {
639
-                    $tmp[] = $v->sql . ' ';
636
+                    $tmp[] = $v->sql.' ';
640 637
                     $par = array_merge($par, $v->par ?? []);
641 638
                 }
642
-                $sql .= implode(' AND ', $tmp) . ' ';
639
+                $sql .= implode(' AND ', $tmp).' ';
643 640
             }
644 641
         }
645 642
         if (count($this->where)) {
646 643
             $sql .= 'WHERE ';
647 644
             $tmp = [];
648 645
             foreach ($this->where as $v) {
649
-                $tmp[] = '(' . $v[0] . ')';
646
+                $tmp[] = '('.$v[0].')';
650 647
                 $par = array_merge($par, $v[1]);
651 648
             }
652 649
             $sql .= implode(' AND ', $tmp).' ';
653 650
         }
654 651
         if (count($this->group)) {
655
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
652
+            $sql .= 'GROUP BY '.$this->group[0].' ';
656 653
             $par = array_merge($par, $this->group[1]);
657 654
         }
658 655
         if (count($this->having)) {
659 656
             $sql .= 'HAVING ';
660 657
             $tmp = [];
661 658
             foreach ($this->having as $v) {
662
-                $tmp[] = '(' . $v[0] . ')';
659
+                $tmp[] = '('.$v[0].')';
663 660
                 $par = array_merge($par, $v[1]);
664 661
             }
665 662
             $sql .= implode(' AND ', $tmp).' ';
666 663
         }
667 664
         if (count($this->order)) {
668
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
665
+            $sql .= 'ORDER BY '.$this->order[0].' ';
669 666
             $par = array_merge($par, $this->order[1]);
670 667
         }
671 668
         $porder = [];
@@ -673,30 +670,30 @@  discard block
 block discarded – undo
673 670
             $porder[] = $this->getColumn($field)['name'];
674 671
         }
675 672
         if (count($porder)) {
676
-            $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
673
+            $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
677 674
         }
678 675
 
679 676
         if ($this->li_of[0]) {
680 677
             if ($this->db->driverName() === 'oracle') {
681
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
682
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
678
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
679
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
683 680
                 } else {
684
-                    $f = array_map(function ($v) {
681
+                    $f = array_map(function($v) {
685 682
                         $v = explode(' ', trim($v), 2);
686 683
                         if (count($v) === 2) { return $v[1]; }
687 684
                         $v = explode('.', $v[0], 2);
688 685
                         return count($v) === 2 ? $v[1] : $v[0];
689 686
                     }, $select);
690
-                    $sql = "SELECT " . implode(', ', $f) . " 
687
+                    $sql = "SELECT ".implode(', ', $f)." 
691 688
                             FROM (
692 689
                                 SELECT tbl__.*, rownum rnum__ FROM (
693
-                                    " . $sql . "
690
+                                    " . $sql."
694 691
                                 ) tbl__ 
695
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
692
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
696 693
                             ) WHERE rnum__ > " . $this->li_of[1];
697 694
                 }
698 695
             } else {
699
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
696
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
700 697
             }
701 698
         }
702 699
         return $this->qiterator = new TableQueryIterator(
@@ -709,7 +706,7 @@  discard block
 block discarded – undo
709 706
     protected function getAlias($name)
710 707
     {
711 708
         // to bypass use: return $name;
712
-        return $this->aliases[$name] = $this->aliases[$name] ?? 'alias' . static::SEP . count($this->aliases);
709
+        return $this->aliases[$name] = $this->aliases[$name] ?? 'alias'.static::SEP.count($this->aliases);
713 710
     }
714 711
     /**
715 712
      * Perform the actual fetch
@@ -751,7 +748,7 @@  discard block
 block discarded – undo
751 748
                 $ret[$k] = str_repeat(' ', 255);
752 749
                 $par[] = &$ret[$k];
753 750
             }
754
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
751
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
755 752
             $this->db->query($sql, $par);
756 753
             return $ret;
757 754
         } else {
@@ -783,7 +780,7 @@  discard block
 block discarded – undo
783 780
         }
784 781
         $sql = 'UPDATE '.$table.' SET ';
785 782
         $par = [];
786
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
783
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
787 784
         $par = array_merge($par, array_values($update));
788 785
         if (count($this->where)) {
789 786
             $sql .= 'WHERE ';
@@ -792,7 +789,7 @@  discard block
 block discarded – undo
792 789
                 $tmp[] = $v[0];
793 790
                 $par = array_merge($par, $v[1]);
794 791
             }
795
-            $sql .= implode(' AND ', $tmp) . ' ';
792
+            $sql .= implode(' AND ', $tmp).' ';
796 793
         }
797 794
         if (count($this->order)) {
798 795
             $sql .= $this->order[0];
@@ -816,7 +813,7 @@  discard block
 block discarded – undo
816 813
                 $tmp[] = $v[0];
817 814
                 $par = array_merge($par, $v[1]);
818 815
             }
819
-            $sql .= implode(' AND ', $tmp) . ' ';
816
+            $sql .= implode(' AND ', $tmp).' ';
820 817
         }
821 818
         if (count($this->order)) {
822 819
             $sql .= $this->order[0];
@@ -836,13 +833,13 @@  discard block
 block discarded – undo
836 833
         $table = $this->definition;
837 834
         array_reduce(
838 835
             $parts,
839
-            function ($carry, $item) use (&$table) {
836
+            function($carry, $item) use (&$table) {
840 837
                 $relation = $table->getRelation($item);
841 838
                 if (!$relation) {
842 839
                     throw new DBException('Invalid relation name');
843 840
                 }
844
-                $name = $carry ? $carry . static::SEP . $item : $item;
845
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
841
+                $name = $carry ? $carry.static::SEP.$item : $item;
842
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
846 843
                 $table = $relation->table;
847 844
                 return $name;
848 845
             }
Please login to merge, or discard this patch.