Completed
Push — master ( 131973...716178 )
by Ivan
03:01
created
src/schema/TableQuery.php 1 patch
Spacing   +177 added lines, -181 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
     /**
@@ -507,7 +503,7 @@  discard block
 block discarded – undo
507 503
                 $name = null;
508 504
             }
509 505
         }
510
-        $this->order = [ $sql, $params, $name ];
506
+        $this->order = [$sql, $params, $name];
511 507
         return $this;
512 508
     }
513 509
     /**
@@ -519,7 +515,7 @@  discard block
 block discarded – undo
519 515
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : TableQuery
520 516
     {
521 517
         $this->qiterator = null;
522
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
518
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
523 519
         return $this;
524 520
     }
525 521
     /**
@@ -529,9 +525,9 @@  discard block
 block discarded – undo
529 525
     public function count() : int
530 526
     {
531 527
         $aliases = [];
532
-        $getAlias = function ($name) use (&$aliases) {
528
+        $getAlias = function($name) use (&$aliases) {
533 529
             // to bypass use: return $name;
534
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
530
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
535 531
         };
536 532
         $table = $this->definition->getName();
537 533
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -546,44 +542,44 @@  discard block
 block discarded – undo
546 542
         $h = $this->having;
547 543
         $o = $this->order;
548 544
         $g = $this->group;
549
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
545
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
550 546
         foreach ($this->definition->getRelations() as $k => $v) {
551 547
             foreach ($w as $kk => $vv) {
552
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
553
-                    $relations[$k] = [ $v, $table ];
554
-                    $w[$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] = [$v, $table];
550
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
555 551
                 }
556 552
             }
557
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
558
-                $relations[$k] = [ $v, $table ];
553
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
554
+                $relations[$k] = [$v, $table];
559 555
             }
560 556
             foreach ($h as $kk => $vv) {
561
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
562
-                    $relations[$k] = [ $relation, $table ];
563
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
557
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
558
+                    $relations[$k] = [$relation, $table];
559
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
564 560
                 }
565 561
             }
566
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
567
-                $relations[$k] = [ $relation, $table ];
568
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
562
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
563
+                $relations[$k] = [$relation, $table];
564
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
569 565
             }
570 566
             foreach ($j as $kk => $v) {
571 567
                 foreach ($v->keymap as $kkk => $vv) {
572
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
573
-                        $relations[$k] = [ $relation, $table ];
574
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
568
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
569
+                        $relations[$k] = [$relation, $table];
570
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
575 571
                     }
576 572
                 }
577 573
             }
578 574
         }
579 575
 
580 576
         foreach ($j as $k => $v) {
581
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
577
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
582 578
             $tmp = [];
583 579
             foreach ($v->keymap as $kk => $vv) {
584 580
                 $tmp[] = $kk.' = '.$vv;
585 581
             }
586
-            $sql .= implode(' AND ', $tmp) . ' ';
582
+            $sql .= implode(' AND ', $tmp).' ';
587 583
         }
588 584
         foreach ($relations as $k => $v) {
589 585
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -595,13 +591,13 @@  discard block
 block discarded – undo
595 591
                 foreach ($v->keymap as $kk => $vv) {
596 592
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
597 593
                 }
598
-                $sql .= implode(' AND ', $tmp) . ' ';
594
+                $sql .= implode(' AND ', $tmp).' ';
599 595
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
600 596
                 $tmp = [];
601 597
                 foreach ($v->pivot_keymap as $kk => $vv) {
602 598
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
603 599
                 }
604
-                $sql .= implode(' AND ', $tmp) . ' ';
600
+                $sql .= implode(' AND ', $tmp).' ';
605 601
             } else {
606 602
                 $alias = $getAlias($k);
607 603
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -610,30 +606,30 @@  discard block
 block discarded – undo
610 606
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
611 607
                 }
612 608
                 if ($v->sql) {
613
-                    $tmp[] = $v->sql . ' ';
609
+                    $tmp[] = $v->sql.' ';
614 610
                     $par = array_merge($par, $v->par ?? []);
615 611
                 }
616
-                $sql .= implode(' AND ', $tmp) . ' ';
612
+                $sql .= implode(' AND ', $tmp).' ';
617 613
             }
618 614
         }
619 615
         if (count($w)) {
620 616
             $sql .= 'WHERE ';
621 617
             $tmp = [];
622 618
             foreach ($w as $v) {
623
-                $tmp[] = '(' . $v[0] . ')';
619
+                $tmp[] = '('.$v[0].')';
624 620
                 $par = array_merge($par, $v[1]);
625 621
             }
626 622
             $sql .= implode(' AND ', $tmp).' ';
627 623
         }
628 624
         if (count($g)) {
629
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
625
+            $sql .= 'GROUP BY '.$g[0].' ';
630 626
             $par = array_merge($par, $g[1]);
631 627
         }
632 628
         if (count($h)) {
633 629
             $sql .= 'HAVING ';
634 630
             $tmp = [];
635 631
             foreach ($h as $v) {
636
-                $tmp[] = '(' . $v[0] . ')';
632
+                $tmp[] = '('.$v[0].')';
637 633
                 $par = array_merge($par, $v[1]);
638 634
             }
639 635
             $sql .= implode(' AND ', $tmp).' ';
@@ -667,7 +663,7 @@  discard block
 block discarded – undo
667 663
                     $this->with(implode('.', $temp));
668 664
                     $table = array_reduce(
669 665
                         $temp,
670
-                        function ($carry, $item) use (&$table) {
666
+                        function($carry, $item) use (&$table) {
671 667
                             return $table->getRelation($item)->table;
672 668
                         }
673 669
                     );
@@ -676,7 +672,7 @@  discard block
 block discarded – undo
676 672
                 }
677 673
                 unset($fields[$k]);
678 674
                 foreach ($cols as $col) {
679
-                    $fields[] = $table . '.' . $col;
675
+                    $fields[] = $table.'.'.$col;
680 676
                 }
681 677
             }
682 678
         }
@@ -708,9 +704,9 @@  discard block
 block discarded – undo
708 704
             return $this->qiterator;
709 705
         }
710 706
         $aliases = [];
711
-        $getAlias = function ($name) use (&$aliases) {
707
+        $getAlias = function($name) use (&$aliases) {
712 708
             // to bypass use: return $name;
713
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
709
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
714 710
         };
715 711
         $table = $this->definition->getName();
716 712
         if ($fields !== null) {
@@ -726,7 +722,7 @@  discard block
 block discarded – undo
726 722
         $h = $this->having;
727 723
         $o = $this->order;
728 724
         $g = $this->group;
729
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
725
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
730 726
 
731 727
         $porder = [];
732 728
         foreach ($this->definition->getPrimaryKey() as $field) {
@@ -739,9 +735,9 @@  discard block
 block discarded – undo
739 735
                 if (count($porder) > 1) {
740 736
                     $pkw = [];
741 737
                     foreach ($porder as $name) {
742
-                        $pkw[] = $name . ' = ?';
738
+                        $pkw[] = $name.' = ?';
743 739
                     }
744
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
740
+                    $pkw = '('.implode(' AND ', $pkw).')';
745 741
                     $pkp = [];
746 742
                     foreach ($ids as $id) {
747 743
                         foreach ($id as $p) {
@@ -753,67 +749,67 @@  discard block
 block discarded – undo
753 749
                         $pkp
754 750
                     ];
755 751
                 } else {
756
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
752
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
757 753
                 }
758 754
             } else {
759
-                $w[] = [ '1=0', [] ];
755
+                $w[] = ['1=0', []];
760 756
             }
761 757
         }
762 758
 
763 759
         foreach ($this->definition->getRelations() as $k => $relation) {
764 760
             foreach ($f as $kk => $field) {
765
-                if (strpos($field, $k . '.') === 0) {
766
-                    $relations[$k] = [ $relation, $table ];
767
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
761
+                if (strpos($field, $k.'.') === 0) {
762
+                    $relations[$k] = [$relation, $table];
763
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
768 764
                 }
769 765
             }
770 766
             foreach ($w as $kk => $v) {
771
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
772
-                    $relations[$k] = [ $relation, $table ];
773
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
767
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
768
+                    $relations[$k] = [$relation, $table];
769
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
774 770
                 }
775 771
             }
776 772
             foreach ($h as $kk => $v) {
777
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
778
-                    $relations[$k] = [ $relation, $table ];
779
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
773
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
774
+                    $relations[$k] = [$relation, $table];
775
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
780 776
                 }
781 777
             }
782
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
783
-                $relations[$k] = [ $relation, $table ];
784
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
778
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
779
+                $relations[$k] = [$relation, $table];
780
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
785 781
             }
786
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
787
-                $relations[$k] = [ $relation, $table ];
788
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
782
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
783
+                $relations[$k] = [$relation, $table];
784
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
789 785
             }
790 786
             foreach ($j as $kk => $v) {
791 787
                 foreach ($v->keymap as $kkk => $vv) {
792
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
793
-                        $relations[$k] = [ $relation, $table ];
794
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
788
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
789
+                        $relations[$k] = [$relation, $table];
790
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
795 791
                     }
796 792
                 }
797 793
             }
798 794
         }
799 795
         $select = [];
800 796
         foreach ($f as $k => $field) {
801
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
797
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
802 798
         }
803 799
         foreach ($this->withr as $name => $relation) {
804 800
             foreach ($relation[0]->table->getColumns() as $column) {
805
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
801
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
806 802
             }
807 803
         }
808 804
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
809 805
         $par = [];
810 806
         foreach ($j as $k => $v) {
811
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
807
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
812 808
             $tmp = [];
813 809
             foreach ($v->keymap as $kk => $vv) {
814 810
                 $tmp[] = $kk.' = '.$vv;
815 811
             }
816
-            $sql .= implode(' AND ', $tmp) . ' ';
812
+            $sql .= implode(' AND ', $tmp).' ';
817 813
         }
818 814
         foreach ($relations as $relation => $v) {
819 815
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -825,13 +821,13 @@  discard block
 block discarded – undo
825 821
                 foreach ($v->keymap as $kk => $vv) {
826 822
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
827 823
                 }
828
-                $sql .= implode(' AND ', $tmp) . ' ';
824
+                $sql .= implode(' AND ', $tmp).' ';
829 825
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($relation).' ON ';
830 826
                 $tmp = [];
831 827
                 foreach ($v->pivot_keymap as $kk => $vv) {
832 828
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
833 829
                 }
834
-                $sql .= implode(' AND ', $tmp) . ' ';
830
+                $sql .= implode(' AND ', $tmp).' ';
835 831
             } else {
836 832
                 $alias = $getAlias($relation);
837 833
 
@@ -841,64 +837,64 @@  discard block
 block discarded – undo
841 837
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
842 838
                 }
843 839
                 if ($v->sql) {
844
-                    $tmp[] = $v->sql . ' ';
840
+                    $tmp[] = $v->sql.' ';
845 841
                     $par = array_merge($par, $v->par ?? []);
846 842
                 }
847
-                $sql .= implode(' AND ', $tmp) . ' ';
843
+                $sql .= implode(' AND ', $tmp).' ';
848 844
             }
849 845
         }
850 846
         if (count($w)) {
851 847
             $sql .= 'WHERE ';
852 848
             $tmp = [];
853 849
             foreach ($w as $v) {
854
-                $tmp[] = '(' . $v[0] . ')';
850
+                $tmp[] = '('.$v[0].')';
855 851
                 $par = array_merge($par, $v[1]);
856 852
             }
857 853
             $sql .= implode(' AND ', $tmp).' ';
858 854
         }
859 855
         if (count($g)) {
860
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
856
+            $sql .= 'GROUP BY '.$g[0].' ';
861 857
             $par = array_merge($par, $g[1]);
862 858
         }
863 859
         if (count($h)) {
864 860
             $sql .= 'HAVING ';
865 861
             $tmp = [];
866 862
             foreach ($h as $v) {
867
-                $tmp[] = '(' . $v[0] . ')';
863
+                $tmp[] = '('.$v[0].')';
868 864
                 $par = array_merge($par, $v[1]);
869 865
             }
870 866
             $sql .= implode(' AND ', $tmp).' ';
871 867
         }
872 868
         if (count($o)) {
873
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
869
+            $sql .= 'ORDER BY '.$o[0].' ';
874 870
             $par = array_merge($par, $o[1]);
875 871
         }
876 872
         if (count($porder)) {
877 873
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
878
-            $porder = array_map(function ($v) use ($pdir) { return $v . ' ' . $pdir; }, $porder);
879
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
874
+            $porder = array_map(function($v) use ($pdir) { return $v.' '.$pdir; }, $porder);
875
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
880 876
         }
881 877
         if (($this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
882 878
             if ($this->db->driverName() === 'oracle') {
883
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
884
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
879
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
880
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
885 881
                 } else {
886
-                    $f = array_map(function ($v) {
882
+                    $f = array_map(function($v) {
887 883
                         $v = explode(' ', trim($v), 2);
888 884
                         if (count($v) === 2) { return $v[1]; }
889 885
                         $v = explode('.', $v[0], 2);
890 886
                         return count($v) === 2 ? $v[1] : $v[0];
891 887
                     }, $select);
892
-                    $sql = "SELECT " . implode(', ', $f) . " 
888
+                    $sql = "SELECT ".implode(', ', $f)." 
893 889
                             FROM (
894 890
                                 SELECT tbl__.*, rownum rnum__ FROM (
895
-                                    " . $sql . "
891
+                                    " . $sql."
896 892
                                 ) tbl__ 
897
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
893
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
898 894
                             ) WHERE rnum__ > " . $this->li_of[1];
899 895
                 }
900 896
             } else {
901
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
897
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
902 898
             }
903 899
         }
904 900
         return $this->qiterator = new TableQueryIterator(
@@ -948,7 +944,7 @@  discard block
 block discarded – undo
948 944
                 $ret[$k] = str_repeat(' ', 255);
949 945
                 $par[] = &$ret[$k];
950 946
             }
951
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
947
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
952 948
             $this->db->query($sql, $par);
953 949
             return $ret;
954 950
         } else {
@@ -980,7 +976,7 @@  discard block
 block discarded – undo
980 976
         }
981 977
         $sql = 'UPDATE '.$table.' SET ';
982 978
         $par = [];
983
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
979
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
984 980
         $par = array_merge($par, array_values($update));
985 981
         if (count($this->where)) {
986 982
             $sql .= 'WHERE ';
@@ -989,7 +985,7 @@  discard block
 block discarded – undo
989 985
                 $tmp[] = $v[0];
990 986
                 $par = array_merge($par, $v[1]);
991 987
             }
992
-            $sql .= implode(' AND ', $tmp) . ' ';
988
+            $sql .= implode(' AND ', $tmp).' ';
993 989
         }
994 990
         if (count($this->order)) {
995 991
             $sql .= $this->order[0];
@@ -1013,7 +1009,7 @@  discard block
 block discarded – undo
1013 1009
                 $tmp[] = $v[0];
1014 1010
                 $par = array_merge($par, $v[1]);
1015 1011
             }
1016
-            $sql .= implode(' AND ', $tmp) . ' ';
1012
+            $sql .= implode(' AND ', $tmp).' ';
1017 1013
         }
1018 1014
         if (count($this->order)) {
1019 1015
             $sql .= $this->order[0];
@@ -1033,13 +1029,13 @@  discard block
 block discarded – undo
1033 1029
         $table = $this->definition;
1034 1030
         array_reduce(
1035 1031
             $parts,
1036
-            function ($carry, $item) use (&$table) {
1032
+            function($carry, $item) use (&$table) {
1037 1033
                 $relation = $table->getRelation($item);
1038 1034
                 if (!$relation) {
1039 1035
                     throw new DBException('Invalid relation name');
1040 1036
                 }
1041
-                $name = $carry ? $carry . static::SEP . $item : $item;
1042
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
1037
+                $name = $carry ? $carry.static::SEP.$item : $item;
1038
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
1043 1039
                 $table = $relation->table;
1044 1040
                 return $name;
1045 1041
             }
@@ -1084,9 +1080,9 @@  discard block
 block discarded – undo
1084 1080
         }
1085 1081
 
1086 1082
         $aliases = [];
1087
-        $getAlias = function ($name) use (&$aliases) {
1083
+        $getAlias = function($name) use (&$aliases) {
1088 1084
             // to bypass use: return $name;
1089
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1085
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1090 1086
         };
1091 1087
         
1092 1088
         $table = $this->definition->getName();
@@ -1099,63 +1095,63 @@  discard block
 block discarded – undo
1099 1095
         $h = $this->having;
1100 1096
         $o = $this->order;
1101 1097
         $g = $this->group;
1102
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
1098
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
1103 1099
         foreach ($this->definition->getRelations() as $k => $v) {
1104 1100
             foreach ($w as $kk => $vv) {
1105
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1106
-                    $relations[$k] = [ $v, $table ];
1107
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1101
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1102
+                    $relations[$k] = [$v, $table];
1103
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1108 1104
                 }
1109 1105
             }
1110
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1111
-                $relations[$k] = [ $v, $table ];
1112
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1113
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1106
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1107
+                $relations[$k] = [$v, $table];
1108
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1109
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1114 1110
             }
1115 1111
             foreach ($h as $kk => $vv) {
1116
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1117
-                    $relations[$k] = [ $relation, $table ];
1118
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1112
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1113
+                    $relations[$k] = [$relation, $table];
1114
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1119 1115
                 }
1120 1116
             }
1121
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1122
-                $relations[$k] = [ $relation, $table ];
1123
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1117
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1118
+                $relations[$k] = [$relation, $table];
1119
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1124 1120
             }
1125 1121
             foreach ($j as $kk => $v) {
1126 1122
                 foreach ($v->keymap as $kkk => $vv) {
1127
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1128
-                        $relations[$k] = [ $relation, $table ];
1129
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
1123
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1124
+                        $relations[$k] = [$relation, $table];
1125
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
1130 1126
                     }
1131 1127
                 }
1132 1128
             }
1133 1129
         }
1134 1130
 
1135
-        $key = array_map(function ($v) use ($table) { return $table . '.' . $v; }, $this->pkey);
1131
+        $key = array_map(function($v) use ($table) { return $table.'.'.$v; }, $this->pkey);
1136 1132
         $own = false;
1137 1133
         $dir = 'ASC';
1138 1134
         if (count($o)) {
1139 1135
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1140
-            $own = strpos($o[2], $table . '.') === 0;
1136
+            $own = strpos($o[2], $table.'.') === 0;
1141 1137
         }
1142 1138
 
1143 1139
         $dst = $key;
1144 1140
         if ($own) {
1145 1141
             // if using own table - do not use max/min in order - that will prevent index usage
1146
-            $dst[] = $o[2] . ' orderbyfix___';
1142
+            $dst[] = $o[2].' orderbyfix___';
1147 1143
         }
1148 1144
         $dst = array_unique($dst);
1149 1145
 
1150 1146
         $par = [];
1151
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1147
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$table.' ';
1152 1148
         foreach ($j as $k => $v) {
1153
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1149
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1154 1150
             $tmp = [];
1155 1151
             foreach ($v->keymap as $kk => $vv) {
1156 1152
                 $tmp[] = $kk.' = '.$vv;
1157 1153
             }
1158
-            $sql .= implode(' AND ', $tmp) . ' ';
1154
+            $sql .= implode(' AND ', $tmp).' ';
1159 1155
         }
1160 1156
         foreach ($relations as $k => $v) {
1161 1157
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -1167,13 +1163,13 @@  discard block
 block discarded – undo
1167 1163
                 foreach ($v->keymap as $kk => $vv) {
1168 1164
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1169 1165
                 }
1170
-                $sql .= implode(' AND ', $tmp) . ' ';
1166
+                $sql .= implode(' AND ', $tmp).' ';
1171 1167
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1172 1168
                 $tmp = [];
1173 1169
                 foreach ($v->pivot_keymap as $kk => $vv) {
1174 1170
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1175 1171
                 }
1176
-                $sql .= implode(' AND ', $tmp) . ' ';
1172
+                $sql .= implode(' AND ', $tmp).' ';
1177 1173
             } else {
1178 1174
                 $alias = $getAlias($k);
1179 1175
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1182,29 +1178,29 @@  discard block
 block discarded – undo
1182 1178
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1183 1179
                 }
1184 1180
                 if ($v->sql) {
1185
-                    $tmp[] = $v->sql . ' ';
1181
+                    $tmp[] = $v->sql.' ';
1186 1182
                     $par = array_merge($par, $v->par ?? []);
1187 1183
                 }
1188
-                $sql .= implode(' AND ', $tmp) . ' ';
1184
+                $sql .= implode(' AND ', $tmp).' ';
1189 1185
             }
1190 1186
         }
1191 1187
         if (count($w)) {
1192 1188
             $sql .= 'WHERE ';
1193 1189
             $tmp = [];
1194 1190
             foreach ($w as $v) {
1195
-                $tmp[] = '(' . $v[0] . ')';
1191
+                $tmp[] = '('.$v[0].')';
1196 1192
                 $par = array_merge($par, $v[1]);
1197 1193
             }
1198 1194
             $sql .= implode(' AND ', $tmp).' ';
1199 1195
         }
1200 1196
         if (!$own) {
1201
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1197
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1202 1198
         }
1203 1199
         if (count($h)) {
1204 1200
             $sql .= 'HAVING ';
1205 1201
             $tmp = [];
1206 1202
             foreach ($h as $v) {
1207
-                $tmp[] = '(' . $v[0] . ')';
1203
+                $tmp[] = '('.$v[0].')';
1208 1204
                 $par = array_merge($par, $v[1]);
1209 1205
             }
1210 1206
             $sql .= implode(' AND ', $tmp).' ';
@@ -1212,44 +1208,44 @@  discard block
 block discarded – undo
1212 1208
         if (count($o)) {
1213 1209
             $sql .= 'ORDER BY ';
1214 1210
             if ($own) {
1215
-                $sql .= $o[2] . ' ' . $dir;
1211
+                $sql .= $o[2].' '.$dir;
1216 1212
             } else {
1217
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1213
+                $sql .= 'MAX('.$o[2].') '.$dir;
1218 1214
             }
1219 1215
         }
1220 1216
         $porder = [];
1221 1217
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1222 1218
         foreach ($this->definition->getPrimaryKey() as $field) {
1223
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1219
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1224 1220
         }
1225 1221
         if (count($porder)) {
1226
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1222
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1227 1223
         }
1228 1224
 
1229 1225
         if ($this->li_of[0]) {
1230 1226
             if ($this->db->driverName() === 'oracle') {
1231
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1232
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1227
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1228
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1233 1229
                 } else {
1234
-                    $f = array_map(function ($v) {
1230
+                    $f = array_map(function($v) {
1235 1231
                         $v = explode(' ', trim($v), 2);
1236 1232
                         if (count($v) === 2) { return $v[1]; }
1237 1233
                         $v = explode('.', $v[0], 2);
1238 1234
                         return count($v) === 2 ? $v[1] : $v[0];
1239 1235
                     }, $select);
1240
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1236
+                    $sql = "SELECT ".implode(', ', $dst)." 
1241 1237
                             FROM (
1242 1238
                                 SELECT tbl__.*, rownum rnum__ FROM (
1243
-                                    " . $sql . "
1239
+                                    " . $sql."
1244 1240
                                 ) tbl__ 
1245
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1241
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1246 1242
                             ) WHERE rnum__ > " . $this->li_of[1];
1247 1243
                 }
1248 1244
             } else {
1249
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1245
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1250 1246
             }
1251 1247
         }
1252
-        return array_map(function ($v) use ($own) {
1248
+        return array_map(function($v) use ($own) {
1253 1249
             if (isset($v['orderbyfix___'])) {
1254 1250
                 unset($v['orderbyfix___']);
1255 1251
             }
Please login to merge, or discard this patch.