Completed
Push — master ( 193b91...6e1dd7 )
by Ivan
03:19
created
src/driver/ibase/Driver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@
 block discarded – undo
52 52
         $this->connect();
53 53
         $statement = \ibase_prepare($this->transaction !== null ? $this->transaction : $this->lnk, $sql);
54 54
         if ($statement === false) {
55
-            throw new DBException('Prepare error: ' . \ibase_errmsg());
55
+            throw new DBException('Prepare error: '.\ibase_errmsg());
56 56
         }
57 57
         return new Statement(
58 58
             $statement,
Please login to merge, or discard this patch.
src/driver/pdo/Statement.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,28 +24,28 @@
 block discarded – undo
24 24
         foreach ($data as $i => $v) {
25 25
             switch (gettype($v)) {
26 26
                 case 'boolean':
27
-                    $this->statement->bindValue($i+1, $v, \PDO::PARAM_BOOL);
27
+                    $this->statement->bindValue($i + 1, $v, \PDO::PARAM_BOOL);
28 28
                     break;
29 29
                 case 'integer':
30
-                    $this->statement->bindValue($i+1, $v, \PDO::PARAM_INT);
30
+                    $this->statement->bindValue($i + 1, $v, \PDO::PARAM_INT);
31 31
                     break;
32 32
                 case 'NULL':
33
-                    $this->statement->bindValue($i+1, $v, \PDO::PARAM_NULL);
33
+                    $this->statement->bindValue($i + 1, $v, \PDO::PARAM_NULL);
34 34
                     break;
35 35
                 case 'double':
36
-                    $this->statement->bindValue($i+1, $v);
36
+                    $this->statement->bindValue($i + 1, $v);
37 37
                     break;
38 38
                 default:
39 39
                     // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax:
40 40
                     // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ?
41 41
                     if (is_resource($v) && get_resource_type($v) === 'stream') {
42
-                        $this->statement->bindParam($i+1, $v, \PDO::PARAM_LOB);
42
+                        $this->statement->bindParam($i + 1, $v, \PDO::PARAM_LOB);
43 43
                         continue;
44 44
                     }
45 45
                     if (!is_string($data[$i])) {
46 46
                         $data[$i] = serialize($data[$i]);
47 47
                     }
48
-                    $this->statement->bindValue($i+1, $v);
48
+                    $this->statement->bindValue($i + 1, $v);
49 49
                     break;
50 50
             }
51 51
         }
Please login to merge, or discard this patch.
src/driver/pdo/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
     }
56 56
     public function next()
57 57
     {
58
-        $this->fetched ++;
58
+        $this->fetched++;
59 59
         $this->last = $this->statement->fetch(\PDO::FETCH_ASSOC);
60 60
     }
61 61
     public function valid()
Please login to merge, or discard this patch.
src/driver/pdo/Driver.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
                     isset($this->connection['opts']) ? $this->connection['opts'] : []
45 45
                 );
46 46
             } catch (\PDOException $e) {
47
-                throw new DBException('Connect error: ' . $e->getMessage());
47
+                throw new DBException('Connect error: '.$e->getMessage());
48 48
             }
49 49
         }
50 50
     }
Please login to merge, or discard this patch.
src/schema/TableColumn.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
             $instance->setDefault($data['default']);
48 48
         }
49 49
         if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) {
50
-            $temp = array_map(function ($v) {
50
+            $temp = array_map(function($v) {
51 51
                 return str_replace("''", "'", $v);
52 52
             }, explode("','", substr($instance->getType(), 6, -2)));
53 53
             $instance->setValues($temp);
Please login to merge, or discard this patch.
src/schema/Table.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     public function setPrimaryKey($column) : Table
79 79
     {
80 80
         if (!is_array($column)) {
81
-            $column = [ $column ];
81
+            $column = [$column];
82 82
         }
83 83
         $this->data['primary'] = $column;
84 84
         return $this;
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
         }
166 166
 
167 167
         if (!isset($name)) {
168
-            $name = $toTable->getName() . '_' . implode('_', array_keys($keymap));
168
+            $name = $toTable->getName().'_'.implode('_', array_keys($keymap));
169 169
         }
170 170
         $this->addRelation(new TableRelation(
171 171
             $name,
Please login to merge, or discard this patch.
src/driver/mysql/Statement.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
             }
84 84
         }
85 85
         if (!$this->statement->execute()) {
86
-            throw new DBException('Prepared execute error: ' . $this->statement->error);
86
+            throw new DBException('Prepared execute error: '.$this->statement->error);
87 87
         }
88 88
         return new Result($this->statement);
89 89
     }
Please login to merge, or discard this patch.
src/schema/TableQuery.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
     /**
61 61
      * Create an instance
62 62
      * @param  DBInterface    $db         the database connection
63
-     * @param  Table|string   $table      the name or definition of the main table in the query
63
+     * @param  Table   $table      the name or definition of the main table in the query
64 64
      */
65 65
     public function __construct(DBInterface $db, $table)
66 66
     {
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
     }
240 240
     /**
241 241
      * Group by a column (or columns)
242
-     * @param  string|array        $column the column name (or names) to group by
242
+     * @param  string        $column the column name (or names) to group by
243 243
      * @return $this
244 244
      */
245 245
     public function group($column) : TableQuery
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 use vakata\collection\Collection;
5 5
 use vakata\database\DBInterface;
6 6
 use vakata\database\DBException;
7
-use vakata\database\ResultInterface;
8 7
 
9 8
 /**
10 9
  * A database query class
Please login to merge, or discard this patch.
Spacing   +160 added lines, -164 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,15 +129,15 @@  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
     {
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
                 }
185 185
                 return $value;
186 186
             case 'int':
187
-                return (int)preg_replace('([^+\-0-9]+)', '', $value);
187
+                return (int) preg_replace('([^+\-0-9]+)', '', $value);
188 188
             case 'float':
189
-                return (float)preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
189
+                return (float) preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value));
190 190
             default:
191 191
                 return $value;
192 192
         }
@@ -204,35 +204,32 @@  discard block
 block discarded – undo
204 204
             // str_replace(['%', '_'], ['\\%','\\_'], $q)
205 205
             return $negate ?
206 206
                 [
207
-                    $name . ' NOT LIKE ?',
208
-                    [ $this->normalizeValue($column, $value) ]
209
-                ] :
210
-                [
211
-                    $name . ' LIKE ?',
212
-                    [ $this->normalizeValue($column, $value) ]
207
+                    $name.' NOT LIKE ?',
208
+                    [$this->normalizeValue($column, $value)]
209
+                ] : [
210
+                    $name.' LIKE ?',
211
+                    [$this->normalizeValue($column, $value)]
213 212
                 ];
214 213
         }
215 214
         if (is_null($value)) {
216 215
             return $negate ?
217
-                [ $name . ' IS NOT NULL', [] ]:
218
-                [ $name . ' IS NULL', [] ];
216
+                [$name.' IS NOT NULL', []] : [$name.' IS NULL', []];
219 217
         }
220 218
         if (!is_array($value)) {
221 219
             return $negate ?
222 220
                 [
223
-                    $name . ' <> ?',
224
-                    [ $this->normalizeValue($column, $value) ]
225
-                ] :
226
-                [
227
-                    $name . ' = ?',
228
-                    [ $this->normalizeValue($column, $value) ]
221
+                    $name.' <> ?',
222
+                    [$this->normalizeValue($column, $value)]
223
+                ] : [
224
+                    $name.' = ?',
225
+                    [$this->normalizeValue($column, $value)]
229 226
                 ];
230 227
         }
231 228
         if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) {
232
-            $value = [ 'gte' => $value['beg'] ];
229
+            $value = ['gte' => $value['beg']];
233 230
         }
234 231
         if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) {
235
-            $value = [ 'lte' => $value['end'] ];
232
+            $value = ['lte' => $value['end']];
236 233
         }
237 234
         if (isset($value['beg']) && isset($value['end'])) {
238 235
             return $negate ?
@@ -242,8 +239,7 @@  discard block
 block discarded – undo
242 239
                         $this->normalizeValue($column, $value['beg']),
243 240
                         $this->normalizeValue($column, $value['end'])
244 241
                     ]
245
-                ] :
246
-                [
242
+                ] : [
247 243
                     $name.' BETWEEN ? AND ?',
248 244
                     [
249 245
                         $this->normalizeValue($column, $value['beg']),
@@ -255,34 +251,34 @@  discard block
 block discarded – undo
255 251
             $sql = [];
256 252
             $par = [];
257 253
             if (isset($value['gt'])) {
258
-                $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?';
254
+                $sql[] = $name.' '.($negate ? '<=' : '>').' ?';
259 255
                 $par[] = $this->normalizeValue($column, $value['gt']);
260 256
             }
261 257
             if (isset($value['gte'])) {
262
-                $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?';
258
+                $sql[] = $name.' '.($negate ? '<' : '>=').' ?';
263 259
                 $par[] = $this->normalizeValue($column, $value['gte']);
264 260
             }
265 261
             if (isset($value['lt'])) {
266
-                $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?';
262
+                $sql[] = $name.' '.($negate ? '>=' : '<').' ?';
267 263
                 $par[] = $this->normalizeValue($column, $value['lt']);
268 264
             }
269 265
             if (isset($value['lte'])) {
270
-                $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?';
266
+                $sql[] = $name.' '.($negate ? '>' : '<=').' ?';
271 267
                 $par[] = $this->normalizeValue($column, $value['lte']);
272 268
             }
273 269
             return [
274
-                '(' . implode(' AND ', $sql) . ')',
270
+                '('.implode(' AND ', $sql).')',
275 271
                 $par
276 272
             ];
277 273
         }
278 274
         return $negate ?
279 275
             [
280
-                $name . ' NOT IN (??)',
281
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
276
+                $name.' NOT IN (??)',
277
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
282 278
             ] :
283 279
             [
284
-                $name . ' IN (??)',
285
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
280
+                $name.' IN (??)',
281
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
286 282
             ];
287 283
     }
288 284
     /**
@@ -313,7 +309,7 @@  discard block
 block discarded – undo
313 309
                 $par = array_merge($par, $temp[1]);
314 310
             }
315 311
         }
316
-        return $this->where('(' . implode(' OR ', $sql) . ')', $par);
312
+        return $this->where('('.implode(' OR ', $sql).')', $par);
317 313
     }
318 314
     /**
319 315
      * Filter the results matching all of the criteria
@@ -331,7 +327,7 @@  discard block
 block discarded – undo
331 327
                 $par = array_merge($par, $temp[1]);
332 328
             }
333 329
         }
334
-        return $this->where('(' . implode(' AND ', $sql) . ')', $par);
330
+        return $this->where('('.implode(' AND ', $sql).')', $par);
335 331
     }
336 332
     /**
337 333
      * Sort by a column
@@ -341,7 +337,7 @@  discard block
 block discarded – undo
341 337
      */
342 338
     public function sort(string $column, bool $desc = false) : TableQuery
343 339
     {
344
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
340
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
345 341
     }
346 342
     /**
347 343
      * Group by a column (or columns)
@@ -351,7 +347,7 @@  discard block
 block discarded – undo
351 347
     public function group($column) : TableQuery
352 348
     {
353 349
         if (!is_array($column)) {
354
-            $column = [ $column ];
350
+            $column = [$column];
355 351
         }
356 352
         foreach ($column as $k => $v) {
357 353
             $column[$k] = $this->getColumn($v)['name'];
@@ -393,7 +389,7 @@  discard block
 block discarded – undo
393 389
         $this->order = [];
394 390
         $this->having = [];
395 391
         $this->aliases = [];
396
-        $this->li_of = [0,0,0];
392
+        $this->li_of = [0, 0, 0];
397 393
         $this->qiterator = null;
398 394
         return $this;
399 395
     }
@@ -406,7 +402,7 @@  discard block
 block discarded – undo
406 402
     public function groupBy(string $sql, array $params = []) : TableQuery
407 403
     {
408 404
         $this->qiterator = null;
409
-        $this->group = [ $sql, $params ];
405
+        $this->group = [$sql, $params];
410 406
         return $this;
411 407
     }
412 408
     /**
@@ -419,7 +415,7 @@  discard block
 block discarded – undo
419 415
      */
420 416
     public function join($table, array $fields, string $name = null, bool $multiple = true)
421 417
     {
422
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
418
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
423 419
         $name = $name ?? $table->getName();
424 420
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
425 421
             throw new DBException('Alias / table name already in use');
@@ -428,7 +424,7 @@  discard block
 block discarded – undo
428 424
         foreach ($fields as $k => $v) {
429 425
             $k = explode('.', $k, 2);
430 426
             $k = count($k) == 2 ? $k[1] : $k[0];
431
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
427
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
432 428
         }
433 429
         return $this;
434 430
     }
@@ -441,7 +437,7 @@  discard block
 block discarded – undo
441 437
     public function where(string $sql, array $params = []) : TableQuery
442 438
     {
443 439
         $this->qiterator = null;
444
-        $this->where[] = [ $sql, $params ];
440
+        $this->where[] = [$sql, $params];
445 441
         return $this;
446 442
     }
447 443
     /**
@@ -453,7 +449,7 @@  discard block
 block discarded – undo
453 449
     public function having(string $sql, array $params = []) : TableQuery
454 450
     {
455 451
         $this->qiterator = null;
456
-        $this->having[] = [ $sql, $params ];
452
+        $this->having[] = [$sql, $params];
457 453
         return $this;
458 454
     }
459 455
     /**
@@ -465,7 +461,7 @@  discard block
 block discarded – undo
465 461
     public function order(string $sql, array $params = []) : TableQuery
466 462
     {
467 463
         $this->qiterator = null;
468
-        $this->order = [ $sql, $params ];
464
+        $this->order = [$sql, $params];
469 465
         return $this;
470 466
     }
471 467
     /**
@@ -477,7 +473,7 @@  discard block
 block discarded – undo
477 473
     public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : TableQuery
478 474
     {
479 475
         $this->qiterator = null;
480
-        $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ];
476
+        $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0];
481 477
         return $this;
482 478
     }
483 479
     /**
@@ -487,9 +483,9 @@  discard block
 block discarded – undo
487 483
     public function count() : int
488 484
     {
489 485
         $aliases = [];
490
-        $getAlias = function ($name) use (&$aliases) {
486
+        $getAlias = function($name) use (&$aliases) {
491 487
             // to bypass use: return $name;
492
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
488
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
493 489
         };
494 490
         $table = $this->definition->getName();
495 491
         $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' ';
@@ -504,44 +500,44 @@  discard block
 block discarded – undo
504 500
         $h = $this->having;
505 501
         $o = $this->order;
506 502
         $g = $this->group;
507
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
503
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
508 504
         foreach ($this->definition->getRelations() as $k => $v) {
509 505
             foreach ($w as $kk => $vv) {
510
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
511
-                    $relations[$k] = [ $v, $table ];
512
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
506
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
507
+                    $relations[$k] = [$v, $table];
508
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
513 509
                 }
514 510
             }
515
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
516
-                $relations[$k] = [ $v, $table ];
511
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
512
+                $relations[$k] = [$v, $table];
517 513
             }
518 514
             foreach ($h as $kk => $vv) {
519
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
520
-                    $relations[$k] = [ $relation, $table ];
521
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
515
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
516
+                    $relations[$k] = [$relation, $table];
517
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
522 518
                 }
523 519
             }
524
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
525
-                $relations[$k] = [ $relation, $table ];
526
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
520
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
521
+                $relations[$k] = [$relation, $table];
522
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
527 523
             }
528 524
             foreach ($j as $kk => $v) {
529 525
                 foreach ($v->keymap as $kkk => $vv) {
530
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
531
-                        $relations[$k] = [ $relation, $table ];
532
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
526
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
527
+                        $relations[$k] = [$relation, $table];
528
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
533 529
                     }
534 530
                 }
535 531
             }
536 532
         }
537 533
 
538 534
         foreach ($j as $k => $v) {
539
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
535
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
540 536
             $tmp = [];
541 537
             foreach ($v->keymap as $kk => $vv) {
542 538
                 $tmp[] = $kk.' = '.$vv;
543 539
             }
544
-            $sql .= implode(' AND ', $tmp) . ' ';
540
+            $sql .= implode(' AND ', $tmp).' ';
545 541
         }
546 542
         foreach ($relations as $k => $v) {
547 543
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -553,13 +549,13 @@  discard block
 block discarded – undo
553 549
                 foreach ($v->keymap as $kk => $vv) {
554 550
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
555 551
                 }
556
-                $sql .= implode(' AND ', $tmp) . ' ';
552
+                $sql .= implode(' AND ', $tmp).' ';
557 553
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
558 554
                 $tmp = [];
559 555
                 foreach ($v->pivot_keymap as $kk => $vv) {
560 556
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
561 557
                 }
562
-                $sql .= implode(' AND ', $tmp) . ' ';
558
+                $sql .= implode(' AND ', $tmp).' ';
563 559
             } else {
564 560
                 $alias = $getAlias($k);
565 561
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -568,30 +564,30 @@  discard block
 block discarded – undo
568 564
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
569 565
                 }
570 566
                 if ($v->sql) {
571
-                    $tmp[] = $v->sql . ' ';
567
+                    $tmp[] = $v->sql.' ';
572 568
                     $par = array_merge($par, $v->par ?? []);
573 569
                 }
574
-                $sql .= implode(' AND ', $tmp) . ' ';
570
+                $sql .= implode(' AND ', $tmp).' ';
575 571
             }
576 572
         }
577 573
         if (count($w)) {
578 574
             $sql .= 'WHERE ';
579 575
             $tmp = [];
580 576
             foreach ($w as $v) {
581
-                $tmp[] = '(' . $v[0] . ')';
577
+                $tmp[] = '('.$v[0].')';
582 578
                 $par = array_merge($par, $v[1]);
583 579
             }
584 580
             $sql .= implode(' AND ', $tmp).' ';
585 581
         }
586 582
         if (count($g)) {
587
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
583
+            $sql .= 'GROUP BY '.$g[0].' ';
588 584
             $par = array_merge($par, $g[1]);
589 585
         }
590 586
         if (count($h)) {
591 587
             $sql .= 'HAVING ';
592 588
             $tmp = [];
593 589
             foreach ($h as $v) {
594
-                $tmp[] = '(' . $v[0] . ')';
590
+                $tmp[] = '('.$v[0].')';
595 591
                 $par = array_merge($par, $v[1]);
596 592
             }
597 593
             $sql .= implode(' AND ', $tmp).' ';
@@ -625,7 +621,7 @@  discard block
 block discarded – undo
625 621
                     $this->with(implode('.', $temp));
626 622
                     $table = array_reduce(
627 623
                         $temp,
628
-                        function ($carry, $item) use (&$table) {
624
+                        function($carry, $item) use (&$table) {
629 625
                             return $table->getRelation($item)->table;
630 626
                         }
631 627
                     );
@@ -634,7 +630,7 @@  discard block
 block discarded – undo
634 630
                 }
635 631
                 unset($fields[$k]);
636 632
                 foreach ($cols as $col) {
637
-                    $fields[] = $table . '.' . $col;
633
+                    $fields[] = $table.'.'.$col;
638 634
                 }
639 635
             }
640 636
         }
@@ -666,9 +662,9 @@  discard block
 block discarded – undo
666 662
             return $this->qiterator;
667 663
         }
668 664
         $aliases = [];
669
-        $getAlias = function ($name) use (&$aliases) {
665
+        $getAlias = function($name) use (&$aliases) {
670 666
             // to bypass use: return $name;
671
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
667
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
672 668
         };
673 669
         $table = $this->definition->getName();
674 670
         if ($fields !== null) {
@@ -684,7 +680,7 @@  discard block
 block discarded – undo
684 680
         $h = $this->having;
685 681
         $o = $this->order;
686 682
         $g = $this->group;
687
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
683
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
688 684
 
689 685
         $porder = [];
690 686
         foreach ($this->definition->getPrimaryKey() as $field) {
@@ -697,9 +693,9 @@  discard block
 block discarded – undo
697 693
                 if (count($porder) > 1) {
698 694
                     $pkw = [];
699 695
                     foreach ($porder as $name) {
700
-                        $pkw[] = $name . ' = ?';
696
+                        $pkw[] = $name.' = ?';
701 697
                     }
702
-                    $pkw = '(' . implode(' AND ', $pkw) . ')';
698
+                    $pkw = '('.implode(' AND ', $pkw).')';
703 699
                     $pkp = [];
704 700
                     foreach ($ids as $id) {
705 701
                         foreach ($id as $p) {
@@ -711,67 +707,67 @@  discard block
 block discarded – undo
711 707
                         $pkp
712 708
                     ];
713 709
                 } else {
714
-                    $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ];
710
+                    $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids];
715 711
                 }
716 712
             } else {
717
-                $w[] = [ '1=0', [] ];
713
+                $w[] = ['1=0', []];
718 714
             }
719 715
         }
720 716
 
721 717
         foreach ($this->definition->getRelations() as $k => $relation) {
722 718
             foreach ($f as $kk => $field) {
723
-                if (strpos($field, $k . '.') === 0) {
724
-                    $relations[$k] = [ $relation, $table ];
725
-                    $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field);
719
+                if (strpos($field, $k.'.') === 0) {
720
+                    $relations[$k] = [$relation, $table];
721
+                    $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field);
726 722
                 }
727 723
             }
728 724
             foreach ($w as $kk => $v) {
729
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
730
-                    $relations[$k] = [ $relation, $table ];
731
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
725
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
726
+                    $relations[$k] = [$relation, $table];
727
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
732 728
                 }
733 729
             }
734 730
             foreach ($h as $kk => $v) {
735
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) {
736
-                    $relations[$k] = [ $relation, $table ];
737
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]);
731
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) {
732
+                    $relations[$k] = [$relation, $table];
733
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]);
738 734
                 }
739 735
             }
740
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
741
-                $relations[$k] = [ $relation, $table ];
742
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
736
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
737
+                $relations[$k] = [$relation, $table];
738
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
743 739
             }
744
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
745
-                $relations[$k] = [ $relation, $table ];
746
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
740
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
741
+                $relations[$k] = [$relation, $table];
742
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
747 743
             }
748 744
             foreach ($j as $kk => $v) {
749 745
                 foreach ($v->keymap as $kkk => $vv) {
750
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
751
-                        $relations[$k] = [ $relation, $table ];
752
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
746
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
747
+                        $relations[$k] = [$relation, $table];
748
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
753 749
                     }
754 750
                 }
755 751
             }
756 752
         }
757 753
         $select = [];
758 754
         foreach ($f as $k => $field) {
759
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
755
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
760 756
         }
761 757
         foreach ($this->withr as $name => $relation) {
762 758
             foreach ($relation[0]->table->getColumns() as $column) {
763
-                $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column);
759
+                $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column);
764 760
             }
765 761
         }
766 762
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
767 763
         $par = [];
768 764
         foreach ($j as $k => $v) {
769
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
765
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
770 766
             $tmp = [];
771 767
             foreach ($v->keymap as $kk => $vv) {
772 768
                 $tmp[] = $kk.' = '.$vv;
773 769
             }
774
-            $sql .= implode(' AND ', $tmp) . ' ';
770
+            $sql .= implode(' AND ', $tmp).' ';
775 771
         }
776 772
         foreach ($relations as $relation => $v) {
777 773
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -783,13 +779,13 @@  discard block
 block discarded – undo
783 779
                 foreach ($v->keymap as $kk => $vv) {
784 780
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
785 781
                 }
786
-                $sql .= implode(' AND ', $tmp) . ' ';
782
+                $sql .= implode(' AND ', $tmp).' ';
787 783
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($relation).' ON ';
788 784
                 $tmp = [];
789 785
                 foreach ($v->pivot_keymap as $kk => $vv) {
790 786
                     $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' ';
791 787
                 }
792
-                $sql .= implode(' AND ', $tmp) . ' ';
788
+                $sql .= implode(' AND ', $tmp).' ';
793 789
             } else {
794 790
                 $alias = $getAlias($relation);
795 791
 
@@ -799,62 +795,62 @@  discard block
 block discarded – undo
799 795
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
800 796
                 }
801 797
                 if ($v->sql) {
802
-                    $tmp[] = $v->sql . ' ';
798
+                    $tmp[] = $v->sql.' ';
803 799
                     $par = array_merge($par, $v->par ?? []);
804 800
                 }
805
-                $sql .= implode(' AND ', $tmp) . ' ';
801
+                $sql .= implode(' AND ', $tmp).' ';
806 802
             }
807 803
         }
808 804
         if (count($w)) {
809 805
             $sql .= 'WHERE ';
810 806
             $tmp = [];
811 807
             foreach ($w as $v) {
812
-                $tmp[] = '(' . $v[0] . ')';
808
+                $tmp[] = '('.$v[0].')';
813 809
                 $par = array_merge($par, $v[1]);
814 810
             }
815 811
             $sql .= implode(' AND ', $tmp).' ';
816 812
         }
817 813
         if (count($g)) {
818
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
814
+            $sql .= 'GROUP BY '.$g[0].' ';
819 815
             $par = array_merge($par, $g[1]);
820 816
         }
821 817
         if (count($h)) {
822 818
             $sql .= 'HAVING ';
823 819
             $tmp = [];
824 820
             foreach ($h as $v) {
825
-                $tmp[] = '(' . $v[0] . ')';
821
+                $tmp[] = '('.$v[0].')';
826 822
                 $par = array_merge($par, $v[1]);
827 823
             }
828 824
             $sql .= implode(' AND ', $tmp).' ';
829 825
         }
830 826
         if (count($o)) {
831
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
827
+            $sql .= 'ORDER BY '.$o[0].' ';
832 828
             $par = array_merge($par, $o[1]);
833 829
         }
834 830
         if (count($porder)) {
835
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
831
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
836 832
         }
837 833
         if (($this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) {
838 834
             if ($this->db->driverName() === 'oracle') {
839
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
840
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
835
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
836
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
841 837
                 } else {
842
-                    $f = array_map(function ($v) {
838
+                    $f = array_map(function($v) {
843 839
                         $v = explode(' ', trim($v), 2);
844 840
                         if (count($v) === 2) { return $v[1]; }
845 841
                         $v = explode('.', $v[0], 2);
846 842
                         return count($v) === 2 ? $v[1] : $v[0];
847 843
                     }, $select);
848
-                    $sql = "SELECT " . implode(', ', $f) . " 
844
+                    $sql = "SELECT ".implode(', ', $f)." 
849 845
                             FROM (
850 846
                                 SELECT tbl__.*, rownum rnum__ FROM (
851
-                                    " . $sql . "
847
+                                    " . $sql."
852 848
                                 ) tbl__ 
853
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
849
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
854 850
                             ) WHERE rnum__ > " . $this->li_of[1];
855 851
                 }
856 852
             } else {
857
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
853
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
858 854
             }
859 855
         }
860 856
         return $this->qiterator = new TableQueryIterator(
@@ -904,7 +900,7 @@  discard block
 block discarded – undo
904 900
                 $ret[$k] = str_repeat(' ', 255);
905 901
                 $par[] = &$ret[$k];
906 902
             }
907
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
903
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
908 904
             $this->db->query($sql, $par);
909 905
             return $ret;
910 906
         } else {
@@ -936,7 +932,7 @@  discard block
 block discarded – undo
936 932
         }
937 933
         $sql = 'UPDATE '.$table.' SET ';
938 934
         $par = [];
939
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
935
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
940 936
         $par = array_merge($par, array_values($update));
941 937
         if (count($this->where)) {
942 938
             $sql .= 'WHERE ';
@@ -945,7 +941,7 @@  discard block
 block discarded – undo
945 941
                 $tmp[] = $v[0];
946 942
                 $par = array_merge($par, $v[1]);
947 943
             }
948
-            $sql .= implode(' AND ', $tmp) . ' ';
944
+            $sql .= implode(' AND ', $tmp).' ';
949 945
         }
950 946
         if (count($this->order)) {
951 947
             $sql .= $this->order[0];
@@ -969,7 +965,7 @@  discard block
 block discarded – undo
969 965
                 $tmp[] = $v[0];
970 966
                 $par = array_merge($par, $v[1]);
971 967
             }
972
-            $sql .= implode(' AND ', $tmp) . ' ';
968
+            $sql .= implode(' AND ', $tmp).' ';
973 969
         }
974 970
         if (count($this->order)) {
975 971
             $sql .= $this->order[0];
@@ -989,13 +985,13 @@  discard block
 block discarded – undo
989 985
         $table = $this->definition;
990 986
         array_reduce(
991 987
             $parts,
992
-            function ($carry, $item) use (&$table) {
988
+            function($carry, $item) use (&$table) {
993 989
                 $relation = $table->getRelation($item);
994 990
                 if (!$relation) {
995 991
                     throw new DBException('Invalid relation name');
996 992
                 }
997
-                $name = $carry ? $carry . static::SEP . $item : $item;
998
-                $this->withr[$name] = [ $relation, $carry ?? $table->getName() ];
993
+                $name = $carry ? $carry.static::SEP.$item : $item;
994
+                $this->withr[$name] = [$relation, $carry ?? $table->getName()];
999 995
                 $table = $relation->table;
1000 996
                 return $name;
1001 997
             }
@@ -1033,9 +1029,9 @@  discard block
 block discarded – undo
1033 1029
     public function ids()
1034 1030
     {
1035 1031
         $aliases = [];
1036
-        $getAlias = function ($name) use (&$aliases) {
1032
+        $getAlias = function($name) use (&$aliases) {
1037 1033
             // to bypass use: return $name;
1038
-            return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases);
1034
+            return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases);
1039 1035
         };
1040 1036
         $table = $this->definition->getName();
1041 1037
         $sql = 'SELECT DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).' FROM '.$table.' ';
@@ -1050,45 +1046,45 @@  discard block
 block discarded – undo
1050 1046
         $h = $this->having;
1051 1047
         $o = $this->order;
1052 1048
         $g = $this->group;
1053
-        $j = array_map(function ($v) { return clone $v; }, $this->joins);
1049
+        $j = array_map(function($v) { return clone $v; }, $this->joins);
1054 1050
         foreach ($this->definition->getRelations() as $k => $v) {
1055 1051
             foreach ($w as $kk => $vv) {
1056
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1057
-                    $relations[$k] = [ $v, $table ];
1058
-                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1052
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1053
+                    $relations[$k] = [$v, $table];
1054
+                    $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1059 1055
                 }
1060 1056
             }
1061
-            if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) {
1062
-                $relations[$k] = [ $v, $table ];
1063
-                $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]);
1057
+            if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) {
1058
+                $relations[$k] = [$v, $table];
1059
+                $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]);
1064 1060
             }
1065 1061
             foreach ($h as $kk => $vv) {
1066
-                if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) {
1067
-                    $relations[$k] = [ $relation, $table ];
1068
-                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]);
1062
+                if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) {
1063
+                    $relations[$k] = [$relation, $table];
1064
+                    $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]);
1069 1065
                 }
1070 1066
             }
1071
-            if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) {
1072
-                $relations[$k] = [ $relation, $table ];
1073
-                $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]);
1067
+            if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) {
1068
+                $relations[$k] = [$relation, $table];
1069
+                $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]);
1074 1070
             }
1075 1071
             foreach ($j as $kk => $v) {
1076 1072
                 foreach ($v->keymap as $kkk => $vv) {
1077
-                    if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) {
1078
-                        $relations[$k] = [ $relation, $table ];
1079
-                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv);
1073
+                    if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) {
1074
+                        $relations[$k] = [$relation, $table];
1075
+                        $j[$k]->keymap[$kkk] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv);
1080 1076
                     }
1081 1077
                 }
1082 1078
             }
1083 1079
         }
1084 1080
 
1085 1081
         foreach ($j as $k => $v) {
1086
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
1082
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
1087 1083
             $tmp = [];
1088 1084
             foreach ($v->keymap as $kk => $vv) {
1089 1085
                 $tmp[] = $kk.' = '.$vv;
1090 1086
             }
1091
-            $sql .= implode(' AND ', $tmp) . ' ';
1087
+            $sql .= implode(' AND ', $tmp).' ';
1092 1088
         }
1093 1089
         foreach ($relations as $k => $v) {
1094 1090
             $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1];
@@ -1100,13 +1096,13 @@  discard block
 block discarded – undo
1100 1096
                 foreach ($v->keymap as $kk => $vv) {
1101 1097
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1102 1098
                 }
1103
-                $sql .= implode(' AND ', $tmp) . ' ';
1099
+                $sql .= implode(' AND ', $tmp).' ';
1104 1100
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON ';
1105 1101
                 $tmp = [];
1106 1102
                 foreach ($v->pivot_keymap as $kk => $vv) {
1107 1103
                     $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' ';
1108 1104
                 }
1109
-                $sql .= implode(' AND ', $tmp) . ' ';
1105
+                $sql .= implode(' AND ', $tmp).' ';
1110 1106
             } else {
1111 1107
                 $alias = $getAlias($k);
1112 1108
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON ';
@@ -1115,36 +1111,36 @@  discard block
 block discarded – undo
1115 1111
                     $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' ';
1116 1112
                 }
1117 1113
                 if ($v->sql) {
1118
-                    $tmp[] = $v->sql . ' ';
1114
+                    $tmp[] = $v->sql.' ';
1119 1115
                     $par = array_merge($par, $v->par ?? []);
1120 1116
                 }
1121
-                $sql .= implode(' AND ', $tmp) . ' ';
1117
+                $sql .= implode(' AND ', $tmp).' ';
1122 1118
             }
1123 1119
         }
1124 1120
         if (count($w)) {
1125 1121
             $sql .= 'WHERE ';
1126 1122
             $tmp = [];
1127 1123
             foreach ($w as $v) {
1128
-                $tmp[] = '(' . $v[0] . ')';
1124
+                $tmp[] = '('.$v[0].')';
1129 1125
                 $par = array_merge($par, $v[1]);
1130 1126
             }
1131 1127
             $sql .= implode(' AND ', $tmp).' ';
1132 1128
         }
1133 1129
         if (count($g)) {
1134
-            $sql .= 'GROUP BY ' . $g[0] . ' ';
1130
+            $sql .= 'GROUP BY '.$g[0].' ';
1135 1131
             $par = array_merge($par, $g[1]);
1136 1132
         }
1137 1133
         if (count($h)) {
1138 1134
             $sql .= 'HAVING ';
1139 1135
             $tmp = [];
1140 1136
             foreach ($h as $v) {
1141
-                $tmp[] = '(' . $v[0] . ')';
1137
+                $tmp[] = '('.$v[0].')';
1142 1138
                 $par = array_merge($par, $v[1]);
1143 1139
             }
1144 1140
             $sql .= implode(' AND ', $tmp).' ';
1145 1141
         }
1146 1142
         if (count($o)) {
1147
-            $sql .= 'ORDER BY ' . $o[0] . ' ';
1143
+            $sql .= 'ORDER BY '.$o[0].' ';
1148 1144
             $par = array_merge($par, $o[1]);
1149 1145
         }
1150 1146
         $porder = [];
@@ -1152,30 +1148,30 @@  discard block
 block discarded – undo
1152 1148
             $porder[] = $this->getColumn($field)['name'];
1153 1149
         }
1154 1150
         if (count($porder)) {
1155
-            $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
1151
+            $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
1156 1152
         }
1157 1153
 
1158 1154
         if ($this->li_of[0]) {
1159 1155
             if ($this->db->driverName() === 'oracle') {
1160
-                if ((int)$this->db->driverOption('version', 0) >= 12) {
1161
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
1156
+                if ((int) $this->db->driverOption('version', 0) >= 12) {
1157
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
1162 1158
                 } else {
1163
-                    $f = array_map(function ($v) {
1159
+                    $f = array_map(function($v) {
1164 1160
                         $v = explode(' ', trim($v), 2);
1165 1161
                         if (count($v) === 2) { return $v[1]; }
1166 1162
                         $v = explode('.', $v[0], 2);
1167 1163
                         return count($v) === 2 ? $v[1] : $v[0];
1168 1164
                     }, $select);
1169
-                    $sql = "SELECT " . implode(', ', $f) . " 
1165
+                    $sql = "SELECT ".implode(', ', $f)." 
1170 1166
                             FROM (
1171 1167
                                 SELECT tbl__.*, rownum rnum__ FROM (
1172
-                                    " . $sql . "
1168
+                                    " . $sql."
1173 1169
                                 ) tbl__ 
1174
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
1170
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
1175 1171
                             ) WHERE rnum__ > " . $this->li_of[1];
1176 1172
                 }
1177 1173
             } else {
1178
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
1174
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
1179 1175
             }
1180 1176
         }
1181 1177
         return $this->db->all($sql, $par);
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +13 added lines, -15 removed lines patch added patch discarded remove patch
@@ -74,8 +74,7 @@  discard block
 block discarded – undo
74 74
         }
75 75
         $connection['name'] = $connectionString;
76 76
         $connection['type'] = isset($aliases[$connection['type']]) ?
77
-            $aliases[$connection['type']] :
78
-            $connection['type'];
77
+            $aliases[$connection['type']] : $connection['type'];
79 78
         $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver';
80 79
         return new $tmp($connection);
81 80
     }
@@ -95,7 +94,7 @@  discard block
 block discarded – undo
95 94
         $new = '';
96 95
         $par = array_values($par);
97 96
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
98
-            $par = [ $par ];
97
+            $par = [$par];
99 98
         }
100 99
         $parts = explode('??', $sql);
101 100
         $index = 0;
@@ -105,7 +104,7 @@  discard block
 block discarded – undo
105 104
             $index += count($tmp) - 1;
106 105
             if (isset($par[$index])) {
107 106
                 if (!is_array($par[$index])) {
108
-                    $par[$index] = [ $par[$index] ];
107
+                    $par[$index] = [$par[$index]];
109 108
                 }
110 109
                 $params = $par[$index];
111 110
                 array_splice($par, $index, 1, $params);
@@ -113,7 +112,7 @@  discard block
 block discarded – undo
113 112
                 $new .= implode(',', array_fill(0, count($params), '?'));
114 113
             }
115 114
         }
116
-        return [ $new, $par ];
115
+        return [$new, $par];
117 116
     }
118 117
     /**
119 118
      * Run a query (prepare & execute).
@@ -145,7 +144,7 @@  discard block
 block discarded – undo
145 144
     {
146 145
         $coll = Collection::from($this->query($sql, $par));
147 146
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
148
-            $coll->map(function ($v) use ($keys) {
147
+            $coll->map(function($v) use ($keys) {
149 148
                 $new = [];
150 149
                 foreach ($v as $k => $vv) {
151 150
                     $new[call_user_func($keys, $k)] = $vv;
@@ -154,13 +153,13 @@  discard block
 block discarded – undo
154 153
             });
155 154
         }
156 155
         if ($key !== null) {
157
-            $coll->mapKey(function ($v) use ($key) { return $v[$key]; });
156
+            $coll->mapKey(function($v) use ($key) { return $v[$key]; });
158 157
         }
159 158
         if ($skip) {
160
-            $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; });
159
+            $coll->map(function($v) use ($key) { unset($v[$key]); return $v; });
161 160
         }
162 161
         if ($opti) {
163
-            $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; });
162
+            $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; });
164 163
         }
165 164
         return $coll;
166 165
     }
@@ -233,8 +232,7 @@  discard block
 block discarded – undo
233 232
     public function definition(string $table, bool $detectRelations = true) : Table
234 233
     {
235 234
         return isset($this->tables[$table]) ?
236
-            $this->tables[$table] :
237
-            $this->driver->table($table, $detectRelations);
235
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
238 236
     }
239 237
     /**
240 238
      * Parse all tables from the database.
@@ -251,12 +249,12 @@  discard block
 block discarded – undo
251 249
      */
252 250
     public function getSchema($asPlainArray = true)
253 251
     {
254
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
252
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
255 253
             return [
256 254
                 'name' => $table->getName(),
257 255
                 'pkey' => $table->getPrimaryKey(),
258 256
                 'comment' => $table->getComment(),
259
-                'columns' => array_map(function ($column) {
257
+                'columns' => array_map(function($column) {
260 258
                     return [
261 259
                         'name' => $column->getName(),
262 260
                         'type' => $column->getType(),
@@ -266,13 +264,13 @@  discard block
 block discarded – undo
266 264
                         'nullable' => $column->isNullable()
267 265
                     ];
268 266
                 }, $table->getFullColumns()),
269
-                'relations' => array_map(function ($rel) {
267
+                'relations' => array_map(function($rel) {
270 268
                     $relation = clone $rel;
271 269
                     $relation->table = $relation->table->getName();
272 270
                     if ($relation->pivot) {
273 271
                         $relation->pivot = $relation->pivot->getName();
274 272
                     }
275
-                    return (array)$relation;
273
+                    return (array) $relation;
276 274
                 }, $table->getRelations())
277 275
             ];
278 276
         }, $this->tables);
Please login to merge, or discard this patch.