Completed
Push — master ( 0c3707...a98725 )
by Ivan
02:20
created
src/schema/TableQuery.php 1 patch
Spacing   +85 added lines, -88 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
      */
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
     public function __construct(DBInterface $db, $table)
70 70
     {
71 71
         $this->db = $db;
72
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
72
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
73 73
         $primary = $this->definition->getPrimaryKey();
74 74
         $columns = $this->definition->getColumns();
75 75
         $this->pkey = count($primary) ? $primary : $columns;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
     {
93 93
         $column = explode('.', $column);
94 94
         if (count($column) === 1) {
95
-            $column = [ $this->definition->getName(), $column[0] ];
95
+            $column = [$this->definition->getName(), $column[0]];
96 96
             $col = $this->definition->getColumn($column[1]);
97 97
             if (!$col) {
98 98
                 throw new DBException('Invalid column name in own table');
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                         throw new DBException('Invalid column name in related table');
116 116
                     }
117 117
                 } else {
118
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
118
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
119 119
                 }
120 120
             }
121 121
         } else {
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
             $table = $this->definition;
125 125
             $table = array_reduce(
126 126
                 $column,
127
-                function ($carry, $item) use (&$table) {
127
+                function($carry, $item) use (&$table) {
128 128
                     $table = $table->getRelation($item)->table;
129 129
                     return $table;
130 130
                 }
131 131
             );
132 132
             $col = $table->getColumn($name);
133
-            $column = [ implode(static::SEP, $column), $name ];
133
+            $column = [implode(static::SEP, $column), $name];
134 134
         }
135
-        return [ 'name' => implode('.', $column), 'data' => $col ];
135
+        return ['name' => implode('.', $column), 'data' => $col];
136 136
     }
137 137
     protected function normalizeValue(TableColumn $col, $value)
138 138
     {
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
                 }
180 180
                 return $value;
181 181
             case 'int':
182
-                return (int)$value;
182
+                return (int) $value;
183 183
             default:
184 184
                 return $value;
185 185
         }
@@ -197,18 +197,16 @@  discard block
 block discarded – undo
197 197
         list($name, $column) = array_values($this->getColumn($column));
198 198
         if (is_null($value)) {
199 199
             return $negate ?
200
-                $this->where($name . ' IS NOT NULL') :
201
-                $this->where($name . ' IS NULL');
200
+                $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL');
202 201
         }
203 202
         if (!is_array($value)) {
204 203
             return $negate ?
205 204
                 $this->where(
206
-                    $name . ' <> ?',
207
-                    [ $this->normalizeValue($column, $value) ]
208
-                ) :
209
-                $this->where(
210
-                    $name . ' = ?',
211
-                    [ $this->normalizeValue($column, $value) ]
205
+                    $name.' <> ?',
206
+                    [$this->normalizeValue($column, $value)]
207
+                ) : $this->where(
208
+                    $name.' = ?',
209
+                    [$this->normalizeValue($column, $value)]
212 210
                 );
213 211
         }
214 212
         if (isset($value['beg']) && isset($value['end'])) {
@@ -219,8 +217,7 @@  discard block
 block discarded – undo
219 217
                         $this->normalizeValue($column, $value['beg']),
220 218
                         $this->normalizeValue($column, $value['end'])
221 219
                     ]
222
-                ) :
223
-                $this->where(
220
+                ) : $this->where(
224 221
                     $name.' BETWEEN ? AND ?',
225 222
                     [
226 223
                         $this->normalizeValue($column, $value['beg']),
@@ -231,38 +228,38 @@  discard block
 block discarded – undo
231 228
         if (isset($value['gt']) || isset($value['lt']) || isset($value['gte']) || isset($value['lte'])) {
232 229
             if (isset($value['gt'])) {
233 230
                 $this->where(
234
-                    $name. ' ' . ($negate ? '<=' : '>') . ' ?',
235
-                    [ $this->normalizeValue($column, $value['gt']) ]
231
+                    $name.' '.($negate ? '<=' : '>').' ?',
232
+                    [$this->normalizeValue($column, $value['gt'])]
236 233
                 );
237 234
             }
238 235
             if (isset($value['gte'])) {
239 236
                 $this->where(
240
-                    $name. ' ' . ($negate ? '<' : '>=') . ' ?',
241
-                    [ $this->normalizeValue($column, $value['gte']) ]
237
+                    $name.' '.($negate ? '<' : '>=').' ?',
238
+                    [$this->normalizeValue($column, $value['gte'])]
242 239
                 );
243 240
             }
244 241
             if (isset($value['lt'])) {
245 242
                 $this->where(
246
-                    $name. ' ' . ($negate ? '>=' : '<') . ' ?',
247
-                    [ $this->normalizeValue($column, $value['lt']) ]
243
+                    $name.' '.($negate ? '>=' : '<').' ?',
244
+                    [$this->normalizeValue($column, $value['lt'])]
248 245
                 );
249 246
             }
250 247
             if (isset($value['lte'])) {
251 248
                 $this->where(
252
-                    $name. ' ' . ($negate ? '>' : '<=') . ' ?',
253
-                    [ $this->normalizeValue($column, $value['lte']) ]
249
+                    $name.' '.($negate ? '>' : '<=').' ?',
250
+                    [$this->normalizeValue($column, $value['lte'])]
254 251
                 );
255 252
             }
256 253
             return $this;
257 254
         }
258 255
         return $negate ?
259 256
             $this->where(
260
-                $name . ' NOT IN (??)',
261
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
257
+                $name.' NOT IN (??)',
258
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
262 259
             ) :
263 260
             $this->where(
264
-                $name . ' IN (??)',
265
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
261
+                $name.' IN (??)',
262
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
266 263
             );
267 264
     }
268 265
     /**
@@ -273,7 +270,7 @@  discard block
 block discarded – undo
273 270
      */
274 271
     public function sort(string $column, bool $desc = false) : TableQuery
275 272
     {
276
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
273
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
277 274
     }
278 275
     /**
279 276
      * Group by a column (or columns)
@@ -283,7 +280,7 @@  discard block
 block discarded – undo
283 280
     public function group($column) : TableQuery
284 281
     {
285 282
         if (!is_array($column)) {
286
-            $column = [ $column ];
283
+            $column = [$column];
287 284
         }
288 285
         foreach ($column as $k => $v) {
289 286
             $column[$k] = $this->getColumn($v)['name'];
@@ -324,7 +321,7 @@  discard block
 block discarded – undo
324 321
         $this->withr = [];
325 322
         $this->order = [];
326 323
         $this->having = [];
327
-        $this->li_of = [0,0];
324
+        $this->li_of = [0, 0];
328 325
         $this->qiterator = null;
329 326
         return $this;
330 327
     }
@@ -337,7 +334,7 @@  discard block
 block discarded – undo
337 334
     public function groupBy(string $sql, array $params = []) : TableQuery
338 335
     {
339 336
         $this->qiterator = null;
340
-        $this->group = [ $sql, $params ];
337
+        $this->group = [$sql, $params];
341 338
         return $this;
342 339
     }
343 340
     /**
@@ -350,7 +347,7 @@  discard block
 block discarded – undo
350 347
      */
351 348
     public function join($table, array $fields, string $name = null, bool $multiple = true)
352 349
     {
353
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
350
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
354 351
         $name = $name ?? $table->getName();
355 352
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
356 353
             throw new DBException('Alias / table name already in use');
@@ -359,7 +356,7 @@  discard block
 block discarded – undo
359 356
         foreach ($fields as $k => $v) {
360 357
             $k = explode('.', $k, 2);
361 358
             $k = count($k) == 2 ? $k[1] : $k[0];
362
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
359
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
363 360
         }
364 361
         return $this;
365 362
     }
@@ -372,7 +369,7 @@  discard block
 block discarded – undo
372 369
     public function where(string $sql, array $params = []) : TableQuery
373 370
     {
374 371
         $this->qiterator = null;
375
-        $this->where[] = [ $sql, $params ];
372
+        $this->where[] = [$sql, $params];
376 373
         return $this;
377 374
     }
378 375
     /**
@@ -384,7 +381,7 @@  discard block
 block discarded – undo
384 381
     public function having(string $sql, array $params = []) : TableQuery
385 382
     {
386 383
         $this->qiterator = null;
387
-        $this->having[] = [ $sql, $params ];
384
+        $this->having[] = [$sql, $params];
388 385
         return $this;
389 386
     }
390 387
     /**
@@ -396,7 +393,7 @@  discard block
 block discarded – undo
396 393
     public function order(string $sql, array $params = []) : TableQuery
397 394
     {
398 395
         $this->qiterator = null;
399
-        $this->order = [ $sql, $params ];
396
+        $this->order = [$sql, $params];
400 397
         return $this;
401 398
     }
402 399
     /**
@@ -408,7 +405,7 @@  discard block
 block discarded – undo
408 405
     public function limit(int $limit, int $offset = 0) : TableQuery
409 406
     {
410 407
         $this->qiterator = null;
411
-        $this->li_of = [ $limit, $offset ];
408
+        $this->li_of = [$limit, $offset];
412 409
         return $this;
413 410
     }
414 411
     /**
@@ -424,22 +421,22 @@  discard block
 block discarded – undo
424 421
         $relations = $this->withr;
425 422
         foreach ($this->definition->getRelations() as $k => $v) {
426 423
             foreach ($this->where as $vv) {
427
-                if (strpos($vv[0], $k . '.') !== false) {
428
-                    $relations[$k] = [ $v, $table ];
424
+                if (strpos($vv[0], $k.'.') !== false) {
425
+                    $relations[$k] = [$v, $table];
429 426
                 }
430 427
             }
431
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
432
-                $relations[$k] = [ $v, $table ];
428
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
429
+                $relations[$k] = [$v, $table];
433 430
             }
434 431
         }
435 432
 
436 433
         foreach ($this->joins as $k => $v) {
437
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
434
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
438 435
             $tmp = [];
439 436
             foreach ($v->keymap as $kk => $vv) {
440 437
                 $tmp[] = $kk.' = '.$vv;
441 438
             }
442
-            $sql .= implode(' AND ', $tmp) . ' ';
439
+            $sql .= implode(' AND ', $tmp).' ';
443 440
         }
444 441
         foreach ($relations as $k => $v) {
445 442
             $table = $v[1];
@@ -450,13 +447,13 @@  discard block
 block discarded – undo
450 447
                 foreach ($v->keymap as $kk => $vv) {
451 448
                     $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' ';
452 449
                 }
453
-                $sql .= implode(' AND ', $tmp) . ' ';
450
+                $sql .= implode(' AND ', $tmp).' ';
454 451
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
455 452
                 $tmp = [];
456 453
                 foreach ($v->pivot_keymap as $kk => $vv) {
457 454
                     $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' ';
458 455
                 }
459
-                $sql .= implode(' AND ', $tmp) . ' ';
456
+                $sql .= implode(' AND ', $tmp).' ';
460 457
             } else {
461 458
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
462 459
                 $tmp = [];
@@ -464,30 +461,30 @@  discard block
 block discarded – undo
464 461
                     $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' ';
465 462
                 }
466 463
                 if ($v->sql) {
467
-                    $tmp[] = $v->sql . ' ';
464
+                    $tmp[] = $v->sql.' ';
468 465
                     $par = array_merge($par, $v->par ?? []);
469 466
                 }
470
-                $sql .= implode(' AND ', $tmp) . ' ';
467
+                $sql .= implode(' AND ', $tmp).' ';
471 468
             }
472 469
         }
473 470
         if (count($this->where)) {
474 471
             $sql .= 'WHERE ';
475 472
             $tmp = [];
476 473
             foreach ($this->where as $v) {
477
-                $tmp[] = '(' . $v[0] . ')';
474
+                $tmp[] = '('.$v[0].')';
478 475
                 $par = array_merge($par, $v[1]);
479 476
             }
480 477
             $sql .= implode(' AND ', $tmp).' ';
481 478
         }
482 479
         if (count($this->group)) {
483
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
480
+            $sql .= 'GROUP BY '.$this->group[0].' ';
484 481
             $par = array_merge($par, $this->group[1]);
485 482
         }
486 483
         if (count($this->having)) {
487 484
             $sql .= 'HAVING ';
488 485
             $tmp = [];
489 486
             foreach ($this->having as $v) {
490
-                $tmp[] = '(' . $v[0] . ')';
487
+                $tmp[] = '('.$v[0].')';
491 488
                 $par = array_merge($par, $v[1]);
492 489
             }
493 490
             $sql .= implode(' AND ', $tmp).' ';
@@ -521,7 +518,7 @@  discard block
 block discarded – undo
521 518
                     $this->with(implode('.', $temp));
522 519
                     $table = array_reduce(
523 520
                         $temp,
524
-                        function ($carry, $item) use (&$table) {
521
+                        function($carry, $item) use (&$table) {
525 522
                             return $table->getRelation($item)->table;
526 523
                         }
527 524
                     );
@@ -530,7 +527,7 @@  discard block
 block discarded – undo
530 527
                 }
531 528
                 unset($fields[$k]);
532 529
                 foreach ($cols as $col) {
533
-                    $fields[] = $table . '.' . $col;
530
+                    $fields[] = $table.'.'.$col;
534 531
                 }
535 532
             }
536 533
         }
@@ -568,37 +565,37 @@  discard block
 block discarded – undo
568 565
         $relations = $this->withr;
569 566
         foreach ($this->definition->getRelations() as $k => $relation) {
570 567
             foreach ($this->fields as $field) {
571
-                if (strpos($field, $k . '.') === 0) {
572
-                    $relations[$k] = [ $relation, $table ];
568
+                if (strpos($field, $k.'.') === 0) {
569
+                    $relations[$k] = [$relation, $table];
573 570
                 }
574 571
             }
575 572
             foreach ($this->where as $v) {
576
-                if (strpos($v[0], $k . '.') !== false) {
577
-                    $relations[$k] = [ $relation, $table ];
573
+                if (strpos($v[0], $k.'.') !== false) {
574
+                    $relations[$k] = [$relation, $table];
578 575
                 }
579 576
             }
580
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
581
-                $relations[$k] = [ $relation, $table ];
577
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
578
+                $relations[$k] = [$relation, $table];
582 579
             }
583 580
         }
584 581
         $select = [];
585 582
         foreach ($this->fields as $k => $field) {
586
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
583
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
587 584
         }
588 585
         foreach ($this->withr as $name => $relation) {
589 586
             foreach ($relation[0]->table->getColumns() as $column) {
590
-                $select[] = $name . '.' . $column . ' ' . $name . static::SEP . $column;
587
+                $select[] = $name.'.'.$column.' '.$name.static::SEP.$column;
591 588
             }
592 589
         }
593 590
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
594 591
         $par = [];
595 592
         foreach ($this->joins as $k => $v) {
596
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
593
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
597 594
             $tmp = [];
598 595
             foreach ($v->keymap as $kk => $vv) {
599 596
                 $tmp[] = $kk.' = '.$vv;
600 597
             }
601
-            $sql .= implode(' AND ', $tmp) . ' ';
598
+            $sql .= implode(' AND ', $tmp).' ';
602 599
         }
603 600
         foreach ($relations as $relation => $v) {
604 601
             $table = $v[1];
@@ -609,13 +606,13 @@  discard block
 block discarded – undo
609 606
                 foreach ($v->keymap as $kk => $vv) {
610 607
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' ';
611 608
                 }
612
-                $sql .= implode(' AND ', $tmp) . ' ';
609
+                $sql .= implode(' AND ', $tmp).' ';
613 610
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
614 611
                 $tmp = [];
615 612
                 foreach ($v->pivot_keymap as $kk => $vv) {
616 613
                     $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' ';
617 614
                 }
618
-                $sql .= implode(' AND ', $tmp) . ' ';
615
+                $sql .= implode(' AND ', $tmp).' ';
619 616
             } else {
620 617
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
621 618
                 $tmp = [];
@@ -623,36 +620,36 @@  discard block
 block discarded – undo
623 620
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' ';
624 621
                 }
625 622
                 if ($v->sql) {
626
-                    $tmp[] = $v->sql . ' ';
623
+                    $tmp[] = $v->sql.' ';
627 624
                     $par = array_merge($par, $v->par ?? []);
628 625
                 }
629
-                $sql .= implode(' AND ', $tmp) . ' ';
626
+                $sql .= implode(' AND ', $tmp).' ';
630 627
             }
631 628
         }
632 629
         if (count($this->where)) {
633 630
             $sql .= 'WHERE ';
634 631
             $tmp = [];
635 632
             foreach ($this->where as $v) {
636
-                $tmp[] = '(' . $v[0] . ')';
633
+                $tmp[] = '('.$v[0].')';
637 634
                 $par = array_merge($par, $v[1]);
638 635
             }
639 636
             $sql .= implode(' AND ', $tmp).' ';
640 637
         }
641 638
         if (count($this->group)) {
642
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
639
+            $sql .= 'GROUP BY '.$this->group[0].' ';
643 640
             $par = array_merge($par, $this->group[1]);
644 641
         }
645 642
         if (count($this->having)) {
646 643
             $sql .= 'HAVING ';
647 644
             $tmp = [];
648 645
             foreach ($this->having 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->order)) {
655
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
652
+            $sql .= 'ORDER BY '.$this->order[0].' ';
656 653
             $par = array_merge($par, $this->order[1]);
657 654
         }
658 655
         $porder = [];
@@ -660,30 +657,30 @@  discard block
 block discarded – undo
660 657
             $porder[] = $this->getColumn($field)['name'];
661 658
         }
662 659
         if (count($porder)) {
663
-            $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
660
+            $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
664 661
         }
665 662
 
666 663
         if ($this->li_of[0]) {
667 664
             if ($this->db->driverName() === 'oracle') {
668
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
669
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
665
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
666
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
670 667
                 } else {
671
-                    $f = array_map(function ($v) {
668
+                    $f = array_map(function($v) {
672 669
                         $v = explode(' ', trim($v), 2);
673 670
                         if (count($v) === 2) { return $v[1]; }
674 671
                         $v = explode('.', $v[0], 2);
675 672
                         return count($v) === 2 ? $v[1] : $v[0];
676 673
                     }, $select);
677
-                    $sql = "SELECT " . implode(', ', $f) . " 
674
+                    $sql = "SELECT ".implode(', ', $f)." 
678 675
                             FROM (
679 676
                                 SELECT tbl__.*, rownum rnum__ FROM (
680
-                                    " . $sql . "
677
+                                    " . $sql."
681 678
                                 ) tbl__ 
682
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
679
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
683 680
                             ) WHERE rnum__ > " . $this->li_of[1];
684 681
                 }
685 682
             } else {
686
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
683
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
687 684
             }
688 685
         }
689 686
         return $this->qiterator = new TableQueryIterator(
@@ -732,7 +729,7 @@  discard block
 block discarded – undo
732 729
                 $ret[$k] = str_repeat(' ', 255);
733 730
                 $par[] = &$ret[$k];
734 731
             }
735
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
732
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
736 733
             $this->db->query($sql, $par);
737 734
             return $ret;
738 735
         } else {
@@ -764,7 +761,7 @@  discard block
 block discarded – undo
764 761
         }
765 762
         $sql = 'UPDATE '.$table.' SET ';
766 763
         $par = [];
767
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
764
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
768 765
         $par = array_merge($par, array_values($update));
769 766
         if (count($this->where)) {
770 767
             $sql .= 'WHERE ';
@@ -773,7 +770,7 @@  discard block
 block discarded – undo
773 770
                 $tmp[] = $v[0];
774 771
                 $par = array_merge($par, $v[1]);
775 772
             }
776
-            $sql .= implode(' AND ', $tmp) . ' ';
773
+            $sql .= implode(' AND ', $tmp).' ';
777 774
         }
778 775
         if (count($this->order)) {
779 776
             $sql .= $this->order[0];
@@ -797,7 +794,7 @@  discard block
 block discarded – undo
797 794
                 $tmp[] = $v[0];
798 795
                 $par = array_merge($par, $v[1]);
799 796
             }
800
-            $sql .= implode(' AND ', $tmp) . ' ';
797
+            $sql .= implode(' AND ', $tmp).' ';
801 798
         }
802 799
         if (count($this->order)) {
803 800
             $sql .= $this->order[0];
@@ -817,13 +814,13 @@  discard block
 block discarded – undo
817 814
         $table = $this->definition;
818 815
         array_reduce(
819 816
             $parts,
820
-            function ($carry, $item) use (&$table) {
817
+            function($carry, $item) use (&$table) {
821 818
                 $relation = $table->getRelation($item);
822 819
                 if (!$relation) {
823 820
                     throw new DBException('Invalid relation name');
824 821
                 }
825
-                $name = $carry ? $carry . static::SEP . $item : $item;
826
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
822
+                $name = $carry ? $carry.static::SEP.$item : $item;
823
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
827 824
                 $table = $relation->table;
828 825
                 return $name;
829 826
             }
Please login to merge, or discard this patch.