Completed
Push — master ( 4f05e7...d82db7 )
by Ivan
02:15
created
src/schema/TableQuery.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     /**
61 61
      * Create an instance
62 62
      * @param  DBInterface    $db         the database connection
63
-     * @param  Table|string   $table      the name or definition of the main table in the query
63
+     * @param  Table   $table      the name or definition of the main table in the query
64 64
      */
65 65
     public function __construct(DBInterface $db, $table)
66 66
     {
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     }
240 240
     /**
241 241
      * Group by a column (or columns)
242
-     * @param  string|array        $column the column name (or names) to group by
242
+     * @param  string        $column the column name (or names) to group by
243 243
      * @return $this
244 244
      */
245 245
     public function group($column) : TableQuery
Please login to merge, or discard this patch.
Spacing   +77 added lines, -80 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
      */
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
     public function __construct(DBInterface $db, $table)
66 66
     {
67 67
         $this->db = $db;
68
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
68
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
69 69
         $this->columns($this->definition->getColumns());
70 70
     }
71 71
     public function __clone()
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     {
86 86
         $column = explode('.', $column);
87 87
         if (count($column) === 1) {
88
-            $column = [ $this->definition->getName(), $column[0] ];
88
+            $column = [$this->definition->getName(), $column[0]];
89 89
             $col = $this->definition->getColumn($column[1]);
90 90
         } elseif (count($column) === 2) {
91 91
             if ($column[0] === $this->definition->getName()) {
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                         throw new DBException('Invalid column name in related table');
106 106
                     }
107 107
                 } else {
108
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
108
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
109 109
                 }
110 110
             }
111 111
         } else {
@@ -114,15 +114,15 @@  discard block
 block discarded – undo
114 114
             $table = $this->definition;
115 115
             $table = array_reduce(
116 116
                 $column,
117
-                function ($carry, $item) use (&$table) {
117
+                function($carry, $item) use (&$table) {
118 118
                     $table = $table->getRelation($item)->table;
119 119
                     return $table;
120 120
                 }
121 121
             );
122 122
             $col = $table->getColumn($name);
123
-            $column = [ implode(static::SEP, $column), $name ];
123
+            $column = [implode(static::SEP, $column), $name];
124 124
         }
125
-        return [ 'name' => implode('.', $column), 'data' => $col ];
125
+        return ['name' => implode('.', $column), 'data' => $col];
126 126
     }
127 127
     protected function normalizeValue(TableColumn $col, $value)
128 128
     {
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
                 }
170 170
                 return $value;
171 171
             case 'int':
172
-                return (int)$value;
172
+                return (int) $value;
173 173
             default:
174 174
                 return $value;
175 175
         }
@@ -186,18 +186,16 @@  discard block
 block discarded – undo
186 186
         list($name, $column) = array_values($this->getColumn($column));
187 187
         if (is_null($value)) {
188 188
             return $negate ?
189
-                $this->where($name . ' IS NOT NULL') :
190
-                $this->where($name . ' IS NULL');
189
+                $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL');
191 190
         }
192 191
         if (!is_array($value)) {
193 192
             return $negate ?
194 193
                 $this->where(
195
-                    $name . ' <> ?',
196
-                    [ $this->normalizeValue($column, $value) ]
197
-                ) :
198
-                $this->where(
199
-                    $name . ' = ?',
200
-                    [ $this->normalizeValue($column, $value) ]
194
+                    $name.' <> ?',
195
+                    [$this->normalizeValue($column, $value)]
196
+                ) : $this->where(
197
+                    $name.' = ?',
198
+                    [$this->normalizeValue($column, $value)]
201 199
                 );
202 200
         }
203 201
         if (isset($value['beg']) && isset($value['end'])) {
@@ -208,8 +206,7 @@  discard block
 block discarded – undo
208 206
                         $this->normalizeValue($column, $value['beg']),
209 207
                         $this->normalizeValue($column, $value['end'])
210 208
                     ]
211
-                ) :
212
-                $this->where(
209
+                ) : $this->where(
213 210
                     $name.' BETWEEN ? AND ?',
214 211
                     [
215 212
                         $this->normalizeValue($column, $value['beg']),
@@ -219,12 +216,12 @@  discard block
 block discarded – undo
219 216
         }
220 217
         return $negate ?
221 218
             $this->where(
222
-                $name . ' NOT IN (??)',
223
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
219
+                $name.' NOT IN (??)',
220
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
224 221
             ) :
225 222
             $this->where(
226
-                $name . ' IN (??)',
227
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
223
+                $name.' IN (??)',
224
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
228 225
             );
229 226
     }
230 227
     /**
@@ -235,7 +232,7 @@  discard block
 block discarded – undo
235 232
      */
236 233
     public function sort(string $column, bool $desc = false) : TableQuery
237 234
     {
238
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
235
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
239 236
     }
240 237
     /**
241 238
      * Group by a column (or columns)
@@ -245,7 +242,7 @@  discard block
 block discarded – undo
245 242
     public function group($column) : TableQuery
246 243
     {
247 244
         if (!is_array($column)) {
248
-            $column = [ $column ];
245
+            $column = [$column];
249 246
         }
250 247
         foreach ($column as $k => $v) {
251 248
             $column[$k] = $this->getColumn($v)['name'];
@@ -286,7 +283,7 @@  discard block
 block discarded – undo
286 283
         $this->withr = [];
287 284
         $this->order = [];
288 285
         $this->having = [];
289
-        $this->li_of = [0,0];
286
+        $this->li_of = [0, 0];
290 287
         $this->qiterator = null;
291 288
         return $this;
292 289
     }
@@ -299,7 +296,7 @@  discard block
 block discarded – undo
299 296
     public function groupBy(string $sql, array $params = []) : TableQuery
300 297
     {
301 298
         $this->qiterator = null;
302
-        $this->group = [ $sql, $params ];
299
+        $this->group = [$sql, $params];
303 300
         return $this;
304 301
     }
305 302
     /**
@@ -312,7 +309,7 @@  discard block
 block discarded – undo
312 309
      */
313 310
     public function join($table, array $fields, string $name = null, bool $multiple = true)
314 311
     {
315
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
312
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
316 313
         $name = $name ?? $table->getName();
317 314
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
318 315
             throw new DBException('Alias / table name already in use');
@@ -321,7 +318,7 @@  discard block
 block discarded – undo
321 318
         foreach ($fields as $k => $v) {
322 319
             $k = explode('.', $k, 2);
323 320
             $k = count($k) == 2 ? $k[1] : $k[0];
324
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
321
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
325 322
         }
326 323
         return $this;
327 324
     }
@@ -334,7 +331,7 @@  discard block
 block discarded – undo
334 331
     public function where(string $sql, array $params = []) : TableQuery
335 332
     {
336 333
         $this->qiterator = null;
337
-        $this->where[] = [ $sql, $params ];
334
+        $this->where[] = [$sql, $params];
338 335
         return $this;
339 336
     }
340 337
     /**
@@ -346,7 +343,7 @@  discard block
 block discarded – undo
346 343
     public function having(string $sql, array $params = []) : TableQuery
347 344
     {
348 345
         $this->qiterator = null;
349
-        $this->having[] = [ $sql, $params ];
346
+        $this->having[] = [$sql, $params];
350 347
         return $this;
351 348
     }
352 349
     /**
@@ -358,7 +355,7 @@  discard block
 block discarded – undo
358 355
     public function order(string $sql, array $params = []) : TableQuery
359 356
     {
360 357
         $this->qiterator = null;
361
-        $this->order = [ $sql, $params ];
358
+        $this->order = [$sql, $params];
362 359
         return $this;
363 360
     }
364 361
     /**
@@ -370,7 +367,7 @@  discard block
 block discarded – undo
370 367
     public function limit(int $limit, int $offset = 0) : TableQuery
371 368
     {
372 369
         $this->qiterator = null;
373
-        $this->li_of = [ $limit, $offset ];
370
+        $this->li_of = [$limit, $offset];
374 371
         return $this;
375 372
     }
376 373
     /**
@@ -387,22 +384,22 @@  discard block
 block discarded – undo
387 384
         $relations = $this->withr;
388 385
         foreach ($this->definition->getRelations() as $k => $v) {
389 386
             foreach ($this->where as $vv) {
390
-                if (strpos($vv[0], $k . '.') !== false) {
391
-                    $relations[$k] = [ $v, $table ];
387
+                if (strpos($vv[0], $k.'.') !== false) {
388
+                    $relations[$k] = [$v, $table];
392 389
                 }
393 390
             }
394
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
395
-                $relations[$k] = [ $v, $table ];
391
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
392
+                $relations[$k] = [$v, $table];
396 393
             }
397 394
         }
398 395
 
399 396
         foreach ($this->joins as $k => $v) {
400
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
397
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
401 398
             $tmp = [];
402 399
             foreach ($v->keymap as $kk => $vv) {
403 400
                 $tmp[] = $kk.' = '.$vv;
404 401
             }
405
-            $sql .= implode(' AND ', $tmp) . ' ';
402
+            $sql .= implode(' AND ', $tmp).' ';
406 403
         }
407 404
         foreach ($relations as $k => $v) {
408 405
             $table = $v[1];
@@ -413,13 +410,13 @@  discard block
 block discarded – undo
413 410
                 foreach ($v->keymap as $kk => $vv) {
414 411
                     $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' ';
415 412
                 }
416
-                $sql .= implode(' AND ', $tmp) . ' ';
413
+                $sql .= implode(' AND ', $tmp).' ';
417 414
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
418 415
                 $tmp = [];
419 416
                 foreach ($v->pivot_keymap as $kk => $vv) {
420 417
                     $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' ';
421 418
                 }
422
-                $sql .= implode(' AND ', $tmp) . ' ';
419
+                $sql .= implode(' AND ', $tmp).' ';
423 420
             } else {
424 421
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
425 422
                 $tmp = [];
@@ -427,30 +424,30 @@  discard block
 block discarded – undo
427 424
                     $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' ';
428 425
                 }
429 426
                 if ($v->sql) {
430
-                    $tmp[] = $v->sql . ' ';
427
+                    $tmp[] = $v->sql.' ';
431 428
                     $par = array_merge($par, $v->par ?? []);
432 429
                 }
433
-                $sql .= implode(' AND ', $tmp) . ' ';
430
+                $sql .= implode(' AND ', $tmp).' ';
434 431
             }
435 432
         }
436 433
         if (count($this->where)) {
437 434
             $sql .= 'WHERE ';
438 435
             $tmp = [];
439 436
             foreach ($this->where as $v) {
440
-                $tmp[] = '(' . $v[0] . ')';
437
+                $tmp[] = '('.$v[0].')';
441 438
                 $par = array_merge($par, $v[1]);
442 439
             }
443 440
             $sql .= implode(' AND ', $tmp).' ';
444 441
         }
445 442
         if (count($this->group)) {
446
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
443
+            $sql .= 'GROUP BY '.$this->group[0].' ';
447 444
             $par = array_merge($par, $this->group[1]);
448 445
         }
449 446
         if (count($this->having)) {
450 447
             $sql .= 'HAVING ';
451 448
             $tmp = [];
452 449
             foreach ($this->having as $v) {
453
-                $tmp[] = '(' . $v[0] . ')';
450
+                $tmp[] = '('.$v[0].')';
454 451
                 $par = array_merge($par, $v[1]);
455 452
             }
456 453
             $sql .= implode(' AND ', $tmp).' ';
@@ -486,7 +483,7 @@  discard block
 block discarded – undo
486 483
                     $this->with(implode('.', $temp));
487 484
                     $table = array_reduce(
488 485
                         $temp,
489
-                        function ($carry, $item) use (&$table) {
486
+                        function($carry, $item) use (&$table) {
490 487
                             return $table->getRelation($item)->table;
491 488
                         }
492 489
                     );
@@ -495,7 +492,7 @@  discard block
 block discarded – undo
495 492
                 }
496 493
                 unset($fields[$k]);
497 494
                 foreach ($cols as $col) {
498
-                    $fields[] = $table . '.' . $col;
495
+                    $fields[] = $table.'.'.$col;
499 496
                 }
500 497
             }
501 498
         }
@@ -534,37 +531,37 @@  discard block
 block discarded – undo
534 531
         $relations = $this->withr;
535 532
         foreach ($this->definition->getRelations() as $k => $relation) {
536 533
             foreach ($this->fields as $field) {
537
-                if (strpos($field, $k . '.') === 0) {
538
-                    $relations[$k] = [ $relation, $table ];
534
+                if (strpos($field, $k.'.') === 0) {
535
+                    $relations[$k] = [$relation, $table];
539 536
                 }
540 537
             }
541 538
             foreach ($this->where as $v) {
542
-                if (strpos($v[0], $k . '.') !== false) {
543
-                    $relations[$k] = [ $relation, $table ];
539
+                if (strpos($v[0], $k.'.') !== false) {
540
+                    $relations[$k] = [$relation, $table];
544 541
                 }
545 542
             }
546
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
547
-                $relations[$k] = [ $relation, $table ];
543
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
544
+                $relations[$k] = [$relation, $table];
548 545
             }
549 546
         }
550 547
         $select = [];
551 548
         foreach ($this->fields as $k => $field) {
552
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
549
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
553 550
         }
554 551
         foreach ($this->withr as $name => $relation) {
555 552
             foreach ($relation[0]->table->getColumns() as $column) {
556
-                $select[] = $name . '.' . $column . ' ' . $name . static::SEP . $column;
553
+                $select[] = $name.'.'.$column.' '.$name.static::SEP.$column;
557 554
             }
558 555
         }
559 556
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
560 557
         $par = [];
561 558
         foreach ($this->joins as $k => $v) {
562
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
559
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
563 560
             $tmp = [];
564 561
             foreach ($v->keymap as $kk => $vv) {
565 562
                 $tmp[] = $kk.' = '.$vv;
566 563
             }
567
-            $sql .= implode(' AND ', $tmp) . ' ';
564
+            $sql .= implode(' AND ', $tmp).' ';
568 565
         }
569 566
         foreach ($relations as $relation => $v) {
570 567
             $table = $v[1];
@@ -575,13 +572,13 @@  discard block
 block discarded – undo
575 572
                 foreach ($v->keymap as $kk => $vv) {
576 573
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' ';
577 574
                 }
578
-                $sql .= implode(' AND ', $tmp) . ' ';
575
+                $sql .= implode(' AND ', $tmp).' ';
579 576
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
580 577
                 $tmp = [];
581 578
                 foreach ($v->pivot_keymap as $kk => $vv) {
582 579
                     $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' ';
583 580
                 }
584
-                $sql .= implode(' AND ', $tmp) . ' ';
581
+                $sql .= implode(' AND ', $tmp).' ';
585 582
             } else {
586 583
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
587 584
                 $tmp = [];
@@ -589,65 +586,65 @@  discard block
 block discarded – undo
589 586
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' ';
590 587
                 }
591 588
                 if ($v->sql) {
592
-                    $tmp[] = $v->sql . ' ';
589
+                    $tmp[] = $v->sql.' ';
593 590
                     $par = array_merge($par, $v->par ?? []);
594 591
                 }
595
-                $sql .= implode(' AND ', $tmp) . ' ';
592
+                $sql .= implode(' AND ', $tmp).' ';
596 593
             }
597 594
         }
598 595
         if (count($this->where)) {
599 596
             $sql .= 'WHERE ';
600 597
             $tmp = [];
601 598
             foreach ($this->where as $v) {
602
-                $tmp[] = '(' . $v[0] . ')';
599
+                $tmp[] = '('.$v[0].')';
603 600
                 $par = array_merge($par, $v[1]);
604 601
             }
605 602
             $sql .= implode(' AND ', $tmp).' ';
606 603
         }
607 604
         if (count($this->group)) {
608
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
605
+            $sql .= 'GROUP BY '.$this->group[0].' ';
609 606
             $par = array_merge($par, $this->group[1]);
610 607
         }
611 608
         if (count($this->having)) {
612 609
             $sql .= 'HAVING ';
613 610
             $tmp = [];
614 611
             foreach ($this->having as $v) {
615
-                $tmp[] = '(' . $v[0] . ')';
612
+                $tmp[] = '('.$v[0].')';
616 613
                 $par = array_merge($par, $v[1]);
617 614
             }
618 615
             $sql .= implode(' AND ', $tmp).' ';
619 616
         }
620 617
         if (count($this->order)) {
621
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
618
+            $sql .= 'ORDER BY '.$this->order[0].' ';
622 619
             $par = array_merge($par, $this->order[1]);
623 620
         }
624 621
         $porder = [];
625 622
         foreach ($primary as $field) {
626 623
             $porder[] = $this->getColumn($field)['name'];
627 624
         }
628
-        $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
625
+        $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
629 626
 
630 627
         if ($this->li_of[0]) {
631 628
             if ($this->db->driver() === 'oracle') {
632
-                if ((int)($this->db->settings()->options['version'] ?? 0) >= 12) {
633
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
629
+                if ((int) ($this->db->settings()->options['version'] ?? 0) >= 12) {
630
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
634 631
                 } else {
635
-                    $f = array_map(function ($v) {
632
+                    $f = array_map(function($v) {
636 633
                         $v = explode(' ', trim($v), 2);
637 634
                         if (count($v) === 2) { return $v[1]; }
638 635
                         $v = explode('.', $v[0], 2);
639 636
                         return count($v) === 2 ? $v[1] : $v[0];
640 637
                     }, $select);
641
-                    $sql = "SELECT " . implode(', ', $f) . " 
638
+                    $sql = "SELECT ".implode(', ', $f)." 
642 639
                             FROM (
643 640
                                 SELECT tbl__.*, rownum rnum__ FROM (
644
-                                    " . $sql . "
641
+                                    " . $sql."
645 642
                                 ) tbl__ 
646
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
643
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
647 644
                             ) WHERE rnum__ > " . $this->li_of[1];
648 645
                 }
649 646
             } else {
650
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
647
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
651 648
             }
652 649
         }
653 650
         return $this->qiterator = new TableQueryIterator(
@@ -692,7 +689,7 @@  discard block
 block discarded – undo
692 689
                 $ret[$k] = str_repeat(' ', 255);
693 690
                 $par[] = &$ret[$k];
694 691
             }
695
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
692
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
696 693
             $this->db->query($sql, $par);
697 694
             return $ret;
698 695
         } else {
@@ -724,7 +721,7 @@  discard block
 block discarded – undo
724 721
         }
725 722
         $sql = 'UPDATE '.$table.' SET ';
726 723
         $par = [];
727
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
724
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
728 725
         $par = array_merge($par, array_values($update));
729 726
         if (count($this->where)) {
730 727
             $sql .= 'WHERE ';
@@ -733,7 +730,7 @@  discard block
 block discarded – undo
733 730
                 $tmp[] = $v[0];
734 731
                 $par = array_merge($par, $v[1]);
735 732
             }
736
-            $sql .= implode(' AND ', $tmp) . ' ';
733
+            $sql .= implode(' AND ', $tmp).' ';
737 734
         }
738 735
         if (count($this->order)) {
739 736
             $sql .= $this->order[0];
@@ -757,7 +754,7 @@  discard block
 block discarded – undo
757 754
                 $tmp[] = $v[0];
758 755
                 $par = array_merge($par, $v[1]);
759 756
             }
760
-            $sql .= implode(' AND ', $tmp) . ' ';
757
+            $sql .= implode(' AND ', $tmp).' ';
761 758
         }
762 759
         if (count($this->order)) {
763 760
             $sql .= $this->order[0];
@@ -777,13 +774,13 @@  discard block
 block discarded – undo
777 774
         $table = $this->definition;
778 775
         array_reduce(
779 776
             $parts,
780
-            function ($carry, $item) use (&$table) {
777
+            function($carry, $item) use (&$table) {
781 778
                 $relation = $table->getRelation($item);
782 779
                 if (!$relation) {
783 780
                     throw new DBException('Invalid relation name');
784 781
                 }
785
-                $name = $carry ? $carry . static::SEP . $item : $item;
786
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
782
+                $name = $carry ? $carry.static::SEP.$item : $item;
783
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
787 784
                 $table = $relation->table;
788 785
                 return $name;
789 786
             }
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +13 added lines, -15 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@  discard block
 block discarded – undo
74 74
         }
75 75
         $connection['name'] = $connectionString;
76 76
         $connection['type'] = isset($aliases[$connection['type']]) ?
77
-            $aliases[$connection['type']] :
78
-            $connection['type'];
77
+            $aliases[$connection['type']] : $connection['type'];
79 78
         $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver';
80 79
         return new $tmp($connection);
81 80
     }
@@ -95,7 +94,7 @@  discard block
 block discarded – undo
95 94
         $new = '';
96 95
         $par = array_values($par);
97 96
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
98
-            $par = [ $par ];
97
+            $par = [$par];
99 98
         }
100 99
         $parts = explode('??', $sql);
101 100
         $index = 0;
@@ -105,7 +104,7 @@  discard block
 block discarded – undo
105 104
             $index += count($tmp) - 1;
106 105
             if (isset($par[$index])) {
107 106
                 if (!is_array($par[$index])) {
108
-                    $par[$index] = [ $par[$index] ];
107
+                    $par[$index] = [$par[$index]];
109 108
                 }
110 109
                 $params = $par[$index];
111 110
                 array_splice($par, $index, 1, $params);
@@ -113,7 +112,7 @@  discard block
 block discarded – undo
113 112
                 $new .= implode(',', array_fill(0, count($params), '?'));
114 113
             }
115 114
         }
116
-        return [ $new, $par ];
115
+        return [$new, $par];
117 116
     }
118 117
     /**
119 118
      * Run a query (prepare & execute).
@@ -145,7 +144,7 @@  discard block
 block discarded – undo
145 144
     {
146 145
         $coll = Collection::from($this->query($sql, $par));
147 146
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
148
-            $coll->map(function ($v) use ($keys) {
147
+            $coll->map(function($v) use ($keys) {
149 148
                 $new = [];
150 149
                 foreach ($v as $k => $vv) {
151 150
                     $new[call_user_func($keys, $k)] = $vv;
@@ -154,13 +153,13 @@  discard block
 block discarded – undo
154 153
             });
155 154
         }
156 155
         if ($key !== null) {
157
-            $coll->mapKey(function ($v) use ($key) { return $v[$key]; });
156
+            $coll->mapKey(function($v) use ($key) { return $v[$key]; });
158 157
         }
159 158
         if ($skip) {
160
-            $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; });
159
+            $coll->map(function($v) use ($key) { unset($v[$key]); return $v; });
161 160
         }
162 161
         if ($opti) {
163
-            $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; });
162
+            $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; });
164 163
         }
165 164
         return $coll;
166 165
     }
@@ -233,8 +232,7 @@  discard block
 block discarded – undo
233 232
     public function definition(string $table, bool $detectRelations = true) : Table
234 233
     {
235 234
         return isset($this->tables[$table]) ?
236
-            $this->tables[$table] :
237
-            $this->driver->table($table, $detectRelations);
235
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
238 236
     }
239 237
     /**
240 238
      * Parse all tables from the database.
@@ -251,12 +249,12 @@  discard block
 block discarded – undo
251 249
      */
252 250
     public function getSchema($asPlainArray = true)
253 251
     {
254
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
252
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
255 253
             return [
256 254
                 'name' => $table->getName(),
257 255
                 'pkey' => $table->getPrimaryKey(),
258 256
                 'comment' => $table->getComment(),
259
-                'columns' => array_map(function ($column) {
257
+                'columns' => array_map(function($column) {
260 258
                     return [
261 259
                         'name' => $column->getName(),
262 260
                         'type' => $column->getType(),
@@ -266,13 +264,13 @@  discard block
 block discarded – undo
266 264
                         'nullable' => $column->isNullable()
267 265
                     ];
268 266
                 }, $table->getFullColumns()),
269
-                'relations' => array_map(function ($rel) {
267
+                'relations' => array_map(function($rel) {
270 268
                     $relation = clone $rel;
271 269
                     $relation->table = $relation->table->getName();
272 270
                     if ($relation->pivot) {
273 271
                         $relation->pivot = $relation->pivot->getName();
274 272
                     }
275
-                    return (array)$relation;
273
+                    return (array) $relation;
276 274
                 }, $table->getRelations())
277 275
             ];
278 276
         }, $this->tables);
Please login to merge, or discard this patch.