Completed
Push — master ( 37635b...73994c )
by Ivan
02:45
created
src/schema/TableQuery.php 1 patch
Spacing   +168 added lines, -172 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     /**
45 45
      * @var int[]
46 46
      */
47
-    protected $li_of = [0,0,0];
47
+    protected $li_of = [0, 0, 0];
48 48
     /**
49 49
      * @var array
50 50
      */
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public function __construct(DBInterface $db, $table)
75 75
     {
76 76
         $this->db = $db;
77
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
77
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
78 78
         $primary = $this->definition->getPrimaryKey();
79 79
         $columns = $this->definition->getColumns();
80 80
         $this->pkey = count($primary) ? $primary : $columns;
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $column = explode('.', $column);
99 99
         if (count($column) === 1) {
100
-            $column = [ $this->definition->getName(), $column[0] ];
100
+            $column = [$this->definition->getName(), $column[0]];
101 101
             $col = $this->definition->getColumn($column[1]);
102 102
             if (!$col) {
103 103
                 throw new DBException('Invalid column name in own table');
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                         throw new DBException('Invalid column name in related table');
121 121
                     }
122 122
                 } else {
123
-                    throw new DBException('Invalid foreign table name: ' . implode(',', $column));
123
+                    throw new DBException('Invalid foreign table name: '.implode(',', $column));
124 124
                 }
125 125
             }
126 126
         } else {
@@ -129,19 +129,19 @@  discard block
 block discarded – undo
129 129
             $table = $this->definition;
130 130
             $table = array_reduce(
131 131
                 $column,
132
-                function ($carry, $item) use (&$table) {
132
+                function($carry, $item) use (&$table) {
133 133
                     $table = $table->getRelation($item)->table;
134 134
                     return $table;
135 135
                 }
136 136
             );
137 137
             $col = $table->getColumn($name);
138
-            $column = [ implode(static::SEP, $column), $name ];
138
+            $column = [implode(static::SEP, $column), $name];
139 139
         }
140
-        return [ 'name' => implode('.', $column), 'data' => $col ];
140
+        return ['name' => implode('.', $column), 'data' => $col];
141 141
     }
142 142
     protected function normalizeValue(TableColumn $col, $value)
143 143
     {
144
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
144
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
145 145
         if ($value === null && $col->isNullable()) {
146 146
             return null;
147 147
         }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
                     $temp = strtotime($value);
152 152
                     if (!$temp) {
153 153
                         if ($strict) {
154
-                            throw new DBException('Invalid value for date column ' . $col->getName());
154
+                            throw new DBException('Invalid value for date column '.$col->getName());
155 155
                         }
156 156
                         return null;
157 157
                     }
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                     return $value->format('Y-m-d');
165 165
                 }
166 166
                 if ($strict) {
167
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
167
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
168 168
                 }
169 169
                 return $value;
170 170
             case 'datetime':
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
                     $temp = strtotime($value);
173 173
                     if (!$temp) {
174 174
                         if ($strict) {
175
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
175
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
176 176
                         }
177 177
                         return null;
178 178
                     }
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                     return $value->format('Y-m-d H:i:s');
186 186
                 }
187 187
                 if ($strict) {
188
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
188
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
189 189
                 }
190 190
                 return $value;
191 191
             case 'enum':
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                 if (is_int($value)) {
194 194
                     if (!isset($values[$value])) {
195 195
                         if ($strict) {
196
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
196
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
197 197
                         }
198 198
                         return $value;
199 199
                     }
@@ -201,21 +201,21 @@  discard block
 block discarded – undo
201 201
                 }
202 202
                 if (!in_array($value, $col->getValues())) {
203 203
                     if ($strict) {
204
-                        throw new DBException('Invalid value for enum ' . $col->getName());
204
+                        throw new DBException('Invalid value for enum '.$col->getName());
205 205
                     }
206 206
                     return 0;
207 207
                 }
208 208
                 return $value;
209 209
             case 'int':
210
-                return (int)preg_replace('([^+\-0-9]+)', '', $value);
210
+                return (int) preg_replace('([^+\-0-9]+)', '', $value);
211 211
             case 'float':
212
-                return (float)preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
212
+                return (float) preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
213 213
             case 'text':
214 214
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
215 215
                 // because the polyfill is quite slow
216 216
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
217 217
                     if ($strict) {
218
-                        throw new DBException('Invalid value for text column ' . $col->getName());
218
+                        throw new DBException('Invalid value for text column '.$col->getName());
219 219
                     }
220 220
                     return mb_substr($value, 0, $col->getLength());
221 221
                 }
@@ -237,35 +237,32 @@  discard block
 block discarded – undo
237 237
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
238 238
             return $negate ?
239 239
                 [
240
-                    $name . ' NOT LIKE ?',
241
-                    [ $this->normalizeValue($column, $value) ]
242
-                ] :
243
-                [
244
-                    $name . ' LIKE ?',
245
-                    [ $this->normalizeValue($column, $value) ]
240
+                    $name.' NOT LIKE ?',
241
+                    [$this->normalizeValue($column, $value)]
242
+                ] : [
243
+                    $name.' LIKE ?',
244
+                    [$this->normalizeValue($column, $value)]
246 245
                 ];
247 246
         }
248 247
         if (is_null($value)) {
249 248
             return $negate ?
250
-                [ $name . ' IS NOT NULL', [] ]:
251
-                [ $name . ' IS NULL', [] ];
249
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
252 250
         }
253 251
         if (!is_array($value)) {
254 252
             return $negate ?
255 253
                 [
256
-                    $name . ' <> ?',
257
-                    [ $this->normalizeValue($column, $value) ]
258
-                ] :
259
-                [
260
-                    $name . ' = ?',
261
-                    [ $this->normalizeValue($column, $value) ]
254
+                    $name.' <> ?',
255
+                    [$this->normalizeValue($column, $value)]
256
+                ] : [
257
+                    $name.' = ?',
258
+                    [$this->normalizeValue($column, $value)]
262 259
                 ];
263 260
         }
264 261
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
265
-            $value = [ 'gte' => $value['beg'] ];
262
+            $value = ['gte' => $value['beg']];
266 263
         }
267 264
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
268
-            $value = [ 'lte' => $value['end'] ];
265
+            $value = ['lte' => $value['end']];
269 266
         }
270 267
         if (isset($value['beg']) && isset($value['end'])) {
271 268
             return $negate ?
@@ -275,8 +272,7 @@  discard block
 block discarded – undo
275 272
                         $this->normalizeValue($column, $value['beg']),
276 273
                         $this->normalizeValue($column, $value['end'])
277 274
                     ]
278
-                ] :
279
-                [
275
+                ] : [
280 276
                     $name.' BETWEEN ? AND ?',
281 277
                     [
282 278
                         $this->normalizeValue($column, $value['beg']),
@@ -288,34 +284,34 @@  discard block
 block discarded – undo
288 284
             $sql = [];
289 285
             $par = [];
290 286
             if (isset($value['gt'])) {
291
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
287
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
292 288
                 $par[] = $this->normalizeValue($column, $value['gt']);
293 289
             }
294 290
             if (isset($value['gte'])) {
295
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
291
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
296 292
                 $par[] = $this->normalizeValue($column, $value['gte']);
297 293
             }
298 294
             if (isset($value['lt'])) {
299
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
295
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
300 296
                 $par[] = $this->normalizeValue($column, $value['lt']);
301 297
             }
302 298
             if (isset($value['lte'])) {
303
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
299
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
304 300
                 $par[] = $this->normalizeValue($column, $value['lte']);
305 301
             }
306 302
             return [
307
-                '(' . implode(' AND ', $sql) . ')',
303
+                '('.implode(' AND ', $sql).')',
308 304
                 $par
309 305
             ];
310 306
         }
311 307
         return $negate ?
312 308
             [
313
-                $name . ' NOT IN (??)',
314
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
309
+                $name.' NOT IN (??)',
310
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
315 311
             ] :
316 312
             [
317
-                $name . ' IN (??)',
318
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
313
+                $name.' IN (??)',
314
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
319 315
             ];
320 316
     }
321 317
     /**
@@ -346,7 +342,7 @@  discard block
 block discarded – undo
346 342
                 $par = array_merge($par, $temp[1]);
347 343
             }
348 344
         }
349
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
345
+        return $this->where('('.implode(' OR ', $sql).')', $par);
350 346
     }
351 347
     /**
352 348
      * Filter the results matching all of the criteria
@@ -364,7 +360,7 @@  discard block
 block discarded – undo
364 360
                 $par = array_merge($par, $temp[1]);
365 361
             }
366 362
         }
367
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
363
+        return $this->where('('.implode(' AND ', $sql).')', $par);
368 364
     }
369 365
     /**
370 366
      * Sort by a column
@@ -374,7 +370,7 @@  discard block
 block discarded – undo
374 370
      */
375 371
     public function sort(string $column, bool $desc = false) : TableQuery
376 372
     {
377
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
373
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
378 374
     }
379 375
     /**
380 376
      * Group by a column (or columns)
@@ -384,7 +380,7 @@  discard block
 block discarded – undo
384 380
     public function group($column) : TableQuery
385 381
     {
386 382
         if (!is_array($column)) {
387
-            $column = [ $column ];
383
+            $column = [$column];
388 384
         }
389 385
         foreach ($column as $k => $v) {
390 386
             $column[$k] = $this->getColumn($v)['name'];
@@ -426,7 +422,7 @@  discard block
 block discarded – undo
426 422
         $this->order = [];
427 423
         $this->having = [];
428 424
         $this->aliases = [];
429
-        $this->li_of = [0,0,0];
425
+        $this->li_of = [0, 0, 0];
430 426
         $this->qiterator = null;
431 427
         return $this;
432 428
     }
@@ -439,7 +435,7 @@  discard block
 block discarded – undo
439 435
     public function groupBy(string $sql, array $params = []) : TableQuery
440 436
     {
441 437
         $this->qiterator = null;
442
-        $this->group = [ $sql, $params ];
438
+        $this->group = [$sql, $params];
443 439
         return $this;
444 440
     }
445 441
     /**
@@ -452,7 +448,7 @@  discard block
 block discarded – undo
452 448
      */
453 449
     public function join($table, array $fields, string $name = null, bool $multiple = true)
454 450
     {
455
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
451
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
456 452
         $name = $name ?? $table->getName();
457 453
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
458 454
             throw new DBException('Alias / table name already in use');
@@ -461,7 +457,7 @@  discard block
 block discarded – undo
461 457
         foreach ($fields as $k => $v) {
462 458
             $k = explode('.', $k, 2);
463 459
             $k = count($k) == 2 ? $k[1] : $k[0];
464
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
460
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
465 461
         }
466 462
         return $this;
467 463
     }
@@ -474,7 +470,7 @@  discard block
 block discarded – undo
474 470
     public function where(string $sql, array $params = []) : TableQuery
475 471
     {
476 472
         $this->qiterator = null;
477
-        $this->where[] = [ $sql, $params ];
473
+        $this->where[] = [$sql, $params];
478 474
         return $this;
479 475
     }
480 476
     /**
@@ -486,7 +482,7 @@  discard block
 block discarded – undo
486 482
     public function having(string $sql, array $params = []) : TableQuery
487 483
     {
488 484
         $this->qiterator = null;
489
-        $this->having[] = [ $sql, $params ];
485
+        $this->having[] = [$sql, $params];
490 486
         return $this;
491 487
     }
492 488
     /**
@@ -498,7 +494,7 @@  discard block
 block discarded – undo
498 494
     public function order(string $sql, array $params = []) : TableQuery
499 495
     {
500 496
         $this->qiterator = null;
501
-        $this->order = [ $sql, $params ];
497
+        $this->order = [$sql, $params];
502 498
         return $this;
503 499
     }
504 500
     /**
@@ -510,7 +506,7 @@  discard block
 block discarded – undo
510 506
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : TableQuery
511 507
     {
512 508
         $this->qiterator = null;
513
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
509
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
514 510
         return $this;
515 511
     }
516 512
     /**
@@ -520,9 +516,9 @@  discard block
 block discarded – undo
520 516
     public function count() : int
521 517
     {
522 518
         $aliases = [];
523
-        $getAlias = function ($name) use (&$aliases) {
519
+        $getAlias = function($name) use (&$aliases) {
524 520
             // to bypass use: return $name;
525
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
521
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
526 522
         };
527 523
         $table = $this->definition->getName();
528 524
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -537,44 +533,44 @@  discard block
 block discarded – undo
537 533
         $h = $this->having;
538 534
         $o = $this->order;
539 535
         $g = $this->group;
540
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
536
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
541 537
         foreach ($this->definition->getRelations() as $k => $v) {
542 538
             foreach ($w as $kk => $vv) {
543
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
544
-                    $relations[$k] = [ $v, $table ];
545
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
539
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
540
+                    $relations[$k] = [$v, $table];
541
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
546 542
                 }
547 543
             }
548
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
549
-                $relations[$k] = [ $v, $table ];
544
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
545
+                $relations[$k] = [$v, $table];
550 546
             }
551 547
             foreach ($h as $kk => $vv) {
552
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
553
-                    $relations[$k] = [ $relation, $table ];
554
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
548
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
549
+                    $relations[$k] = [$relation, $table];
550
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
555 551
                 }
556 552
             }
557
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
558
-                $relations[$k] = [ $relation, $table ];
559
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
553
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
554
+                $relations[$k] = [$relation, $table];
555
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
560 556
             }
561 557
             foreach ($j as $kk => $v) {
562 558
                 foreach ($v->keymap as $kkk => $vv) {
563
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
564
-                        $relations[$k] = [ $relation, $table ];
565
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
559
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
560
+                        $relations[$k] = [$relation, $table];
561
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
566 562
                     }
567 563
                 }
568 564
             }
569 565
         }
570 566
 
571 567
         foreach ($j as $k => $v) {
572
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
568
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
573 569
             $tmp = [];
574 570
             foreach ($v->keymap as $kk => $vv) {
575 571
                 $tmp[] = $kk.' = '.$vv;
576 572
             }
577
-            $sql .= implode(' AND ', $tmp) . ' ';
573
+            $sql .= implode(' AND ', $tmp).' ';
578 574
         }
579 575
         foreach ($relations as $k => $v) {
580 576
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -586,13 +582,13 @@  discard block
 block discarded – undo
586 582
                 foreach ($v->keymap as $kk => $vv) {
587 583
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
588 584
                 }
589
-                $sql .= implode(' AND ', $tmp) . ' ';
585
+                $sql .= implode(' AND ', $tmp).' ';
590 586
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
591 587
                 $tmp = [];
592 588
                 foreach ($v->pivot_keymap as $kk => $vv) {
593 589
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
594 590
                 }
595
-                $sql .= implode(' AND ', $tmp) . ' ';
591
+                $sql .= implode(' AND ', $tmp).' ';
596 592
             } else {
597 593
                 $alias = $getAlias($k);
598 594
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -601,30 +597,30 @@  discard block
 block discarded – undo
601 597
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
602 598
                 }
603 599
                 if ($v->sql) {
604
-                    $tmp[] = $v->sql . ' ';
600
+                    $tmp[] = $v->sql.' ';
605 601
                     $par = array_merge($par, $v->par ?? []);
606 602
                 }
607
-                $sql .= implode(' AND ', $tmp) . ' ';
603
+                $sql .= implode(' AND ', $tmp).' ';
608 604
             }
609 605
         }
610 606
         if (count($w)) {
611 607
             $sql .= 'WHERE ';
612 608
             $tmp = [];
613 609
             foreach ($w as $v) {
614
-                $tmp[] = '(' . $v[0] . ')';
610
+                $tmp[] = '('.$v[0].')';
615 611
                 $par = array_merge($par, $v[1]);
616 612
             }
617 613
             $sql .= implode(' AND ', $tmp).' ';
618 614
         }
619 615
         if (count($g)) {
620
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
616
+            $sql .= 'GROUP BY '.$g[0].' ';
621 617
             $par = array_merge($par, $g[1]);
622 618
         }
623 619
         if (count($h)) {
624 620
             $sql .= 'HAVING ';
625 621
             $tmp = [];
626 622
             foreach ($h as $v) {
627
-                $tmp[] = '(' . $v[0] . ')';
623
+                $tmp[] = '('.$v[0].')';
628 624
                 $par = array_merge($par, $v[1]);
629 625
             }
630 626
             $sql .= implode(' AND ', $tmp).' ';
@@ -658,7 +654,7 @@  discard block
 block discarded – undo
658 654
                     $this->with(implode('.', $temp));
659 655
                     $table = array_reduce(
660 656
                         $temp,
661
-                        function ($carry, $item) use (&$table) {
657
+                        function($carry, $item) use (&$table) {
662 658
                             return $table->getRelation($item)->table;
663 659
                         }
664 660
                     );
@@ -667,7 +663,7 @@  discard block
 block discarded – undo
667 663
                 }
668 664
                 unset($fields[$k]);
669 665
                 foreach ($cols as $col) {
670
-                    $fields[] = $table . '.' . $col;
666
+                    $fields[] = $table.'.'.$col;
671 667
                 }
672 668
             }
673 669
         }
@@ -699,9 +695,9 @@  discard block
 block discarded – undo
699 695
             return $this->qiterator;
700 696
         }
701 697
         $aliases = [];
702
-        $getAlias = function ($name) use (&$aliases) {
698
+        $getAlias = function($name) use (&$aliases) {
703 699
             // to bypass use: return $name;
704
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
700
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
705 701
         };
706 702
         $table = $this->definition->getName();
707 703
         if ($fields !== null) {
@@ -717,7 +713,7 @@  discard block
 block discarded – undo
717 713
         $h = $this->having;
718 714
         $o = $this->order;
719 715
         $g = $this->group;
720
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
716
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
721 717
 
722 718
         $porder = [];
723 719
         foreach ($this->definition->getPrimaryKey() as $field) {
@@ -730,9 +726,9 @@  discard block
 block discarded – undo
730 726
                 if (count($porder) > 1) {
731 727
                     $pkw = [];
732 728
                     foreach ($porder as $name) {
733
-                        $pkw[] = $name . ' = ?';
729
+                        $pkw[] = $name.' = ?';
734 730
                     }
735
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
731
+                    $pkw = '('.implode(' AND ', $pkw).')';
736 732
                     $pkp = [];
737 733
                     foreach ($ids as $id) {
738 734
                         foreach ($id as $p) {
@@ -744,67 +740,67 @@  discard block
 block discarded – undo
744 740
                         $pkp
745 741
                     ];
746 742
                 } else {
747
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
743
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
748 744
                 }
749 745
             } else {
750
-                $w[] = [ '1=0', [] ];
746
+                $w[] = ['1=0', []];
751 747
             }
752 748
         }
753 749
 
754 750
         foreach ($this->definition->getRelations() as $k => $relation) {
755 751
             foreach ($f as $kk => $field) {
756
-                if (strpos($field, $k . '.') === 0) {
757
-                    $relations[$k] = [ $relation, $table ];
758
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
752
+                if (strpos($field, $k.'.') === 0) {
753
+                    $relations[$k] = [$relation, $table];
754
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
759 755
                 }
760 756
             }
761 757
             foreach ($w as $kk => $v) {
762
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
763
-                    $relations[$k] = [ $relation, $table ];
764
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
758
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
759
+                    $relations[$k] = [$relation, $table];
760
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
765 761
                 }
766 762
             }
767 763
             foreach ($h as $kk => $v) {
768
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
769
-                    $relations[$k] = [ $relation, $table ];
770
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
764
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
765
+                    $relations[$k] = [$relation, $table];
766
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
771 767
                 }
772 768
             }
773
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
774
-                $relations[$k] = [ $relation, $table ];
775
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
769
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
770
+                $relations[$k] = [$relation, $table];
771
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
776 772
             }
777
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
778
-                $relations[$k] = [ $relation, $table ];
779
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
773
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
774
+                $relations[$k] = [$relation, $table];
775
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
780 776
             }
781 777
             foreach ($j as $kk => $v) {
782 778
                 foreach ($v->keymap as $kkk => $vv) {
783
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
784
-                        $relations[$k] = [ $relation, $table ];
785
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
779
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
780
+                        $relations[$k] = [$relation, $table];
781
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
786 782
                     }
787 783
                 }
788 784
             }
789 785
         }
790 786
         $select = [];
791 787
         foreach ($f as $k => $field) {
792
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
788
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
793 789
         }
794 790
         foreach ($this->withr as $name => $relation) {
795 791
             foreach ($relation[0]->table->getColumns() as $column) {
796
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
792
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
797 793
             }
798 794
         }
799 795
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
800 796
         $par = [];
801 797
         foreach ($j as $k => $v) {
802
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
798
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
803 799
             $tmp = [];
804 800
             foreach ($v->keymap as $kk => $vv) {
805 801
                 $tmp[] = $kk.' = '.$vv;
806 802
             }
807
-            $sql .= implode(' AND ', $tmp) . ' ';
803
+            $sql .= implode(' AND ', $tmp).' ';
808 804
         }
809 805
         foreach ($relations as $relation => $v) {
810 806
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -816,13 +812,13 @@  discard block
 block discarded – undo
816 812
                 foreach ($v->keymap as $kk => $vv) {
817 813
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
818 814
                 }
819
-                $sql .= implode(' AND ', $tmp) . ' ';
815
+                $sql .= implode(' AND ', $tmp).' ';
820 816
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($relation).' ON ';
821 817
                 $tmp = [];
822 818
                 foreach ($v->pivot_keymap as $kk => $vv) {
823 819
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
824 820
                 }
825
-                $sql .= implode(' AND ', $tmp) . ' ';
821
+                $sql .= implode(' AND ', $tmp).' ';
826 822
             } else {
827 823
                 $alias = $getAlias($relation);
828 824
 
@@ -832,62 +828,62 @@  discard block
 block discarded – undo
832 828
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
833 829
                 }
834 830
                 if ($v->sql) {
835
-                    $tmp[] = $v->sql . ' ';
831
+                    $tmp[] = $v->sql.' ';
836 832
                     $par = array_merge($par, $v->par ?? []);
837 833
                 }
838
-                $sql .= implode(' AND ', $tmp) . ' ';
834
+                $sql .= implode(' AND ', $tmp).' ';
839 835
             }
840 836
         }
841 837
         if (count($w)) {
842 838
             $sql .= 'WHERE ';
843 839
             $tmp = [];
844 840
             foreach ($w as $v) {
845
-                $tmp[] = '(' . $v[0] . ')';
841
+                $tmp[] = '('.$v[0].')';
846 842
                 $par = array_merge($par, $v[1]);
847 843
             }
848 844
             $sql .= implode(' AND ', $tmp).' ';
849 845
         }
850 846
         if (count($g)) {
851
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
847
+            $sql .= 'GROUP BY '.$g[0].' ';
852 848
             $par = array_merge($par, $g[1]);
853 849
         }
854 850
         if (count($h)) {
855 851
             $sql .= 'HAVING ';
856 852
             $tmp = [];
857 853
             foreach ($h as $v) {
858
-                $tmp[] = '(' . $v[0] . ')';
854
+                $tmp[] = '('.$v[0].')';
859 855
                 $par = array_merge($par, $v[1]);
860 856
             }
861 857
             $sql .= implode(' AND ', $tmp).' ';
862 858
         }
863 859
         if (count($o)) {
864
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
860
+            $sql .= 'ORDER BY '.$o[0].' ';
865 861
             $par = array_merge($par, $o[1]);
866 862
         }
867 863
         if (count($porder)) {
868
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
864
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
869 865
         }
870 866
         if (($this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
871 867
             if ($this->db->driverName() === 'oracle') {
872
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
873
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
868
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
869
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
874 870
                 } else {
875
-                    $f = array_map(function ($v) {
871
+                    $f = array_map(function($v) {
876 872
                         $v = explode(' ', trim($v), 2);
877 873
                         if (count($v) === 2) { return $v[1]; }
878 874
                         $v = explode('.', $v[0], 2);
879 875
                         return count($v) === 2 ? $v[1] : $v[0];
880 876
                     }, $select);
881
-                    $sql = "SELECT " . implode(', ', $f) . " 
877
+                    $sql = "SELECT ".implode(', ', $f)." 
882 878
                             FROM (
883 879
                                 SELECT tbl__.*, rownum rnum__ FROM (
884
-                                    " . $sql . "
880
+                                    " . $sql."
885 881
                                 ) tbl__ 
886
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
882
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
887 883
                             ) WHERE rnum__ > " . $this->li_of[1];
888 884
                 }
889 885
             } else {
890
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
886
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
891 887
             }
892 888
         }
893 889
         return $this->qiterator = new TableQueryIterator(
@@ -937,7 +933,7 @@  discard block
 block discarded – undo
937 933
                 $ret[$k] = str_repeat(' ', 255);
938 934
                 $par[] = &$ret[$k];
939 935
             }
940
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
936
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
941 937
             $this->db->query($sql, $par);
942 938
             return $ret;
943 939
         } else {
@@ -969,7 +965,7 @@  discard block
 block discarded – undo
969 965
         }
970 966
         $sql = 'UPDATE '.$table.' SET ';
971 967
         $par = [];
972
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
968
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
973 969
         $par = array_merge($par, array_values($update));
974 970
         if (count($this->where)) {
975 971
             $sql .= 'WHERE ';
@@ -978,7 +974,7 @@  discard block
 block discarded – undo
978 974
                 $tmp[] = $v[0];
979 975
                 $par = array_merge($par, $v[1]);
980 976
             }
981
-            $sql .= implode(' AND ', $tmp) . ' ';
977
+            $sql .= implode(' AND ', $tmp).' ';
982 978
         }
983 979
         if (count($this->order)) {
984 980
             $sql .= $this->order[0];
@@ -1002,7 +998,7 @@  discard block
 block discarded – undo
1002 998
                 $tmp[] = $v[0];
1003 999
                 $par = array_merge($par, $v[1]);
1004 1000
             }
1005
-            $sql .= implode(' AND ', $tmp) . ' ';
1001
+            $sql .= implode(' AND ', $tmp).' ';
1006 1002
         }
1007 1003
         if (count($this->order)) {
1008 1004
             $sql .= $this->order[0];
@@ -1022,13 +1018,13 @@  discard block
 block discarded – undo
1022 1018
         $table = $this->definition;
1023 1019
         array_reduce(
1024 1020
             $parts,
1025
-            function ($carry, $item) use (&$table) {
1021
+            function($carry, $item) use (&$table) {
1026 1022
                 $relation = $table->getRelation($item);
1027 1023
                 if (!$relation) {
1028 1024
                     throw new DBException('Invalid relation name');
1029 1025
                 }
1030
-                $name = $carry ? $carry . static::SEP . $item : $item;
1031
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
1026
+                $name = $carry ? $carry.static::SEP.$item : $item;
1027
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
1032 1028
                 $table = $relation->table;
1033 1029
                 return $name;
1034 1030
             }
@@ -1066,9 +1062,9 @@  discard block
 block discarded – undo
1066 1062
     public function ids()
1067 1063
     {
1068 1064
         $aliases = [];
1069
-        $getAlias = function ($name) use (&$aliases) {
1065
+        $getAlias = function($name) use (&$aliases) {
1070 1066
             // to bypass use: return $name;
1071
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1067
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1072 1068
         };
1073 1069
         $table = $this->definition->getName();
1074 1070
         $sql = 'SELECT DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).' FROM '.$table.' ';
@@ -1083,45 +1079,45 @@  discard block
 block discarded – undo
1083 1079
         $h = $this->having;
1084 1080
         $o = $this->order;
1085 1081
         $g = $this->group;
1086
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
1082
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
1087 1083
         foreach ($this->definition->getRelations() as $k => $v) {
1088 1084
             foreach ($w as $kk => $vv) {
1089
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1090
-                    $relations[$k] = [ $v, $table ];
1091
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1085
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1086
+                    $relations[$k] = [$v, $table];
1087
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1092 1088
                 }
1093 1089
             }
1094
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1095
-                $relations[$k] = [ $v, $table ];
1096
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1090
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1091
+                $relations[$k] = [$v, $table];
1092
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1097 1093
             }
1098 1094
             foreach ($h as $kk => $vv) {
1099
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1100
-                    $relations[$k] = [ $relation, $table ];
1101
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1095
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1096
+                    $relations[$k] = [$relation, $table];
1097
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1102 1098
                 }
1103 1099
             }
1104
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1105
-                $relations[$k] = [ $relation, $table ];
1106
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1100
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1101
+                $relations[$k] = [$relation, $table];
1102
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1107 1103
             }
1108 1104
             foreach ($j as $kk => $v) {
1109 1105
                 foreach ($v->keymap as $kkk => $vv) {
1110
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1111
-                        $relations[$k] = [ $relation, $table ];
1112
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
1106
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1107
+                        $relations[$k] = [$relation, $table];
1108
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
1113 1109
                     }
1114 1110
                 }
1115 1111
             }
1116 1112
         }
1117 1113
 
1118 1114
         foreach ($j as $k => $v) {
1119
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1115
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1120 1116
             $tmp = [];
1121 1117
             foreach ($v->keymap as $kk => $vv) {
1122 1118
                 $tmp[] = $kk.' = '.$vv;
1123 1119
             }
1124
-            $sql .= implode(' AND ', $tmp) . ' ';
1120
+            $sql .= implode(' AND ', $tmp).' ';
1125 1121
         }
1126 1122
         foreach ($relations as $k => $v) {
1127 1123
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -1133,13 +1129,13 @@  discard block
 block discarded – undo
1133 1129
                 foreach ($v->keymap as $kk => $vv) {
1134 1130
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1135 1131
                 }
1136
-                $sql .= implode(' AND ', $tmp) . ' ';
1132
+                $sql .= implode(' AND ', $tmp).' ';
1137 1133
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1138 1134
                 $tmp = [];
1139 1135
                 foreach ($v->pivot_keymap as $kk => $vv) {
1140 1136
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1141 1137
                 }
1142
-                $sql .= implode(' AND ', $tmp) . ' ';
1138
+                $sql .= implode(' AND ', $tmp).' ';
1143 1139
             } else {
1144 1140
                 $alias = $getAlias($k);
1145 1141
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1148,36 +1144,36 @@  discard block
 block discarded – undo
1148 1144
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1149 1145
                 }
1150 1146
                 if ($v->sql) {
1151
-                    $tmp[] = $v->sql . ' ';
1147
+                    $tmp[] = $v->sql.' ';
1152 1148
                     $par = array_merge($par, $v->par ?? []);
1153 1149
                 }
1154
-                $sql .= implode(' AND ', $tmp) . ' ';
1150
+                $sql .= implode(' AND ', $tmp).' ';
1155 1151
             }
1156 1152
         }
1157 1153
         if (count($w)) {
1158 1154
             $sql .= 'WHERE ';
1159 1155
             $tmp = [];
1160 1156
             foreach ($w as $v) {
1161
-                $tmp[] = '(' . $v[0] . ')';
1157
+                $tmp[] = '('.$v[0].')';
1162 1158
                 $par = array_merge($par, $v[1]);
1163 1159
             }
1164 1160
             $sql .= implode(' AND ', $tmp).' ';
1165 1161
         }
1166 1162
         if (count($g)) {
1167
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1163
+            $sql .= 'GROUP BY '.$g[0].' ';
1168 1164
             $par = array_merge($par, $g[1]);
1169 1165
         }
1170 1166
         if (count($h)) {
1171 1167
             $sql .= 'HAVING ';
1172 1168
             $tmp = [];
1173 1169
             foreach ($h as $v) {
1174
-                $tmp[] = '(' . $v[0] . ')';
1170
+                $tmp[] = '('.$v[0].')';
1175 1171
                 $par = array_merge($par, $v[1]);
1176 1172
             }
1177 1173
             $sql .= implode(' AND ', $tmp).' ';
1178 1174
         }
1179 1175
         if (count($o)) {
1180
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1176
+            $sql .= 'ORDER BY '.$o[0].' ';
1181 1177
             $par = array_merge($par, $o[1]);
1182 1178
         }
1183 1179
         $porder = [];
@@ -1185,30 +1181,30 @@  discard block
 block discarded – undo
1185 1181
             $porder[] = $this->getColumn($field)['name'];
1186 1182
         }
1187 1183
         if (count($porder)) {
1188
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1184
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1189 1185
         }
1190 1186
 
1191 1187
         if ($this->li_of[0]) {
1192 1188
             if ($this->db->driverName() === 'oracle') {
1193
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1194
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1189
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1190
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1195 1191
                 } else {
1196
-                    $f = array_map(function ($v) {
1192
+                    $f = array_map(function($v) {
1197 1193
                         $v = explode(' ', trim($v), 2);
1198 1194
                         if (count($v) === 2) { return $v[1]; }
1199 1195
                         $v = explode('.', $v[0], 2);
1200 1196
                         return count($v) === 2 ? $v[1] : $v[0];
1201 1197
                     }, $select);
1202
-                    $sql = "SELECT " . implode(', ', $f) . " 
1198
+                    $sql = "SELECT ".implode(', ', $f)." 
1203 1199
                             FROM (
1204 1200
                                 SELECT tbl__.*, rownum rnum__ FROM (
1205
-                                    " . $sql . "
1201
+                                    " . $sql."
1206 1202
                                 ) tbl__ 
1207
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1203
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1208 1204
                             ) WHERE rnum__ > " . $this->li_of[1];
1209 1205
                 }
1210 1206
             } else {
1211
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1207
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1212 1208
             }
1213 1209
         }
1214 1210
         return $this->db->all($sql, $par);
Please login to merge, or discard this patch.