Completed
Push — master ( acf079...5e69a5 )
by Ivan
20:38 queued 05:34
created
src/driver/sphinx/Driver.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     {
38 38
         if ($this->lnk === null) {
39 39
             $this->lnk = new \mysqli(
40
-                (isset($this->connection['opts']['persist']) && $this->connection['opts']['persist'] ? 'p:' : '') .
40
+                (isset($this->connection['opts']['persist']) && $this->connection['opts']['persist'] ? 'p:' : '').
41 41
                     $this->connection['host'],
42 42
                 $this->connection['user'],
43 43
                 $this->connection['pass'],
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
         $res = $this->lnk->query($sql);
98 98
         if ($log) {
99 99
             $tm = microtime(true) - $tm;
100
-            if ($tm >= (float)$this->option('log_slow', 0)) {
100
+            if ($tm >= (float) $this->option('log_slow', 0)) {
101 101
                 @file_put_contents(
102 102
                     $log,
103
-                    '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" .
104
-                    $sql . "\r\n" .
103
+                    '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n".
104
+                    $sql."\r\n".
105 105
                     "\r\n",
106 106
                     FILE_APPEND
107 107
                 );
Please login to merge, or discard this patch.
src/driver/sphinx/Statement.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -40,23 +40,23 @@
 block discarded – undo
40 40
                             break;
41 41
                         case 'array':
42 42
                             $par = implode(',', $par);
43
-                            $par = "'" . $this->lnk->escape_string($par) . "'";
43
+                            $par = "'".$this->lnk->escape_string($par)."'";
44 44
                             break;
45 45
                         case 'object':
46 46
                             $par = serialize($par);
47
-                            $par = "'" . $this->lnk->escape_string($par) . "'";
47
+                            $par = "'".$this->lnk->escape_string($par)."'";
48 48
                             break;
49 49
                         case 'resource':
50 50
                             if (is_resource($v) && get_resource_type($v) === 'stream') {
51 51
                                 $par = stream_get_contents($par);
52
-                                $par = "'" . $this->lnk->escape_string($par) . "'";
52
+                                $par = "'".$this->lnk->escape_string($par)."'";
53 53
                             } else {
54 54
                                 $par = serialize($par);
55
-                                $par = "'" . $this->lnk->escape_string($par) . "'";
55
+                                $par = "'".$this->lnk->escape_string($par)."'";
56 56
                             }
57 57
                             break;
58 58
                         default:
59
-                            $par = "'" . $this->lnk->escape_string((string)$par) . "'";
59
+                            $par = "'".$this->lnk->escape_string((string) $par)."'";
60 60
                             break;
61 61
                     }
62 62
                     $sql .= $par;
Please login to merge, or discard this patch.
src/schema/TableQuery.php 1 patch
Spacing   +201 added lines, -205 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->getFullName(), $column[0] ];
100
+            $column = [$this->definition->getFullName(), $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 {
@@ -128,26 +128,26 @@  discard block
 block discarded – undo
128 128
             if ($this->definition->hasRelation(implode('.', $column))) {
129 129
                 $this->with(implode('.', $column), false);
130 130
                 $col = $this->definition->getRelation(implode('.', $column))->table->getColumn($name);
131
-                $column = [ implode('.', $column), $name ];
131
+                $column = [implode('.', $column), $name];
132 132
             } else {
133 133
                 $this->with(implode('.', $column), false);
134 134
                 $table = $this->definition;
135 135
                 $table = array_reduce(
136 136
                     $column,
137
-                    function ($carry, $item) use (&$table) {
137
+                    function($carry, $item) use (&$table) {
138 138
                         $table = $table->getRelation($item)->table;
139 139
                         return $table;
140 140
                     }
141 141
                 );
142 142
                 $col = $table->getColumn($name);
143
-                $column = [ implode(static::SEP, $column), $name ];
143
+                $column = [implode(static::SEP, $column), $name];
144 144
             }
145 145
         }
146
-        return [ 'name' => implode('.', $column), 'data' => $col ];
146
+        return ['name' => implode('.', $column), 'data' => $col];
147 147
     }
148 148
     protected function normalizeValue(TableColumn $col, $value)
149 149
     {
150
-        $strict = (int)$this->db->driverOption('strict', 0) > 0;
150
+        $strict = (int) $this->db->driverOption('strict', 0) > 0;
151 151
         if ($value === null && $col->isNullable()) {
152 152
             return null;
153 153
         }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
                     $temp = strtotime($value);
158 158
                     if (!$temp) {
159 159
                         if ($strict) {
160
-                            throw new DBException('Invalid value for date column ' . $col->getName());
160
+                            throw new DBException('Invalid value for date column '.$col->getName());
161 161
                         }
162 162
                         return null;
163 163
                     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
                     return $value->format('Y-m-d');
171 171
                 }
172 172
                 if ($strict) {
173
-                    throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName());
173
+                    throw new DBException('Invalid value (unknown data type) for date column '.$col->getName());
174 174
                 }
175 175
                 return $value;
176 176
             case 'datetime':
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                     $temp = strtotime($value);
179 179
                     if (!$temp) {
180 180
                         if ($strict) {
181
-                            throw new DBException('Invalid value for datetime column ' . $col->getName());
181
+                            throw new DBException('Invalid value for datetime column '.$col->getName());
182 182
                         }
183 183
                         return null;
184 184
                     }
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     return $value->format('Y-m-d H:i:s');
192 192
                 }
193 193
                 if ($strict) {
194
-                    throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName());
194
+                    throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName());
195 195
                 }
196 196
                 return $value;
197 197
             case 'enum':
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                 if (is_int($value)) {
200 200
                     if (!isset($values[$value])) {
201 201
                         if ($strict) {
202
-                            throw new DBException('Invalid value (using integer) for enum ' . $col->getName());
202
+                            throw new DBException('Invalid value (using integer) for enum '.$col->getName());
203 203
                         }
204 204
                         return $value;
205 205
                     }
@@ -207,23 +207,23 @@  discard block
 block discarded – undo
207 207
                 }
208 208
                 if (!in_array($value, $col->getValues())) {
209 209
                     if ($strict) {
210
-                        throw new DBException('Invalid value for enum ' . $col->getName());
210
+                        throw new DBException('Invalid value for enum '.$col->getName());
211 211
                     }
212 212
                     return 0;
213 213
                 }
214 214
                 return $value;
215 215
             case 'int':
216 216
                 $temp = preg_replace('([^+\-0-9]+)', '', $value);
217
-                return is_string($temp) ? (int)$temp : 0;
217
+                return is_string($temp) ? (int) $temp : 0;
218 218
             case 'float':
219 219
                 $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
220
-                return is_string($temp) ? (float)$temp : 0;
220
+                return is_string($temp) ? (float) $temp : 0;
221 221
             case 'text':
222 222
                 // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled
223 223
                 // because the polyfill is quite slow
224 224
                 if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) {
225 225
                     if ($strict) {
226
-                        throw new DBException('Invalid value for text column ' . $col->getName());
226
+                        throw new DBException('Invalid value for text column '.$col->getName());
227 227
                     }
228 228
                     return mb_substr($value, 0, $col->getLength());
229 229
                 }
@@ -245,35 +245,32 @@  discard block
 block discarded – undo
245 245
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
246 246
             return $negate ?
247 247
                 [
248
-                    $name . ' NOT LIKE ?',
249
-                    [ $this->normalizeValue($column, $value) ]
250
-                ] :
251
-                [
252
-                    $name . ' LIKE ?',
253
-                    [ $this->normalizeValue($column, $value) ]
248
+                    $name.' NOT LIKE ?',
249
+                    [$this->normalizeValue($column, $value)]
250
+                ] : [
251
+                    $name.' LIKE ?',
252
+                    [$this->normalizeValue($column, $value)]
254 253
                 ];
255 254
         }
256 255
         if (is_null($value)) {
257 256
             return $negate ?
258
-                [ $name . ' IS NOT NULL', [] ]:
259
-                [ $name . ' IS NULL', [] ];
257
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
260 258
         }
261 259
         if (!is_array($value)) {
262 260
             return $negate ?
263 261
                 [
264
-                    $name . ' <> ?',
265
-                    [ $this->normalizeValue($column, $value) ]
266
-                ] :
267
-                [
268
-                    $name . ' = ?',
269
-                    [ $this->normalizeValue($column, $value) ]
262
+                    $name.' <> ?',
263
+                    [$this->normalizeValue($column, $value)]
264
+                ] : [
265
+                    $name.' = ?',
266
+                    [$this->normalizeValue($column, $value)]
270 267
                 ];
271 268
         }
272 269
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
273
-            $value = [ 'gte' => $value['beg'] ];
270
+            $value = ['gte' => $value['beg']];
274 271
         }
275 272
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
276
-            $value = [ 'lte' => $value['end'] ];
273
+            $value = ['lte' => $value['end']];
277 274
         }
278 275
         if (isset($value['beg']) && isset($value['end'])) {
279 276
             return $negate ?
@@ -283,8 +280,7 @@  discard block
 block discarded – undo
283 280
                         $this->normalizeValue($column, $value['beg']),
284 281
                         $this->normalizeValue($column, $value['end'])
285 282
                     ]
286
-                ] :
287
-                [
283
+                ] : [
288 284
                     $name.' BETWEEN ? AND ?',
289 285
                     [
290 286
                         $this->normalizeValue($column, $value['beg']),
@@ -296,42 +292,42 @@  discard block
 block discarded – undo
296 292
             $sql = [];
297 293
             $par = [];
298 294
             if (isset($value['gt'])) {
299
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
295
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
300 296
                 $par[] = $this->normalizeValue($column, $value['gt']);
301 297
             }
302 298
             if (isset($value['gte'])) {
303
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
299
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
304 300
                 $par[] = $this->normalizeValue($column, $value['gte']);
305 301
             }
306 302
             if (isset($value['lt'])) {
307
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
303
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
308 304
                 $par[] = $this->normalizeValue($column, $value['lt']);
309 305
             }
310 306
             if (isset($value['lte'])) {
311
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
307
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
312 308
                 $par[] = $this->normalizeValue($column, $value['lte']);
313 309
             }
314 310
             return [
315
-                '(' . implode(' AND ', $sql) . ')',
311
+                '('.implode(' AND ', $sql).')',
316 312
                 $par
317 313
             ];
318 314
         }
319 315
 
320
-        $value = array_values(array_map(function ($v) use ($column) {
316
+        $value = array_values(array_map(function($v) use ($column) {
321 317
             return $this->normalizeValue($column, $v);
322 318
         }, $value));
323 319
         if ($this->db->driverName() === 'oracle') {
324 320
             $sql = [];
325 321
             $par = [];
326 322
             for ($i = 0; $i < count($value); $i += 500) {
327
-                $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)';
323
+                $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)';
328 324
                 $par[] = array_slice($value, $i, 500);
329 325
             }
330
-            $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')';
331
-            return [ $sql, [$par] ];
326
+            $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')';
327
+            return [$sql, [$par]];
332 328
         }
333 329
         return [
334
-            $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)',
330
+            $negate ? $name.' NOT IN (??)' : $name.' IN (??)',
335 331
             [$value]
336 332
         ];
337 333
     }
@@ -363,7 +359,7 @@  discard block
 block discarded – undo
363 359
                 $par = array_merge($par, $temp[1]);
364 360
             }
365 361
         }
366
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
362
+        return $this->where('('.implode(' OR ', $sql).')', $par);
367 363
     }
368 364
     /**
369 365
      * Filter the results matching all of the criteria
@@ -381,7 +377,7 @@  discard block
 block discarded – undo
381 377
                 $par = array_merge($par, $temp[1]);
382 378
             }
383 379
         }
384
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
380
+        return $this->where('('.implode(' AND ', $sql).')', $par);
385 381
     }
386 382
     /**
387 383
      * Sort by a column
@@ -396,7 +392,7 @@  discard block
 block discarded – undo
396 392
         } catch (DBException $e) {
397 393
             throw new DBException('Invalid sort column');
398 394
         }
399
-        return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC'));
395
+        return $this->order($column.' '.($desc ? 'DESC' : 'ASC'));
400 396
     }
401 397
     /**
402 398
      * Group by a column (or columns)
@@ -406,7 +402,7 @@  discard block
 block discarded – undo
406 402
     public function group($column) : self
407 403
     {
408 404
         if (!is_array($column)) {
409
-            $column = [ $column ];
405
+            $column = [$column];
410 406
         }
411 407
         foreach ($column as $k => $v) {
412 408
             $column[$k] = $this->getColumn($v)['name'];
@@ -448,7 +444,7 @@  discard block
 block discarded – undo
448 444
         $this->order = [];
449 445
         $this->having = [];
450 446
         $this->aliases = [];
451
-        $this->li_of = [0,0,0];
447
+        $this->li_of = [0, 0, 0];
452 448
         $this->qiterator = null;
453 449
         return $this;
454 450
     }
@@ -461,7 +457,7 @@  discard block
 block discarded – undo
461 457
     public function groupBy(string $sql, array $params = []) : self
462 458
     {
463 459
         $this->qiterator = null;
464
-        $this->group = [ $sql, $params ];
460
+        $this->group = [$sql, $params];
465 461
         return $this;
466 462
     }
467 463
     /**
@@ -474,7 +470,7 @@  discard block
 block discarded – undo
474 470
      */
475 471
     public function join($table, array $fields, string $name = null, bool $multiple = true)
476 472
     {
477
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
473
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
478 474
         $name = $name ?? $table->getName();
479 475
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
480 476
             throw new DBException('Alias / table name already in use');
@@ -483,7 +479,7 @@  discard block
 block discarded – undo
483 479
         foreach ($fields as $k => $v) {
484 480
             $k = explode('.', $k, 2);
485 481
             $k = count($k) == 2 ? $k[1] : $k[0];
486
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
482
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
487 483
         }
488 484
         return $this;
489 485
     }
@@ -496,7 +492,7 @@  discard block
 block discarded – undo
496 492
     public function where(string $sql, array $params = []) : self
497 493
     {
498 494
         $this->qiterator = null;
499
-        $this->where[] = [ $sql, $params ];
495
+        $this->where[] = [$sql, $params];
500 496
         return $this;
501 497
     }
502 498
     /**
@@ -508,7 +504,7 @@  discard block
 block discarded – undo
508 504
     public function having(string $sql, array $params = []) : self
509 505
     {
510 506
         $this->qiterator = null;
511
-        $this->having[] = [ $sql, $params ];
507
+        $this->having[] = [$sql, $params];
512 508
         return $this;
513 509
     }
514 510
     /**
@@ -528,12 +524,12 @@  discard block
 block discarded – undo
528 524
                     throw new \Exception();
529 525
                 }
530 526
                 $name = $this->getColumn(trim($name))['name'];
531
-                $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
527
+                $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC');
532 528
             } catch (\Exception $e) {
533 529
                 $name = null;
534 530
             }
535 531
         }
536
-        $this->order = [ $sql, $params, $name ];
532
+        $this->order = [$sql, $params, $name];
537 533
         return $this;
538 534
     }
539 535
     /**
@@ -545,7 +541,7 @@  discard block
 block discarded – undo
545 541
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self
546 542
     {
547 543
         $this->qiterator = null;
548
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
544
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
549 545
         return $this;
550 546
     }
551 547
     /**
@@ -555,9 +551,9 @@  discard block
 block discarded – undo
555 551
     public function count() : int
556 552
     {
557 553
         $aliases = [];
558
-        $getAlias = function ($name) use (&$aliases) {
554
+        $getAlias = function($name) use (&$aliases) {
559 555
             // to bypass use: return $name;
560
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
556
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
561 557
         };
562 558
         $table = $this->definition->getFullName();
563 559
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -571,35 +567,35 @@  discard block
 block discarded – undo
571 567
         $h = $this->having;
572 568
         $o = $this->order;
573 569
         $g = $this->group;
574
-        $j = array_map(function ($v) {
570
+        $j = array_map(function($v) {
575 571
             return clone $v;
576 572
         }, $this->joins);
577 573
         foreach ($this->definition->getRelations() as $k => $v) {
578 574
             foreach ($w as $kk => $vv) {
579
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
580
-                    $relations[$k] = [ $v, $table ];
581
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
575
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
576
+                    $relations[$k] = [$v, $table];
577
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
582 578
                 }
583 579
             }
584
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
585
-                $relations[$k] = [ $v, $table ];
580
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
581
+                $relations[$k] = [$v, $table];
586 582
             }
587 583
             foreach ($h as $kk => $vv) {
588
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
589
-                    $relations[$k] = [ $v, $table ];
590
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
584
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
585
+                    $relations[$k] = [$v, $table];
586
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
591 587
                 }
592 588
             }
593
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
594
-                $relations[$k] = [ $v, $table ];
595
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
589
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
590
+                $relations[$k] = [$v, $table];
591
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
596 592
             }
597 593
             foreach ($j as $kk => $vv) {
598 594
                 foreach ($vv->keymap as $kkk => $vvv) {
599
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
600
-                        $relations[$k] = [ $v, $table ];
595
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
596
+                        $relations[$k] = [$v, $table];
601 597
                         $j[$kk]->keymap[$kkk] =
602
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
598
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
603 599
                     }
604 600
                 }
605 601
             }
@@ -615,13 +611,13 @@  discard block
 block discarded – undo
615 611
                 foreach ($v->keymap as $kk => $vv) {
616 612
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
617 613
                 }
618
-                $sql .= implode(' AND ', $tmp) . ' ';
614
+                $sql .= implode(' AND ', $tmp).' ';
619 615
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON ';
620 616
                 $tmp = [];
621 617
                 foreach ($v->pivot_keymap as $kk => $vv) {
622 618
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
623 619
                 }
624
-                $sql .= implode(' AND ', $tmp) . ' ';
620
+                $sql .= implode(' AND ', $tmp).' ';
625 621
             } else {
626 622
                 $alias = $getAlias($k);
627 623
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON ';
@@ -630,38 +626,38 @@  discard block
 block discarded – undo
630 626
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
631 627
                 }
632 628
                 if ($v->sql) {
633
-                    $tmp[] = $v->sql . ' ';
629
+                    $tmp[] = $v->sql.' ';
634 630
                     $par = array_merge($par, $v->par ?? []);
635 631
                 }
636
-                $sql .= implode(' AND ', $tmp) . ' ';
632
+                $sql .= implode(' AND ', $tmp).' ';
637 633
             }
638 634
         }
639 635
         foreach ($j as $k => $v) {
640
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON ';
636
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON ';
641 637
             $tmp = [];
642 638
             foreach ($v->keymap as $kk => $vv) {
643 639
                 $tmp[] = $kk.' = '.$vv;
644 640
             }
645
-            $sql .= implode(' AND ', $tmp) . ' ';
641
+            $sql .= implode(' AND ', $tmp).' ';
646 642
         }
647 643
         if (count($w)) {
648 644
             $sql .= 'WHERE ';
649 645
             $tmp = [];
650 646
             foreach ($w as $v) {
651
-                $tmp[] = '(' . $v[0] . ')';
647
+                $tmp[] = '('.$v[0].')';
652 648
                 $par = array_merge($par, $v[1]);
653 649
             }
654 650
             $sql .= implode(' AND ', $tmp).' ';
655 651
         }
656 652
         if (count($g)) {
657
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
653
+            $sql .= 'GROUP BY '.$g[0].' ';
658 654
             $par = array_merge($par, $g[1]);
659 655
         }
660 656
         if (count($h)) {
661 657
             $sql .= 'HAVING ';
662 658
             $tmp = [];
663 659
             foreach ($h as $v) {
664
-                $tmp[] = '(' . $v[0] . ')';
660
+                $tmp[] = '('.$v[0].')';
665 661
                 $par = array_merge($par, $v[1]);
666 662
             }
667 663
             $sql .= implode(' AND ', $tmp).' ';
@@ -695,7 +691,7 @@  discard block
 block discarded – undo
695 691
                     $this->with(implode('.', $temp));
696 692
                     $table = array_reduce(
697 693
                         $temp,
698
-                        function ($carry, $item) use (&$table) {
694
+                        function($carry, $item) use (&$table) {
699 695
                             return $table->getRelation($item)->table;
700 696
                         }
701 697
                     );
@@ -704,7 +700,7 @@  discard block
 block discarded – undo
704 700
                 }
705 701
                 unset($fields[$k]);
706 702
                 foreach ($cols as $col) {
707
-                    $fields[] = $table . '.' . $col;
703
+                    $fields[] = $table.'.'.$col;
708 704
                 }
709 705
             }
710 706
         }
@@ -738,9 +734,9 @@  discard block
 block discarded – undo
738 734
             return $this->qiterator;
739 735
         }
740 736
         $aliases = [];
741
-        $getAlias = function ($name) use (&$aliases) {
737
+        $getAlias = function($name) use (&$aliases) {
742 738
             // to bypass use: return $name;
743
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
739
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
744 740
         };
745 741
         $table = $this->definition->getName();
746 742
         if ($fields !== null) {
@@ -756,7 +752,7 @@  discard block
 block discarded – undo
756 752
         $h = $this->having;
757 753
         $o = $this->order;
758 754
         $g = $this->group;
759
-        $j = array_map(function ($v) {
755
+        $j = array_map(function($v) {
760 756
             return clone $v;
761 757
         }, $this->joins);
762 758
 
@@ -770,32 +766,32 @@  discard block
 block discarded – undo
770 766
                 continue;
771 767
             }
772 768
             foreach ($f as $kk => $field) {
773
-                if (strpos($field, $k . '.') === 0) {
774
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
769
+                if (strpos($field, $k.'.') === 0) {
770
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
775 771
                 }
776 772
             }
777 773
             foreach ($w as $kk => $v) {
778
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
779
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
774
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
775
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
780 776
                 }
781 777
             }
782 778
             foreach ($h as $kk => $v) {
783
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
784
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
779
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
780
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
785 781
                 }
786 782
             }
787
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
788
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
783
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
784
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
789 785
             }
790
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
791
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
786
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
787
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
792 788
             }
793 789
             foreach ($j as $kk => $v) {
794 790
                 foreach ($v->keymap as $kkk => $vv) {
795
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
791
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
796 792
                         $j[$kk]->keymap[$kkk] = preg_replace(
797
-                            '(\b'.preg_quote($k . '.'). ')i',
798
-                            $getAlias($k) . '.',
793
+                            '(\b'.preg_quote($k.'.').')i',
794
+                            $getAlias($k).'.',
799 795
                             $vv
800 796
                         );
801 797
                     }
@@ -804,38 +800,38 @@  discard block
 block discarded – undo
804 800
         }
805 801
         foreach ($this->definition->getRelations() as $k => $relation) {
806 802
             foreach ($f as $kk => $field) {
807
-                if (strpos($field, $k . '.') === 0) {
808
-                    $relations[$k] = [ $relation, $table ];
809
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
803
+                if (strpos($field, $k.'.') === 0) {
804
+                    $relations[$k] = [$relation, $table];
805
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
810 806
                 }
811 807
             }
812 808
             foreach ($w as $kk => $v) {
813
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
814
-                    $relations[$k] = [ $relation, $table ];
815
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
809
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
810
+                    $relations[$k] = [$relation, $table];
811
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
816 812
                 }
817 813
             }
818 814
             foreach ($h as $kk => $v) {
819
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
820
-                    $relations[$k] = [ $relation, $table ];
821
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
815
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
816
+                    $relations[$k] = [$relation, $table];
817
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
822 818
                 }
823 819
             }
824
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
825
-                $relations[$k] = [ $relation, $table ];
826
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
820
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
821
+                $relations[$k] = [$relation, $table];
822
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
827 823
             }
828
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
829
-                $relations[$k] = [ $relation, $table ];
830
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
824
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
825
+                $relations[$k] = [$relation, $table];
826
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
831 827
             }
832 828
             foreach ($j as $kk => $v) {
833 829
                 foreach ($v->keymap as $kkk => $vv) {
834
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
835
-                        $relations[$k] = [ $relation, $table ];
830
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
831
+                        $relations[$k] = [$relation, $table];
836 832
                         $j[$kk]->keymap[$kkk] = preg_replace(
837
-                            '(\b'.preg_quote($k . '.'). ')i',
838
-                            $getAlias($k) . '.',
833
+                            '(\b'.preg_quote($k.'.').')i',
834
+                            $getAlias($k).'.',
839 835
                             $vv
840 836
                         );
841 837
                     }
@@ -844,12 +840,12 @@  discard block
 block discarded – undo
844 840
         }
845 841
         $select = [];
846 842
         foreach ($f as $k => $field) {
847
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
843
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
848 844
         }
849 845
         foreach ($this->withr as $name => $relation) {
850 846
             if ($relation[2]) {
851 847
                 foreach ($relation[0]->table->getColumns() as $column) {
852
-                    $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
848
+                    $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
853 849
                 }
854 850
             }
855 851
         }
@@ -869,13 +865,13 @@  discard block
 block discarded – undo
869 865
                 foreach ($v->keymap as $kk => $vv) {
870 866
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
871 867
                 }
872
-                $sql .= implode(' AND ', $tmp) . ' ';
868
+                $sql .= implode(' AND ', $tmp).' ';
873 869
                 $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON ';
874 870
                 $tmp = [];
875 871
                 foreach ($v->pivot_keymap as $kk => $vv) {
876 872
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
877 873
                 }
878
-                $sql .= implode(' AND ', $tmp) . ' ';
874
+                $sql .= implode(' AND ', $tmp).' ';
879 875
             } else {
880 876
                 $alias = $getAlias($relation);
881 877
 
@@ -885,22 +881,22 @@  discard block
 block discarded – undo
885 881
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
886 882
                 }
887 883
                 if ($v->sql) {
888
-                    $tmp[] = $v->sql . ' ';
884
+                    $tmp[] = $v->sql.' ';
889 885
                     $par = array_merge($par, $v->par ?? []);
890 886
                 }
891
-                $sql .= implode(' AND ', $tmp) . ' ';
887
+                $sql .= implode(' AND ', $tmp).' ';
892 888
             }
893 889
         }
894 890
         foreach ($j as $k => $v) {
895 891
             if ($v->many) {
896 892
                 $many = true;
897 893
             }
898
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
894
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
899 895
             $tmp = [];
900 896
             foreach ($v->keymap as $kk => $vv) {
901 897
                 $tmp[] = $kk.' = '.$vv;
902 898
             }
903
-            $sql .= implode(' AND ', $tmp) . ' ';
899
+            $sql .= implode(' AND ', $tmp).' ';
904 900
         }
905 901
         if ($many && count($porder) && $this->li_of[2] === 1) {
906 902
             $ids = $this->ids();
@@ -908,9 +904,9 @@  discard block
 block discarded – undo
908 904
                 if (count($porder) > 1) {
909 905
                     $pkw = [];
910 906
                     foreach ($porder as $name) {
911
-                        $pkw[] = $name . ' = ?';
907
+                        $pkw[] = $name.' = ?';
912 908
                     }
913
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
909
+                    $pkw = '('.implode(' AND ', $pkw).')';
914 910
                     $pkp = [];
915 911
                     foreach ($ids as $id) {
916 912
                         foreach ($id as $p) {
@@ -922,51 +918,51 @@  discard block
 block discarded – undo
922 918
                         $pkp
923 919
                     ];
924 920
                 } else {
925
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
921
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
926 922
                 }
927 923
             } else {
928
-                $w[] = [ '1=0', [] ];
924
+                $w[] = ['1=0', []];
929 925
             }
930 926
         }
931 927
         if (count($w)) {
932 928
             $sql .= 'WHERE ';
933 929
             $tmp = [];
934 930
             foreach ($w as $v) {
935
-                $tmp[] = '(' . $v[0] . ')';
931
+                $tmp[] = '('.$v[0].')';
936 932
                 $par = array_merge($par, $v[1]);
937 933
             }
938 934
             $sql .= implode(' AND ', $tmp).' ';
939 935
         }
940 936
         if (count($g)) {
941
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
937
+            $sql .= 'GROUP BY '.$g[0].' ';
942 938
             $par = array_merge($par, $g[1]);
943 939
         }
944 940
         if (count($h)) {
945 941
             $sql .= 'HAVING ';
946 942
             $tmp = [];
947 943
             foreach ($h as $v) {
948
-                $tmp[] = '(' . $v[0] . ')';
944
+                $tmp[] = '('.$v[0].')';
949 945
                 $par = array_merge($par, $v[1]);
950 946
             }
951 947
             $sql .= implode(' AND ', $tmp).' ';
952 948
         }
953 949
         if (count($o)) {
954
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
950
+            $sql .= 'ORDER BY '.$o[0].' ';
955 951
             $par = array_merge($par, $o[1]);
956 952
         }
957 953
         if (!count($g) && count($porder)) {
958 954
             $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
959
-            $porder = array_map(function ($v) use ($pdir) {
960
-                return $v . ' ' . $pdir;
955
+            $porder = array_map(function($v) use ($pdir) {
956
+                return $v.' '.$pdir;
961 957
             }, $porder);
962
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
958
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
963 959
         }
964 960
         if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
965 961
             if ($this->db->driverName() === 'oracle') {
966
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
967
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
962
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
963
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
968 964
                 } else {
969
-                    $f = array_map(function ($v) {
965
+                    $f = array_map(function($v) {
970 966
                         $v = explode(' ', trim($v), 2);
971 967
                         if (count($v) === 2) {
972 968
                             return $v[1];
@@ -974,16 +970,16 @@  discard block
 block discarded – undo
974 970
                         $v = explode('.', $v[0], 2);
975 971
                         return count($v) === 2 ? $v[1] : $v[0];
976 972
                     }, $select);
977
-                    $sql = "SELECT " . implode(', ', $f) . " 
973
+                    $sql = "SELECT ".implode(', ', $f)." 
978 974
                             FROM (
979 975
                                 SELECT tbl__.*, rownum rnum__ FROM (
980
-                                    " . $sql . "
976
+                                    " . $sql."
981 977
                                 ) tbl__ 
982
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
978
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
983 979
                             ) WHERE rnum__ > " . $this->li_of[1];
984 980
                 }
985 981
             } else {
986
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
982
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
987 983
             }
988 984
         }
989 985
         return $this->qiterator = new TableQueryIterator(
@@ -1033,12 +1029,12 @@  discard block
 block discarded – undo
1033 1029
                 $ret[$k] = str_repeat(' ', 255);
1034 1030
                 $par[] = &$ret[$k];
1035 1031
             }
1036
-            $sql .= ' RETURNING ' . implode(',', $primary) .
1037
-                ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
1032
+            $sql .= ' RETURNING '.implode(',', $primary).
1033
+                ' INTO '.implode(',', array_fill(0, count($primary), '?'));
1038 1034
             $this->db->query($sql, $par);
1039 1035
             return $ret;
1040 1036
         } elseif ($this->db->driverName() === 'postgre') {
1041
-            $sql .= ' RETURNING ' . implode(',', $primary);
1037
+            $sql .= ' RETURNING '.implode(',', $primary);
1042 1038
             return $this->db->one($sql, $par, false);
1043 1039
         } else {
1044 1040
             $ret = [];
@@ -1069,9 +1065,9 @@  discard block
 block discarded – undo
1069 1065
         }
1070 1066
         $sql = 'UPDATE '.$table.' SET ';
1071 1067
         $par = [];
1072
-        $sql .= implode(', ', array_map(function ($v) {
1073
-            return $v . ' = ?';
1074
-        }, array_keys($update))) . ' ';
1068
+        $sql .= implode(', ', array_map(function($v) {
1069
+            return $v.' = ?';
1070
+        }, array_keys($update))).' ';
1075 1071
         $par = array_merge($par, array_values($update));
1076 1072
         if (count($this->where)) {
1077 1073
             $sql .= 'WHERE ';
@@ -1080,7 +1076,7 @@  discard block
 block discarded – undo
1080 1076
                 $tmp[] = $v[0];
1081 1077
                 $par = array_merge($par, $v[1]);
1082 1078
             }
1083
-            $sql .= implode(' AND ', $tmp) . ' ';
1079
+            $sql .= implode(' AND ', $tmp).' ';
1084 1080
         }
1085 1081
         if (count($this->order)) {
1086 1082
             $sql .= $this->order[0];
@@ -1104,7 +1100,7 @@  discard block
 block discarded – undo
1104 1100
                 $tmp[] = $v[0];
1105 1101
                 $par = array_merge($par, $v[1]);
1106 1102
             }
1107
-            $sql .= implode(' AND ', $tmp) . ' ';
1103
+            $sql .= implode(' AND ', $tmp).' ';
1108 1104
         }
1109 1105
         if (count($this->order)) {
1110 1106
             $sql .= $this->order[0];
@@ -1123,17 +1119,17 @@  discard block
 block discarded – undo
1123 1119
         $table = $this->definition;
1124 1120
         if ($table->hasRelation($relation)) {
1125 1121
             $temp = $table->getRelation($relation);
1126
-            $this->withr[$relation] = [ $temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false) ];
1122
+            $this->withr[$relation] = [$temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false)];
1127 1123
         } else {
1128 1124
             $parts = explode('.', $relation);
1129 1125
             array_reduce(
1130 1126
                 $parts,
1131
-                function ($carry, $item) use (&$table, $select) {
1127
+                function($carry, $item) use (&$table, $select) {
1132 1128
                     if (!$table->hasRelation($item)) {
1133
-                        throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item);
1129
+                        throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item);
1134 1130
                     }
1135 1131
                     $relation = $table->getRelation($item);
1136
-                    $name = $carry ? $carry . static::SEP . $item : $item;
1132
+                    $name = $carry ? $carry.static::SEP.$item : $item;
1137 1133
                     $this->withr[$name] = [
1138 1134
                         $relation,
1139 1135
                         $carry ?? $table->getName(),
@@ -1184,9 +1180,9 @@  discard block
 block discarded – undo
1184 1180
         }
1185 1181
 
1186 1182
         $aliases = [];
1187
-        $getAlias = function ($name) use (&$aliases) {
1183
+        $getAlias = function($name) use (&$aliases) {
1188 1184
             // to bypass use: return $name;
1189
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1185
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1190 1186
         };
1191 1187
         
1192 1188
         $table = $this->definition->getName();
@@ -1198,65 +1194,65 @@  discard block
 block discarded – undo
1198 1194
         $h = $this->having;
1199 1195
         $o = $this->order;
1200 1196
         $g = $this->group;
1201
-        $j = array_map(function ($v) {
1197
+        $j = array_map(function($v) {
1202 1198
             return clone $v;
1203 1199
         }, $this->joins);
1204 1200
         foreach ($this->definition->getRelations() as $k => $v) {
1205 1201
             foreach ($w as $kk => $vv) {
1206
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1207
-                    $relations[$k] = [ $v, $table ];
1208
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1202
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1203
+                    $relations[$k] = [$v, $table];
1204
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1209 1205
                 }
1210 1206
             }
1211
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1212
-                $relations[$k] = [ $v, $table ];
1213
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1214
-                $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]);
1207
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1208
+                $relations[$k] = [$v, $table];
1209
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1210
+                $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]);
1215 1211
             }
1216 1212
             foreach ($h as $kk => $vv) {
1217
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1218
-                    $relations[$k] = [ $v, $table ];
1219
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1213
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1214
+                    $relations[$k] = [$v, $table];
1215
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1220 1216
                 }
1221 1217
             }
1222
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1223
-                $relations[$k] = [ $v, $table ];
1224
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1218
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1219
+                $relations[$k] = [$v, $table];
1220
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1225 1221
             }
1226 1222
             foreach ($j as $kk => $vv) {
1227 1223
                 foreach ($vv->keymap as $kkk => $vvv) {
1228
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) {
1229
-                        $relations[$k] = [ $v, $table ];
1224
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) {
1225
+                        $relations[$k] = [$v, $table];
1230 1226
                         $j[$kk]->keymap[$kkk] =
1231
-                            preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv);
1227
+                            preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv);
1232 1228
                     }
1233 1229
                 }
1234 1230
             }
1235 1231
         }
1236 1232
 
1237
-        $key = array_map(function ($v) use ($table) {
1238
-            return $table . '.' . $v;
1233
+        $key = array_map(function($v) use ($table) {
1234
+            return $table.'.'.$v;
1239 1235
         }, $this->pkey);
1240 1236
         $own = false;
1241 1237
         $dir = 'ASC';
1242 1238
         if (count($o)) {
1243 1239
             $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC';
1244
-            $own = strpos($o[2], $table . '.') === 0;
1240
+            $own = strpos($o[2], $table.'.') === 0;
1245 1241
         }
1246 1242
 
1247 1243
         $dst = $key;
1248 1244
         if (count($o)) {
1249 1245
             if ($own) {
1250 1246
                 // if using own table - do not use max/min in order - that will prevent index usage
1251
-                $dst[] = $o[2] . ' orderbyfix___';
1247
+                $dst[] = $o[2].' orderbyfix___';
1252 1248
             } else {
1253
-                $dst[] = 'MAX(' . $o[2] . ') orderbyfix___';
1249
+                $dst[] = 'MAX('.$o[2].') orderbyfix___';
1254 1250
             }
1255 1251
         }
1256 1252
         $dst = array_unique($dst);
1257 1253
 
1258 1254
         $par = [];
1259
-        $sql  = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1255
+        $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' ';
1260 1256
         foreach ($relations as $k => $v) {
1261 1257
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
1262 1258
             $v = $v[0];
@@ -1267,13 +1263,13 @@  discard block
 block discarded – undo
1267 1263
                 foreach ($v->keymap as $kk => $vv) {
1268 1264
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1269 1265
                 }
1270
-                $sql .= implode(' AND ', $tmp) . ' ';
1266
+                $sql .= implode(' AND ', $tmp).' ';
1271 1267
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1272 1268
                 $tmp = [];
1273 1269
                 foreach ($v->pivot_keymap as $kk => $vv) {
1274 1270
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1275 1271
                 }
1276
-                $sql .= implode(' AND ', $tmp) . ' ';
1272
+                $sql .= implode(' AND ', $tmp).' ';
1277 1273
             } else {
1278 1274
                 $alias = $getAlias($k);
1279 1275
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1282,37 +1278,37 @@  discard block
 block discarded – undo
1282 1278
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1283 1279
                 }
1284 1280
                 if ($v->sql) {
1285
-                    $tmp[] = $v->sql . ' ';
1281
+                    $tmp[] = $v->sql.' ';
1286 1282
                     $par = array_merge($par, $v->par ?? []);
1287 1283
                 }
1288
-                $sql .= implode(' AND ', $tmp) . ' ';
1284
+                $sql .= implode(' AND ', $tmp).' ';
1289 1285
             }
1290 1286
         }
1291 1287
         foreach ($j as $k => $v) {
1292
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1288
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1293 1289
             $tmp = [];
1294 1290
             foreach ($v->keymap as $kk => $vv) {
1295 1291
                 $tmp[] = $kk.' = '.$vv;
1296 1292
             }
1297
-            $sql .= implode(' AND ', $tmp) . ' ';
1293
+            $sql .= implode(' AND ', $tmp).' ';
1298 1294
         }
1299 1295
         if (count($w)) {
1300 1296
             $sql .= 'WHERE ';
1301 1297
             $tmp = [];
1302 1298
             foreach ($w as $v) {
1303
-                $tmp[] = '(' . $v[0] . ')';
1299
+                $tmp[] = '('.$v[0].')';
1304 1300
                 $par = array_merge($par, $v[1]);
1305 1301
             }
1306 1302
             $sql .= implode(' AND ', $tmp).' ';
1307 1303
         }
1308 1304
         if (!$own) {
1309
-            $sql .= 'GROUP BY ' . implode(', ', $key) . ' ';
1305
+            $sql .= 'GROUP BY '.implode(', ', $key).' ';
1310 1306
         }
1311 1307
         if (count($h)) {
1312 1308
             $sql .= 'HAVING ';
1313 1309
             $tmp = [];
1314 1310
             foreach ($h as $v) {
1315
-                $tmp[] = '(' . $v[0] . ')';
1311
+                $tmp[] = '('.$v[0].')';
1316 1312
                 $par = array_merge($par, $v[1]);
1317 1313
             }
1318 1314
             $sql .= implode(' AND ', $tmp).' ';
@@ -1320,38 +1316,38 @@  discard block
 block discarded – undo
1320 1316
         if (count($o)) {
1321 1317
             $sql .= 'ORDER BY ';
1322 1318
             if ($own) {
1323
-                $sql .= $o[2] . ' ' . $dir;
1319
+                $sql .= $o[2].' '.$dir;
1324 1320
             } else {
1325
-                $sql .= 'MAX('.$o[2].') ' . $dir;
1321
+                $sql .= 'MAX('.$o[2].') '.$dir;
1326 1322
             }
1327 1323
         }
1328 1324
         $porder = [];
1329 1325
         $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC';
1330 1326
         foreach ($this->definition->getPrimaryKey() as $field) {
1331
-            $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir;
1327
+            $porder[] = $this->getColumn($field)['name'].' '.$pdir;
1332 1328
         }
1333 1329
         if (count($porder)) {
1334
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1330
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1335 1331
         }
1336 1332
 
1337 1333
         if ($this->li_of[0]) {
1338 1334
             if ($this->db->driverName() === 'oracle') {
1339
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1340
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1335
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1336
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1341 1337
                 } else {
1342
-                    $sql = "SELECT " . implode(', ', $dst) . " 
1338
+                    $sql = "SELECT ".implode(', ', $dst)." 
1343 1339
                             FROM (
1344 1340
                                 SELECT tbl__.*, rownum rnum__ FROM (
1345
-                                    " . $sql . "
1341
+                                    " . $sql."
1346 1342
                                 ) tbl__ 
1347
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1343
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1348 1344
                             ) WHERE rnum__ > " . $this->li_of[1];
1349 1345
                 }
1350 1346
             } else {
1351
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1347
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1352 1348
             }
1353 1349
         }
1354
-        return array_map(function ($v) {
1350
+        return array_map(function($v) {
1355 1351
             if (array_key_exists('orderbyfix___', $v)) {
1356 1352
                 unset($v['orderbyfix___']);
1357 1353
             }
Please login to merge, or discard this patch.
src/driver/oracle/Result.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
     }
24 24
     public function affected() : int
25 25
     {
26
-        return (int)\oci_num_rows($this->statement);
26
+        return (int) \oci_num_rows($this->statement);
27 27
     }
28 28
     public function insertID(string $sequence = null)
29 29
     {
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     }
65 65
     public function next(): void
66 66
     {
67
-        $this->fetched ++;
67
+        $this->fetched++;
68 68
         $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS);
69 69
     }
70 70
     public function valid(): bool
Please login to merge, or discard this patch.
src/driver/odbc/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
     }
79 79
     public function next(): void
80 80
     {
81
-        $this->fetched ++;
81
+        $this->fetched++;
82 82
         $temp = \odbc_fetch_row($this->statement);
83 83
         if (!$temp) {
84 84
             $this->last = false;
Please login to merge, or discard this patch.
src/driver/postgre/Result.php 1 patch
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -36,8 +36,7 @@  discard block
 block discarded – undo
36 36
             $temp = @\pg_query(
37 37
                 $this->driver,
38 38
                 $sequence ?
39
-                    'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' :
40
-                    'SELECT lastval()'
39
+                    'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : 'SELECT lastval()'
41 40
             );
42 41
             if ($temp) {
43 42
                 $res = \pg_fetch_row($temp);
@@ -75,7 +74,7 @@  discard block
 block discarded – undo
75 74
     }
76 75
     public function next(): void
77 76
     {
78
-        $this->fetched ++;
77
+        $this->fetched++;
79 78
         $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC);
80 79
     }
81 80
     public function valid(): bool
Please login to merge, or discard this patch.
src/driver/sqlite/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
     }
62 62
     public function next(): void
63 63
     {
64
-        $this->fetched ++;
64
+        $this->fetched++;
65 65
         $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC);
66 66
     }
67 67
     public function valid(): bool
Please login to merge, or discard this patch.
src/driver/sphinx/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
58 58
     }
59 59
     public function next(): void
60 60
     {
61
-        $this->fetched ++;
61
+        $this->fetched++;
62 62
         $this->last = $this->result->fetch_assoc();
63 63
     }
64 64
     public function valid(): bool
Please login to merge, or discard this patch.
src/driver/ibase/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
     }
68 68
     public function next(): void
69 69
     {
70
-        $this->fetched ++;
70
+        $this->fetched++;
71 71
         $this->last = \ibase_fetch_assoc($this->result, \IBASE_TEXT);
72 72
     }
73 73
     public function valid(): bool
Please login to merge, or discard this patch.