Completed
Push — master ( d82db7...107033 )
by Ivan
02:39
created
src/schema/TableQueryIterator.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -65,27 +65,27 @@  discard block
 block discarded – undo
65 65
                 $fields = [];
66 66
                 $exists = false;
67 67
                 foreach ($relation->table->getColumns() as $column) {
68
-                    $fields[$column] = $row[$name . static::SEP . $column];
69
-                    if (!$exists && $row[$name . static::SEP . $column] !== null) {
68
+                    $fields[$column] = $row[$name.static::SEP.$column];
69
+                    if (!$exists && $row[$name.static::SEP.$column] !== null) {
70 70
                         $exists = true;
71 71
                     }
72
-                    $remove[] = $name . static::SEP . $column;
72
+                    $remove[] = $name.static::SEP.$column;
73 73
                 }
74 74
                 $temp  = &$result;
75 75
                 $parts = explode(static::SEP, $name);
76 76
                 $name  = array_pop($parts);
77 77
                 $full  = '';
78 78
                 foreach ($parts as $item) {
79
-                    $full = $full ? $full . static::SEP . $item : $item;
79
+                    $full = $full ? $full.static::SEP.$item : $item;
80 80
                     $temp = &$temp[$item];
81 81
                     $rpk = [];
82 82
                     foreach ($this->relations[$full][0]->table->getPrimaryKey() as $pkey) {
83
-                        $rpk[$pkey] = $row[$full . static::SEP . $pkey];
83
+                        $rpk[$pkey] = $row[$full.static::SEP.$pkey];
84 84
                     }
85 85
                     $temp = &$temp[json_encode($rpk)];
86 86
                 }
87 87
                 if (!isset($temp[$name])) {
88
-                    $temp[$name] = $relation->many ? [ '___clean' => true ] : null;
88
+                    $temp[$name] = $relation->many ? ['___clean' => true] : null;
89 89
                 }
90 90
                 $temp = &$temp[$name];
91 91
                 if ($exists) {
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
                 return;
145 145
             }
146 146
         }
147
-        $this->fetched ++;
147
+        $this->fetched++;
148 148
         while ($this->result->valid()) {
149 149
             $row = $this->result->current();
150 150
             $pk = [];
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 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).' ';
@@ -484,7 +481,7 @@  discard block
 block discarded – undo
484 481
                     $this->with(implode('.', $temp));
485 482
                     $table = array_reduce(
486 483
                         $temp,
487
-                        function ($carry, $item) use (&$table) {
484
+                        function($carry, $item) use (&$table) {
488 485
                             return $table->getRelation($item)->table;
489 486
                         }
490 487
                     );
@@ -493,7 +490,7 @@  discard block
 block discarded – undo
493 490
                 }
494 491
                 unset($fields[$k]);
495 492
                 foreach ($cols as $col) {
496
-                    $fields[] = $table . '.' . $col;
493
+                    $fields[] = $table.'.'.$col;
497 494
                 }
498 495
             }
499 496
         }
@@ -532,37 +529,37 @@  discard block
 block discarded – undo
532 529
         $relations = $this->withr;
533 530
         foreach ($this->definition->getRelations() as $k => $relation) {
534 531
             foreach ($this->fields as $field) {
535
-                if (strpos($field, $k . '.') === 0) {
536
-                    $relations[$k] = [ $relation, $table ];
532
+                if (strpos($field, $k.'.') === 0) {
533
+                    $relations[$k] = [$relation, $table];
537 534
                 }
538 535
             }
539 536
             foreach ($this->where as $v) {
540
-                if (strpos($v[0], $k . '.') !== false) {
541
-                    $relations[$k] = [ $relation, $table ];
537
+                if (strpos($v[0], $k.'.') !== false) {
538
+                    $relations[$k] = [$relation, $table];
542 539
                 }
543 540
             }
544
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
545
-                $relations[$k] = [ $relation, $table ];
541
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
542
+                $relations[$k] = [$relation, $table];
546 543
             }
547 544
         }
548 545
         $select = [];
549 546
         foreach ($this->fields as $k => $field) {
550
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
547
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
551 548
         }
552 549
         foreach ($this->withr as $name => $relation) {
553 550
             foreach ($relation[0]->table->getColumns() as $column) {
554
-                $select[] = $name . '.' . $column . ' ' . $name . static::SEP . $column;
551
+                $select[] = $name.'.'.$column.' '.$name.static::SEP.$column;
555 552
             }
556 553
         }
557 554
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
558 555
         $par = [];
559 556
         foreach ($this->joins as $k => $v) {
560
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
557
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
561 558
             $tmp = [];
562 559
             foreach ($v->keymap as $kk => $vv) {
563 560
                 $tmp[] = $kk.' = '.$vv;
564 561
             }
565
-            $sql .= implode(' AND ', $tmp) . ' ';
562
+            $sql .= implode(' AND ', $tmp).' ';
566 563
         }
567 564
         foreach ($relations as $relation => $v) {
568 565
             $table = $v[1];
@@ -573,13 +570,13 @@  discard block
 block discarded – undo
573 570
                 foreach ($v->keymap as $kk => $vv) {
574 571
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' ';
575 572
                 }
576
-                $sql .= implode(' AND ', $tmp) . ' ';
573
+                $sql .= implode(' AND ', $tmp).' ';
577 574
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
578 575
                 $tmp = [];
579 576
                 foreach ($v->pivot_keymap as $kk => $vv) {
580 577
                     $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' ';
581 578
                 }
582
-                $sql .= implode(' AND ', $tmp) . ' ';
579
+                $sql .= implode(' AND ', $tmp).' ';
583 580
             } else {
584 581
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
585 582
                 $tmp = [];
@@ -587,65 +584,65 @@  discard block
 block discarded – undo
587 584
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' ';
588 585
                 }
589 586
                 if ($v->sql) {
590
-                    $tmp[] = $v->sql . ' ';
587
+                    $tmp[] = $v->sql.' ';
591 588
                     $par = array_merge($par, $v->par ?? []);
592 589
                 }
593
-                $sql .= implode(' AND ', $tmp) . ' ';
590
+                $sql .= implode(' AND ', $tmp).' ';
594 591
             }
595 592
         }
596 593
         if (count($this->where)) {
597 594
             $sql .= 'WHERE ';
598 595
             $tmp = [];
599 596
             foreach ($this->where as $v) {
600
-                $tmp[] = '(' . $v[0] . ')';
597
+                $tmp[] = '('.$v[0].')';
601 598
                 $par = array_merge($par, $v[1]);
602 599
             }
603 600
             $sql .= implode(' AND ', $tmp).' ';
604 601
         }
605 602
         if (count($this->group)) {
606
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
603
+            $sql .= 'GROUP BY '.$this->group[0].' ';
607 604
             $par = array_merge($par, $this->group[1]);
608 605
         }
609 606
         if (count($this->having)) {
610 607
             $sql .= 'HAVING ';
611 608
             $tmp = [];
612 609
             foreach ($this->having as $v) {
613
-                $tmp[] = '(' . $v[0] . ')';
610
+                $tmp[] = '('.$v[0].')';
614 611
                 $par = array_merge($par, $v[1]);
615 612
             }
616 613
             $sql .= implode(' AND ', $tmp).' ';
617 614
         }
618 615
         if (count($this->order)) {
619
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
616
+            $sql .= 'ORDER BY '.$this->order[0].' ';
620 617
             $par = array_merge($par, $this->order[1]);
621 618
         }
622 619
         $porder = [];
623 620
         foreach ($primary as $field) {
624 621
             $porder[] = $this->getColumn($field)['name'];
625 622
         }
626
-        $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
623
+        $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
627 624
 
628 625
         if ($this->li_of[0]) {
629 626
             if ($this->db->driverName() === 'oracle') {
630
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
631
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
627
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
628
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
632 629
                 } else {
633
-                    $f = array_map(function ($v) {
630
+                    $f = array_map(function($v) {
634 631
                         $v = explode(' ', trim($v), 2);
635 632
                         if (count($v) === 2) { return $v[1]; }
636 633
                         $v = explode('.', $v[0], 2);
637 634
                         return count($v) === 2 ? $v[1] : $v[0];
638 635
                     }, $select);
639
-                    $sql = "SELECT " . implode(', ', $f) . " 
636
+                    $sql = "SELECT ".implode(', ', $f)." 
640 637
                             FROM (
641 638
                                 SELECT tbl__.*, rownum rnum__ FROM (
642
-                                    " . $sql . "
639
+                                    " . $sql."
643 640
                                 ) tbl__ 
644
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
641
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
645 642
                             ) WHERE rnum__ > " . $this->li_of[1];
646 643
                 }
647 644
             } else {
648
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
645
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
649 646
             }
650 647
         }
651 648
         return $this->qiterator = new TableQueryIterator(
@@ -690,7 +687,7 @@  discard block
 block discarded – undo
690 687
                 $ret[$k] = str_repeat(' ', 255);
691 688
                 $par[] = &$ret[$k];
692 689
             }
693
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
690
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
694 691
             $this->db->query($sql, $par);
695 692
             return $ret;
696 693
         } else {
@@ -722,7 +719,7 @@  discard block
 block discarded – undo
722 719
         }
723 720
         $sql = 'UPDATE '.$table.' SET ';
724 721
         $par = [];
725
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
722
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
726 723
         $par = array_merge($par, array_values($update));
727 724
         if (count($this->where)) {
728 725
             $sql .= 'WHERE ';
@@ -731,7 +728,7 @@  discard block
 block discarded – undo
731 728
                 $tmp[] = $v[0];
732 729
                 $par = array_merge($par, $v[1]);
733 730
             }
734
-            $sql .= implode(' AND ', $tmp) . ' ';
731
+            $sql .= implode(' AND ', $tmp).' ';
735 732
         }
736 733
         if (count($this->order)) {
737 734
             $sql .= $this->order[0];
@@ -755,7 +752,7 @@  discard block
 block discarded – undo
755 752
                 $tmp[] = $v[0];
756 753
                 $par = array_merge($par, $v[1]);
757 754
             }
758
-            $sql .= implode(' AND ', $tmp) . ' ';
755
+            $sql .= implode(' AND ', $tmp).' ';
759 756
         }
760 757
         if (count($this->order)) {
761 758
             $sql .= $this->order[0];
@@ -775,13 +772,13 @@  discard block
 block discarded – undo
775 772
         $table = $this->definition;
776 773
         array_reduce(
777 774
             $parts,
778
-            function ($carry, $item) use (&$table) {
775
+            function($carry, $item) use (&$table) {
779 776
                 $relation = $table->getRelation($item);
780 777
                 if (!$relation) {
781 778
                     throw new DBException('Invalid relation name');
782 779
                 }
783
-                $name = $carry ? $carry . static::SEP . $item : $item;
784
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
780
+                $name = $carry ? $carry.static::SEP.$item : $item;
781
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
785 782
                 $table = $relation->table;
786 783
                 return $name;
787 784
             }
Please login to merge, or discard this patch.
src/driver/oracle/Driver.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
         $columns = Collection::from($this
125 125
             ->query(
126 126
                 "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?",
127
-                [ strtoupper($table), $this->name() ]
127
+                [strtoupper($table), $this->name()]
128 128
             ))
129
-            ->map(function ($v) {
129
+            ->map(function($v) {
130 130
                 $new = [];
131 131
                 foreach ($v as $kk => $vv) {
132 132
                     $new[strtoupper($kk)] = $vv;
133 133
                 }
134 134
                 return $new;
135 135
             })
136
-            ->mapKey(function ($v) { return $v['COLUMN_NAME']; })
136
+            ->mapKey(function($v) { return $v['COLUMN_NAME']; })
137 137
             ->toArray();
138 138
         if (!count($columns)) {
139 139
             throw new DBException('Table not found by name');
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
             ->query(
144 144
                 "SELECT constraint_name FROM all_constraints
145 145
                 WHERE table_name = ? AND constraint_type = ? AND owner = ?",
146
-                [ strtoupper($table), 'P', $owner ]
146
+                [strtoupper($table), 'P', $owner]
147 147
             ))
148
-            ->map(function ($v) {
148
+            ->map(function($v) {
149 149
                 $new = [];
150 150
                 foreach ($v as $kk => $vv) {
151 151
                     $new[strtoupper($kk)] = $vv;
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
                 ->query(
161 161
                     "SELECT column_name FROM all_cons_columns
162 162
                     WHERE table_name = ? AND constraint_name = ? AND owner = ?",
163
-                    [ strtoupper($table), $pkname, $owner ]
163
+                    [strtoupper($table), $pkname, $owner]
164 164
                 ))
165
-                ->map(function ($v) {
165
+                ->map(function($v) {
166 166
                     $new = [];
167 167
                     foreach ($v as $kk => $vv) {
168 168
                         $new[strtoupper($kk)] = $vv;
@@ -189,9 +189,9 @@  discard block
 block discarded – undo
189 189
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
190 190
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
191 191
                     ORDER BY cc.POSITION",
192
-                    [ $owner, $owner, $pkname, 'R' ]
192
+                    [$owner, $owner, $pkname, 'R']
193 193
                 ))
194
-                ->map(function ($v) {
194
+                ->map(function($v) {
195 195
                     $new = [];
196 196
                     foreach ($v as $kk => $vv) {
197 197
                         $new[strtoupper($kk)] = $vv;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                  as $relation
202 202
             ) {
203 203
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
204
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME'];
204
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME'];
205 205
             }
206 206
             foreach ($relations as $data) {
207 207
                 $rtable = $this->table($data['table'], true);
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
                                 ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
226 226
                                 cc.COLUMN_NAME IN (??)
227 227
                             ORDER BY POSITION",
228
-                            [ $owner, $owner, $data['table'], 'R', $columns ]
228
+                            [$owner, $owner, $data['table'], 'R', $columns]
229 229
                         ))
230
-                        ->map(function ($v) {
230
+                        ->map(function($v) {
231 231
                             $new = [];
232 232
                             foreach ($v as $kk => $vv) {
233 233
                                 $new[strtoupper($kk)] = $vv;
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
                     $rcolumns = Collection::from($this
246 246
                         ->query(
247 247
                             "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
248
-                            [ $owner, current($foreign['keymap']) ]
248
+                            [$owner, current($foreign['keymap'])]
249 249
                         ))
250
-                        ->map(function ($v) {
250
+                        ->map(function($v) {
251 251
                             $new = [];
252 252
                             foreach ($v as $kk => $vv) {
253 253
                                 $new[strtoupper($kk)] = $vv;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
                     $relname = $foreign['table'];
263 263
                     $cntr = 1;
264 264
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
265
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
265
+                        $relname = $foreign['table'].'_'.(++$cntr);
266 266
                     }
267 267
                     $definition->addRelation(
268 268
                         new TableRelation(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
                     $relname = $data['table'];
279 279
                     $cntr = 1;
280 280
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
281
-                        $relname = $data['table'] . '_' . (++ $cntr);
281
+                        $relname = $data['table'].'_'.(++$cntr);
282 282
                     }
283 283
                     $definition->addRelation(
284 284
                         new TableRelation(
@@ -302,9 +302,9 @@  discard block
 block discarded – undo
302 302
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
303 303
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
304 304
                     ORDER BY cc.POSITION",
305
-                    [ $owner, $owner, strtoupper($table), 'R' ]
305
+                    [$owner, $owner, strtoupper($table), 'R']
306 306
                 ))
307
-                ->map(function ($v) {
307
+                ->map(function($v) {
308 308
                     $new = [];
309 309
                     foreach ($v as $kk => $vv) {
310 310
                         $new[strtoupper($kk)] = $vv;
@@ -320,9 +320,9 @@  discard block
 block discarded – undo
320 320
                 $rcolumns = Collection::from($this
321 321
                     ->query(
322 322
                         "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
323
-                        [ $owner, current($data['keymap']) ]
323
+                        [$owner, current($data['keymap'])]
324 324
                     ))
325
-                    ->map(function ($v) {
325
+                    ->map(function($v) {
326 326
                         $new = [];
327 327
                         foreach ($v as $kk => $vv) {
328 328
                             $new[strtoupper($kk)] = $vv;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                 $relname = $data['table'];
338 338
                 $cntr = 1;
339 339
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
340
-                    $relname = $data['table'] . '_' . (++ $cntr);
340
+                    $relname = $data['table'].'_'.(++$cntr);
341 341
                 }
342 342
                 $definition->addRelation(
343 343
                     new TableRelation(
@@ -358,7 +358,7 @@  discard block
 block discarded – undo
358 358
                 "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?",
359 359
                 [$this->connection['name']]
360 360
             ))
361
-            ->map(function ($v) {
361
+            ->map(function($v) {
362 362
                 $new = [];
363 363
                 foreach ($v as $kk => $vv) {
364 364
                     $new[strtoupper($kk)] = $vv;
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
                 return $new;
367 367
             })
368 368
             ->pluck('TABLE_NAME')
369
-            ->map(function ($v) {
369
+            ->map(function($v) {
370 370
                 return $this->table($v);
371 371
             })
372 372
             ->toArray();
Please login to merge, or discard this patch.