Completed
Branch master (b71ad6)
by Ivan
03:07
created
src/DB.php 2 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,6 +43,9 @@  discard block
 block discarded – undo
43 43
         $this->drv = $drv;
44 44
     }
45 45
 
46
+    /**
47
+     * @param string $sql
48
+     */
46 49
     protected function expand($sql, $data)
47 50
     {
48 51
         $new = '';
@@ -159,7 +162,7 @@  discard block
 block discarded – undo
159 162
      * @param string $mode     result mode - `"assoc"` by default, could be `"num"`, `"both"`, `"assoc_ci"`, `"assoc_lc"`, `"assoc_uc"`
160 163
      * @param bool   $opti     if a single column is returned - do not use an array wrapper (defaults to `true`)
161 164
      *
162
-     * @return mixed the result of the execution
165
+     * @return string the result of the execution
163 166
      */
164 167
     public function one($sql, $data = null, $mode = null, $opti = true)
165 168
     {
@@ -256,7 +259,7 @@  discard block
 block discarded – undo
256 259
      * @param  string            $table the table to analyze
257 260
      * @param  bool      $detectRelations should relations be extracted - defaults to `true`
258 261
      * @param  bool      $lowerCase should the table fields be converted to lowercase - defaults to `true`
259
-     * @return  the newly added definition
262
+     * @return  Table newly added definition
260 263
      */
261 264
     public function definition(
262 265
         string $table,
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function __construct($options)
32 32
     {
33
-        $this->settings = new Settings((string)$options);
33
+        $this->settings = new Settings((string) $options);
34 34
         try {
35 35
             $tmp = '\\vakata\\database\\driver\\'.ucfirst($this->settings->type);
36 36
             $drv = new $tmp($this->settings);
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
     {
48 48
         $new = '';
49 49
         if (!is_array($data)) {
50
-            $data = [ $data ];
50
+            $data = [$data];
51 51
         }
52 52
         $data = array_values($data);
53 53
         if (substr_count($sql, '?') === 2 && !is_array($data[0])) {
54
-            $data = [ $data ];
54
+            $data = [$data];
55 55
         }
56 56
         $parts = explode('??', $sql);
57 57
         $index = 0;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
             $index += count($tmp) - 1;
62 62
             if (isset($data[$index])) {
63 63
                 if (!is_array($data[$index])) {
64
-                    $data[$index] = [ $data[$index] ];
64
+                    $data[$index] = [$data[$index]];
65 65
                 }
66 66
                 $params = $data[$index];
67 67
                 array_splice($data, $index, 1, $params);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                 $new .= implode(',', array_fill(0, count($params), '?'));
70 70
             }
71 71
         }
72
-        return [ $new, $data ];
72
+        return [$new, $data];
73 73
     }
74 74
 
75 75
     /**
@@ -280,15 +280,15 @@  discard block
 block discarded – undo
280 280
                         $primary[] = $data['Field'];
281 281
                     }
282 282
                 }
283
-                $comment = (string)$this->one(
283
+                $comment = (string) $this->one(
284 284
                     "SELECT table_comment FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
285
-                    [ $this->name(), $table ]
285
+                    [$this->name(), $table]
286 286
                 );
287 287
                 break;
288 288
             case 'postgre':
289 289
                 $columns = $this->all(
290 290
                     "SELECT * FROM information_schema.columns WHERE table_schema = ? AND table_name = ?",
291
-                    [ $this->name(), $table ],
291
+                    [$this->name(), $table],
292 292
                     'column_name',
293 293
                     false,
294 294
                     'assoc_lc'
@@ -296,20 +296,20 @@  discard block
 block discarded – undo
296 296
                 $pkname = $this->one(
297 297
                     "SELECT constraint_name FROM information_schema.table_constraints
298 298
                     WHERE table_schema = ? AND table_name = ? AND constraint_type = ?",
299
-                    [ $this->name(), $table, 'PRIMARY KEY' ]
299
+                    [$this->name(), $table, 'PRIMARY KEY']
300 300
                 );
301 301
                 if ($pkname) {
302 302
                     $primary = $this->all(
303 303
                         "SELECT column_name FROM information_schema.key_column_usage
304 304
                         WHERE table_schema = ? AND table_name = ? AND constraint_name = ?",
305
-                        [ $this->name(), $table, $pkname ]
305
+                        [$this->name(), $table, $pkname]
306 306
                     );
307 307
                 }
308 308
                 break;
309 309
             case 'oracle':
310 310
                 $columns = $this->all(
311 311
                     "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?",
312
-                    [ strtoupper($table), $this->name() ],
312
+                    [strtoupper($table), $this->name()],
313 313
                     'COLUMN_NAME',
314 314
                     false,
315 315
                     'assoc_uc'
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
                 $pkname = $this->one(
319 319
                     "SELECT constraint_name FROM all_constraints
320 320
                     WHERE table_name = ? AND constraint_type = ? AND owner = ?",
321
-                    [ strtoupper($table), 'P', $owner ]
321
+                    [strtoupper($table), 'P', $owner]
322 322
                 );
323 323
                 if ($pkname) {
324 324
                     $primary = $this->all(
325 325
                         "SELECT column_name FROM all_cons_columns
326 326
                         WHERE table_name = ? AND constraint_name = ? AND owner = ?",
327
-                        [ strtoupper($table), $pkname, $owner ]
327
+                        [strtoupper($table), $pkname, $owner]
328 328
                     );
329 329
                 }
330 330
                 break;
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
                         "SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_COLUMN_NAME
366 366
                         FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
367 367
                         WHERE TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND REFERENCED_TABLE_NAME = ?",
368
-                        [ $this->name(), $this->name(), $table ],
368
+                        [$this->name(), $this->name(), $table],
369 369
                         null,
370 370
                         false,
371 371
                         'assoc_uc'
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
                                 WHERE
393 393
                                     TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME IN (??) AND
394 394
                                     REFERENCED_TABLE_NAME IS NOT NULL",
395
-                                [ $this->name(), $data['table'], $columns ],
395
+                                [$this->name(), $data['table'], $columns],
396 396
                                 null,
397 397
                                 false,
398 398
                                 'assoc_uc'
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
                             $relname = $foreign['table'];
408 408
                             $cntr = 1;
409 409
                             while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
410
-                                $relname = $foreign['table'] . '_' . (++ $cntr);
410
+                                $relname = $foreign['table'].'_'.(++$cntr);
411 411
                             }
412 412
                             $definition->addRelation(
413 413
                                 new TableRelation(
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
                             $relname = $data['table'];
424 424
                             $cntr = 1;
425 425
                             while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
426
-                                $relname = $data['table'] . '_' . (++ $cntr);
426
+                                $relname = $data['table'].'_'.(++$cntr);
427 427
                             }
428 428
                             $definition->addRelation(
429 429
                                 new TableRelation(
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
                         "SELECT TABLE_NAME, COLUMN_NAME, CONSTRAINT_NAME, REFERENCED_TABLE_NAME, REFERENCED_COLUMN_NAME
444 444
                         FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
445 445
                         WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND REFERENCED_TABLE_NAME IS NOT NULL",
446
-                        [ $this->name(), $table ],
446
+                        [$this->name(), $table],
447 447
                         null,
448 448
                         false,
449 449
                         'assoc_uc'
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
                         $relname = $data['table'];
456 456
                         $cntr = 1;
457 457
                         while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
458
-                            $relname = $data['table'] . '_' . (++ $cntr);
458
+                            $relname = $data['table'].'_'.(++$cntr);
459 459
                         }
460 460
                         $definition->addRelation(
461 461
                             new TableRelation(
@@ -478,13 +478,13 @@  discard block
 block discarded – undo
478 478
                         LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
479 479
                         WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
480 480
                         ORDER BY cc.POSITION",
481
-                        [ $owner, $owner, $pkname, 'R' ],
481
+                        [$owner, $owner, $pkname, 'R'],
482 482
                         null,
483 483
                         false,
484 484
                         'assoc_uc'
485 485
                     ) as $k => $relation) {
486 486
                         $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
487
-                        $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME'];
487
+                        $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME'];
488 488
                     }
489 489
                     foreach ($relations as $data) {
490 490
                         $rtable = $this->definition($data['table'], true, $lowerCase); // ?? $this->addTableByName($data['table'], false);
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
                                     ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
508 508
                                     cc.COLUMN_NAME IN (??)
509 509
                                 ORDER BY POSITION",
510
-                                [ $owner, $owner, $data['table'], 'R', $columns ],
510
+                                [$owner, $owner, $data['table'], 'R', $columns],
511 511
                                 null,
512 512
                                 false,
513 513
                                 'assoc_uc'
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
                             $foreign = current($foreign);
522 522
                             $rcolumns = $this->all(
523 523
                                 "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
524
-                                [ $owner, current($foreign['keymap']) ],
524
+                                [$owner, current($foreign['keymap'])],
525 525
                                 null, false, 'assoc_uc'
526 526
                             );
527 527
                             foreach ($foreign['keymap'] as $column => $related) {
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
                             $relname = $foreign['table'];
531 531
                             $cntr = 1;
532 532
                             while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
533
-                                $relname = $foreign['table'] . '_' . (++ $cntr);
533
+                                $relname = $foreign['table'].'_'.(++$cntr);
534 534
                             }
535 535
                             $definition->addRelation(
536 536
                                 new TableRelation(
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
                             $relname = $data['table'];
547 547
                             $cntr = 1;
548 548
                             while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
549
-                                $relname = $data['table'] . '_' . (++ $cntr);
549
+                                $relname = $data['table'].'_'.(++$cntr);
550 550
                             }
551 551
                             $definition->addRelation(
552 552
                                 new TableRelation(
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
                         LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
570 570
                         WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
571 571
                         ORDER BY cc.POSITION",
572
-                        [ $owner, $owner, strtoupper($table), 'R' ],
572
+                        [$owner, $owner, strtoupper($table), 'R'],
573 573
                         null, false, 'assoc_uc'
574 574
                     ) as $relation) {
575 575
                         $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_NAME'];
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
                     foreach ($relations as $name => $data) {
579 579
                         $rcolumns = $this->all(
580 580
                             "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
581
-                            [ $owner, current($data['keymap']) ],
581
+                            [$owner, current($data['keymap'])],
582 582
                             null, false, 'assoc_uc'
583 583
                         );
584 584
                         foreach ($data['keymap'] as $column => $related) {
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
                         $relname = $data['table'];
588 588
                         $cntr = 1;
589 589
                         while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
590
-                            $relname = $data['table'] . '_' . (++ $cntr);
590
+                            $relname = $data['table'].'_'.(++$cntr);
591 591
                         }
592 592
                         $definition->addRelation(
593 593
                             new TableRelation(
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
      */
677 677
     public function getSchema()
678 678
     {
679
-        return array_map(function ($table) {
679
+        return array_map(function($table) {
680 680
             return [
681 681
                 'name' => $table->getName(),
682 682
                 'pkey' => $table->getPrimaryKey(),
683 683
                 'comment' => $table->getComment(),
684
-                'columns' => array_map(function ($column) {
684
+                'columns' => array_map(function($column) {
685 685
                     return [
686 686
                         'name' => $column->getName(),
687 687
                         'type' => $column->getType(),
@@ -691,13 +691,13 @@  discard block
 block discarded – undo
691 691
                         'nullable' => $column->isNullable()
692 692
                     ];
693 693
                 }, $table->getFullColumns()),
694
-                'relations' => array_map(function ($rel) {
694
+                'relations' => array_map(function($rel) {
695 695
                     $relation = clone $rel;
696 696
                     $relation->table = $relation->table->getName();
697 697
                     if ($relation->pivot) {
698 698
                         $relation->pivot = $relation->pivot->getName();
699 699
                     }
700
-                    return (array)$relation;
700
+                    return (array) $relation;
701 701
                 }, $table->getRelations())
702 702
             ];
703 703
         }, $this->tables);
Please login to merge, or discard this patch.
src/driver/Oracle.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -40,6 +40,10 @@
 block discarded – undo
40 40
             oci_close($this->lnk);
41 41
         }
42 42
     }
43
+
44
+    /**
45
+     * @param string $sql
46
+     */
43 47
     public function real($sql)
44 48
     {
45 49
         $this->connect();
Please login to merge, or discard this patch.
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,8 +18,7 @@
 block discarded – undo
18 18
                     $this->settings->password,
19 19
                     $this->settings->servername,
20 20
                     $this->settings->charset
21
-                ) :
22
-                @oci_connect(
21
+                ) : @oci_connect(
23 22
                     $this->settings->username,
24 23
                     $this->settings->password,
25 24
                     $this->settings->servername,
Please login to merge, or discard this patch.
src/driver/Pdo.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -61,6 +61,10 @@
 block discarded – undo
61 61
     {
62 62
         return $this->lnk->lastInsertId(null);
63 63
     }
64
+
65
+    /**
66
+     * @param string $sql
67
+     */
64 68
     public function prepare($sql)
65 69
     {
66 70
         $this->connect();
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -85,34 +85,34 @@
 block discarded – undo
85 85
         foreach ($data as $i => $v) {
86 86
             switch (gettype($v)) {
87 87
                 case 'boolean':
88
-                    $sql->bindValue($i+1, $v, \PDO::PARAM_BOOL);
88
+                    $sql->bindValue($i + 1, $v, \PDO::PARAM_BOOL);
89 89
                     break;
90 90
                 case 'integer':
91
-                    $sql->bindValue($i+1, $v, \PDO::PARAM_INT);
91
+                    $sql->bindValue($i + 1, $v, \PDO::PARAM_INT);
92 92
                     break;
93 93
                 case 'NULL':
94
-                    $sql->bindValue($i+1, $v, \PDO::PARAM_NULL);
94
+                    $sql->bindValue($i + 1, $v, \PDO::PARAM_NULL);
95 95
                     break;
96 96
                 case 'double':
97
-                    $sql->bindValue($i+1, $v);
97
+                    $sql->bindValue($i + 1, $v);
98 98
                     break;
99 99
                 default:
100 100
                     // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax:
101 101
                     // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ?
102 102
                     if (is_resource($v) && get_resource_type($v) === 'stream') {
103
-                        $sql->bindParam($i+1, $v, \PDO::PARAM_LOB);
103
+                        $sql->bindParam($i + 1, $v, \PDO::PARAM_LOB);
104 104
                         continue;
105 105
                     }
106 106
                     if (!is_string($data[$i])) {
107 107
                         $data[$i] = serialize($data[$i]);
108 108
                     }
109
-                    $sql->bindValue($i+1, $v);
109
+                    $sql->bindValue($i + 1, $v);
110 110
                     break;
111 111
             }
112 112
         }
113 113
         $rtrn = $sql->execute();
114 114
         if (!$rtrn) {
115
-            throw new DatabaseException('Prepared execute error : '. implode(',', $sql->errorInfo()));
115
+            throw new DatabaseException('Prepared execute error : '.implode(',', $sql->errorInfo()));
116 116
         }
117 117
         $this->aff = $sql->rowCount();
118 118
         return $sql->columnCount() ? $sql : $rtrn;
Please login to merge, or discard this patch.
src/TableQuery.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     /**
53 53
      * Create an instance
54 54
      * @param  DatabaseInterface        $db         the database connection
55
-     * @param  Table|string  $definition     the name or definition of the main table in the query
55
+     * @param Table $table
56 56
      */
57 57
     public function __construct(DatabaseInterface $db, $table)
58 58
     {
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     }
188 188
     /**
189 189
      * Group by a column (or columns)
190
-     * @param  string|array        $column the column name (or names) to group by
190
+     * @param  string        $column the column name (or names) to group by
191 191
      * @return $this
192 192
      */
193 193
     public function group($column) : TableQuery
Please login to merge, or discard this patch.
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     /**
39 39
      * @var int[]
40 40
      */
41
-    protected $li_of = [0,0];
41
+    protected $li_of = [0, 0];
42 42
     protected $fields = [];
43 43
     /**
44 44
      * @var array
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
     public function __construct(DatabaseInterface $db, $table)
58 58
     {
59 59
         $this->db = $db;
60
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
60
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
61 61
         $this->columns($this->definition->getColumns());
62 62
     }
63 63
     public function __clone()
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $column = explode('.', $column, 2);
79 79
         if (count($column) === 1) {
80
-            $column = [ $this->definition->getName(), $column[0] ];
80
+            $column = [$this->definition->getName(), $column[0]];
81 81
         }
82 82
         if ($column[0] === $this->definition->getName()) {
83 83
             $col = $this->definition->getColumn($column[1]);
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
                     throw new DatabaseException('Invalid column name in related table');
97 97
                 }
98 98
             } else {
99
-                throw new DatabaseException('Invalid foreign table name: ' . implode(',', $column));
99
+                throw new DatabaseException('Invalid foreign table name: '.implode(',', $column));
100 100
             }
101 101
         }
102
-        return [ 'name' => implode('.', $column), 'data' => $col ];
102
+        return ['name' => implode('.', $column), 'data' => $col];
103 103
     }
104 104
     protected function normalizeValue(TableColumn $col, $value)
105 105
     {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
                 }
139 139
                 return $value;
140 140
             case 'int':
141
-                return (int)$value;
141
+                return (int) $value;
142 142
             default:
143 143
                 return $value;
144 144
         }
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
     {
154 154
         list($name, $column) = array_values($this->getColumn($column));
155 155
         if (is_null($value)) {
156
-            return $this->where($name . ' IS NULL');
156
+            return $this->where($name.' IS NULL');
157 157
         }
158 158
         if (!is_array($value)) {
159 159
             return $this->where(
160
-                $name . ' = ?',
161
-                [ $this->normalizeValue($column, $value) ]
160
+                $name.' = ?',
161
+                [$this->normalizeValue($column, $value)]
162 162
             );
163 163
         }
164 164
         if (isset($value['beg']) && isset($value['end'])) {
@@ -171,8 +171,8 @@  discard block
 block discarded – undo
171 171
             );
172 172
         }
173 173
         return $this->where(
174
-            $name . ' IN (??)',
175
-            [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
174
+            $name.' IN (??)',
175
+            [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
176 176
         );
177 177
     }
178 178
     /**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      */
184 184
     public function sort(string $column, bool $desc = false) : TableQuery
185 185
     {
186
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
186
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
187 187
     }
188 188
     /**
189 189
      * Group by a column (or columns)
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     public function group($column) : TableQuery
194 194
     {
195 195
         if (!is_array($column)) {
196
-            $column = [ $column ];
196
+            $column = [$column];
197 197
         }
198 198
         foreach ($column as $k => $v) {
199 199
             $column[$k] = $this->getColumn($v)['name'];
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
         $this->withr = [];
235 235
         $this->order = [];
236 236
         $this->having = [];
237
-        $this->li_of = [0,0];
237
+        $this->li_of = [0, 0];
238 238
         $this->qiterator = null;
239 239
         return $this;
240 240
     }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     public function groupBy(string $sql, array $params = []) : TableQuery
248 248
     {
249 249
         $this->qiterator = null;
250
-        $this->group = [ $sql, $params ];
250
+        $this->group = [$sql, $params];
251 251
         return $this;
252 252
     }
253 253
     /**
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      */
261 261
     public function join($table, array $fields, string $name = null, bool $multiple = true)
262 262
     {
263
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
263
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
264 264
         $name = $name ?? $table->getName();
265 265
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
266 266
             throw new DatabaseException('Alias / table name already in use');
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
         foreach ($fields as $k => $v) {
270 270
             $k = explode('.', $k, 2);
271 271
             $k = count($k) == 2 ? $k[1] : $k[0];
272
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
272
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
273 273
         }
274 274
         return $this;
275 275
     }
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
     public function where(string $sql, array $params = []) : TableQuery
283 283
     {
284 284
         $this->qiterator = null;
285
-        $this->where[] = [ $sql, $params ];
285
+        $this->where[] = [$sql, $params];
286 286
         return $this;
287 287
     }
288 288
     /**
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
     public function having(string $sql, array $params = []) : TableQuery
295 295
     {
296 296
         $this->qiterator = null;
297
-        $this->having[] = [ $sql, $params ];
297
+        $this->having[] = [$sql, $params];
298 298
         return $this;
299 299
     }
300 300
     /**
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
     public function order(string $sql, array $params = []) : TableQuery
307 307
     {
308 308
         $this->qiterator = null;
309
-        $this->order = [ $sql, $params ];
309
+        $this->order = [$sql, $params];
310 310
         return $this;
311 311
     }
312 312
     /**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
     public function limit(int $limit, int $offset = 0) : TableQuery
319 319
     {
320 320
         $this->qiterator = null;
321
-        $this->li_of = [ $limit, $offset ];
321
+        $this->li_of = [$limit, $offset];
322 322
         return $this;
323 323
     }
324 324
     /**
@@ -335,22 +335,22 @@  discard block
 block discarded – undo
335 335
         $relations = $this->withr;
336 336
         foreach ($this->definition->getRelations() as $k => $v) {
337 337
             foreach ($this->where as $vv) {
338
-                if (strpos($vv[0], $k . '.') !== false) {
338
+                if (strpos($vv[0], $k.'.') !== false) {
339 339
                     $relations[] = $k;
340 340
                 }
341 341
             }
342
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
342
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
343 343
                 $relations[] = $k;
344 344
             }
345 345
         }
346 346
 
347 347
         foreach ($this->joins as $k => $v) {
348
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
348
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
349 349
             $tmp = [];
350 350
             foreach ($v->keymap as $kk => $vv) {
351 351
                 $tmp[] = $kk.' = '.$vv;
352 352
             }
353
-            $sql .= implode(' AND ', $tmp) . ' ';
353
+            $sql .= implode(' AND ', $tmp).' ';
354 354
         }
355 355
         foreach (array_unique($relations) as $k) {
356 356
             $v = $this->definition->getRelation($k);
@@ -360,13 +360,13 @@  discard block
 block discarded – undo
360 360
                 foreach ($v->keymap as $kk => $vv) {
361 361
                     $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' ';
362 362
                 }
363
-                $sql .= implode(' AND ', $tmp) . ' ';
363
+                $sql .= implode(' AND ', $tmp).' ';
364 364
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
365 365
                 $tmp = [];
366 366
                 foreach ($v->pivot_keymap as $kk => $vv) {
367 367
                     $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' ';
368 368
                 }
369
-                $sql .= implode(' AND ', $tmp) . ' ';
369
+                $sql .= implode(' AND ', $tmp).' ';
370 370
             } else {
371 371
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
372 372
                 $tmp = [];
@@ -374,30 +374,30 @@  discard block
 block discarded – undo
374 374
                     $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' ';
375 375
                 }
376 376
                 if ($v->sql) {
377
-                    $tmp[] = $v->sql . ' ';
377
+                    $tmp[] = $v->sql.' ';
378 378
                     $par = array_merge($par, $v->par ?? []);
379 379
                 }
380
-                $sql .= implode(' AND ', $tmp) . ' ';
380
+                $sql .= implode(' AND ', $tmp).' ';
381 381
             }
382 382
         }
383 383
         if (count($this->where)) {
384 384
             $sql .= 'WHERE ';
385 385
             $tmp = [];
386 386
             foreach ($this->where as $v) {
387
-                $tmp[] = '(' . $v[0] . ')';
387
+                $tmp[] = '('.$v[0].')';
388 388
                 $par = array_merge($par, $v[1]);
389 389
             }
390 390
             $sql .= implode(' AND ', $tmp).' ';
391 391
         }
392 392
         if (count($this->group)) {
393
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
393
+            $sql .= 'GROUP BY '.$this->group[0].' ';
394 394
             $par = array_merge($par, $this->group[1]);
395 395
         }
396 396
         if (count($this->having)) {
397 397
             $sql .= 'HAVING ';
398 398
             $tmp = [];
399 399
             foreach ($this->having as $v) {
400
-                $tmp[] = '(' . $v[0] . ')';
400
+                $tmp[] = '('.$v[0].')';
401 401
                 $par = array_merge($par, $v[1]);
402 402
             }
403 403
             $sql .= implode(' AND ', $tmp).' ';
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
                     throw new DatabaseException('Invalid foreign table name');
429 429
                 }
430 430
                 foreach ($cols as $col) {
431
-                    $fields[] = $table . '.' . $col;
431
+                    $fields[] = $table.'.'.$col;
432 432
                 }
433 433
                 unset($fields[$k]);
434 434
             }
@@ -468,37 +468,37 @@  discard block
 block discarded – undo
468 468
         $relations = $this->withr;
469 469
         foreach ($this->definition->getRelations() as $k => $v) {
470 470
             foreach ($this->fields as $field) {
471
-                if (strpos($field, $k . '.') === 0) {
471
+                if (strpos($field, $k.'.') === 0) {
472 472
                     $relations[] = $k;
473 473
                 }
474 474
             }
475 475
             foreach ($this->where as $v) {
476
-                if (strpos($v[0], $k . '.') !== false) {
476
+                if (strpos($v[0], $k.'.') !== false) {
477 477
                     $relations[] = $k;
478 478
                 }
479 479
             }
480
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
480
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
481 481
                 $relations[] = $k;
482 482
             }
483 483
         }
484 484
         $select = [];
485 485
         foreach ($this->fields as $k => $field) {
486
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
486
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
487 487
         }
488 488
         foreach ($this->withr as $relation) {
489 489
             foreach ($this->definition->getRelation($relation)->table->getColumns() as $column) {
490
-                $select[] = $relation . '.' . $column . ' ' . $relation . '___' . $column;
490
+                $select[] = $relation.'.'.$column.' '.$relation.'___'.$column;
491 491
             }
492 492
         }
493 493
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
494 494
         $par = [];
495 495
         foreach ($this->joins as $k => $v) {
496
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
496
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
497 497
             $tmp = [];
498 498
             foreach ($v->keymap as $kk => $vv) {
499 499
                 $tmp[] = $kk.' = '.$vv;
500 500
             }
501
-            $sql .= implode(' AND ', $tmp) . ' ';
501
+            $sql .= implode(' AND ', $tmp).' ';
502 502
         }
503 503
         foreach (array_unique($relations) as $relation) {
504 504
             $v = $this->definition->getRelation($relation);
@@ -508,13 +508,13 @@  discard block
 block discarded – undo
508 508
                 foreach ($v->keymap as $kk => $vv) {
509 509
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' ';
510 510
                 }
511
-                $sql .= implode(' AND ', $tmp) . ' ';
511
+                $sql .= implode(' AND ', $tmp).' ';
512 512
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
513 513
                 $tmp = [];
514 514
                 foreach ($v->pivot_keymap as $kk => $vv) {
515 515
                     $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' ';
516 516
                 }
517
-                $sql .= implode(' AND ', $tmp) . ' ';
517
+                $sql .= implode(' AND ', $tmp).' ';
518 518
             } else {
519 519
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
520 520
                 $tmp = [];
@@ -522,30 +522,30 @@  discard block
 block discarded – undo
522 522
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' ';
523 523
                 }
524 524
                 if ($v->sql) {
525
-                    $tmp[] = $v->sql . ' ';
525
+                    $tmp[] = $v->sql.' ';
526 526
                     $par = array_merge($par, $v->par ?? []);
527 527
                 }
528
-                $sql .= implode(' AND ', $tmp) . ' ';
528
+                $sql .= implode(' AND ', $tmp).' ';
529 529
             }
530 530
         }
531 531
         if (count($this->where)) {
532 532
             $sql .= 'WHERE ';
533 533
             $tmp = [];
534 534
             foreach ($this->where as $v) {
535
-                $tmp[] = '(' . $v[0] . ')';
535
+                $tmp[] = '('.$v[0].')';
536 536
                 $par = array_merge($par, $v[1]);
537 537
             }
538 538
             $sql .= implode(' AND ', $tmp).' ';
539 539
         }
540 540
         if (count($this->group)) {
541
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
541
+            $sql .= 'GROUP BY '.$this->group[0].' ';
542 542
             $par = array_merge($par, $this->group[1]);
543 543
         }
544 544
         if (count($this->having)) {
545 545
             $sql .= 'HAVING ';
546 546
             $tmp = [];
547 547
             foreach ($this->having as $v) {
548
-                $tmp[] = '(' . $v[0] . ')';
548
+                $tmp[] = '('.$v[0].')';
549 549
                 $par = array_merge($par, $v[1]);
550 550
             }
551 551
             $sql .= implode(' AND ', $tmp).' ';
@@ -554,36 +554,36 @@  discard block
 block discarded – undo
554 554
         //    $sql .= 'GROUP BY '.$table.'.'.implode(', '.$table.'.', $primary).' ';
555 555
         //}
556 556
         if (count($this->order)) {
557
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
557
+            $sql .= 'ORDER BY '.$this->order[0].' ';
558 558
             $par = array_merge($par, $this->order[1]);
559 559
         }
560 560
         $porder = [];
561 561
         foreach ($primary as $field) {
562 562
             $porder[] = $this->getColumn($field)['name'];
563 563
         }
564
-        $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
564
+        $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
565 565
 
566 566
         if ($this->li_of[0]) {
567 567
             if ($this->db->driver() === 'oracle') {
568
-                if ((int)($this->db->settings()->options['version'] ?? 0) >= 12) {
569
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
568
+                if ((int) ($this->db->settings()->options['version'] ?? 0) >= 12) {
569
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
570 570
                 } else {
571
-                    $f = array_map(function ($v) {
571
+                    $f = array_map(function($v) {
572 572
                         $v = explode(' ', trim($v), 2);
573 573
                         if (count($v) === 2) { return $v[1]; }
574 574
                         $v = explode('.', $v[0], 2);
575 575
                         return count($v) === 2 ? $v[1] : $v[0];
576 576
                     }, $select);
577
-                    $sql = "SELECT " . implode(', ', $f) . " 
577
+                    $sql = "SELECT ".implode(', ', $f)." 
578 578
                             FROM (
579 579
                                 SELECT tbl__.*, rownum rnum__ FROM (
580
-                                    " . $sql . "
580
+                                    " . $sql."
581 581
                                 ) tbl__ 
582
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
582
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
583 583
                             ) WHERE rnum__ > " . $this->li_of[1];
584 584
                 }
585 585
             } else {
586
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
586
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
587 587
             }
588 588
         }
589 589
         // echo $sql; die();
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
             $this->definition->getPrimaryKey(),
593 593
             array_combine(
594 594
                 $this->withr,
595
-                array_map(function ($relation) {
595
+                array_map(function($relation) {
596 596
                     return $this->definition->getRelation($relation);
597 597
                 }, $this->withr)
598 598
             )
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
                 $ret[$k] = str_repeat(' ', 255);
640 640
                 $par[] = &$ret[$k];
641 641
             }
642
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
642
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
643 643
             $this->db->query($sql, $par);
644 644
             return $ret;
645 645
         } else {
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
         }
672 672
         $sql = 'UPDATE '.$table.' SET ';
673 673
         $par = [];
674
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
674
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
675 675
         $par = array_merge($par, array_values($update));
676 676
         if (count($this->where)) {
677 677
             $sql .= 'WHERE ';
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
                 $tmp[] = $v[0];
681 681
                 $par = array_merge($par, $v[1]);
682 682
             }
683
-            $sql .= implode(' AND ', $tmp) . ' ';
683
+            $sql .= implode(' AND ', $tmp).' ';
684 684
         }
685 685
         if (count($this->order)) {
686 686
             $sql .= $this->order[0];
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
                 $tmp[] = $v[0];
705 705
                 $par = array_merge($par, $v[1]);
706 706
             }
707
-            $sql .= implode(' AND ', $tmp) . ' ';
707
+            $sql .= implode(' AND ', $tmp).' ';
708 708
         }
709 709
         if (count($this->order)) {
710 710
             $sql .= $this->order[0];
Please login to merge, or discard this patch.
src/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/driver/Postgre.php 1 patch
Spacing   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
                         'password='.$this->settings->password.' '.
28 28
                         'dbname='.$this->settings->database.' '.
29 29
                         "options='--client_encoding=".strtoupper($this->settings->charset)."' "
30
-                    ) :
31
-                    @pg_connect(
30
+                    ) : @pg_connect(
32 31
                         'host='.$this->settings->servername.' '.
33 32
                         'port='.$this->settings->serverport.' '.
34 33
                         'user='.$this->settings->username.' '.
@@ -78,8 +77,7 @@  discard block
 block discarded – undo
78 77
             $data = array();
79 78
         }
80 79
         $temp = (is_array($data) && count($data)) ?
81
-            pg_query_params($this->lnk, $sql, $data) :
82
-            pg_query_params($this->lnk, $sql, array());
80
+            pg_query_params($this->lnk, $sql, $data) : pg_query_params($this->lnk, $sql, array());
83 81
         if (!$temp) {
84 82
             throw new DatabaseException('Could not execute query : '.pg_last_error($this->lnk).' <'.$sql.'>');
85 83
         }
Please login to merge, or discard this patch.
src/driver/Mysql.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@
 block discarded – undo
23 23
                         $this->settings->servername.':'.$this->settings->serverport,
24 24
                         $this->settings->username,
25 25
                         $this->settings->password
26
-                    ) :
27
-                    @mysql_connect(
26
+                    ) : @mysql_connect(
28 27
                         $this->settings->servername.':'.$this->settings->serverport,
29 28
                         $this->settings->username,
30 29
                         $this->settings->password
Please login to merge, or discard this patch.
src/driver/Ibase.php 1 patch
Spacing   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
         }
18 18
         $this->settings->servername =
19 19
             ($this->settings->servername === 'localhost' || $this->settings->servername === '') ?
20
-                '' :
21
-                $this->settings->servername.':';
20
+                '' : $this->settings->servername.':';
22 21
     }
23 22
     protected function connect()
24 23
     {
@@ -29,8 +28,7 @@  discard block
 block discarded – undo
29 28
                         $this->settings->username,
30 29
                         $this->settings->password,
31 30
                         strtoupper($this->settings->charset)
32
-                    ) :
33
-                    @\ibase_connect(
31
+                    ) : @\ibase_connect(
34 32
                         $this->settings->servername.$this->settings->database,
35 33
                         $this->settings->username,
36 34
                         $this->settings->password,
Please login to merge, or discard this patch.
src/Result.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -102,8 +102,7 @@  discard block
 block discarded – undo
102 102
             }
103 103
         }
104 104
         $cnt = $this->mode === 'assoc_ci' ?
105
-            count(array_unique(array_map('strtolower', array_keys($row)))) :
106
-            count($row);
105
+            count(array_unique(array_map('strtolower', array_keys($row)))) : count($row);
107 106
         if ($this->opti && is_array($row) && $cnt <= 1) {
108 107
             $row = count($row) ? current($row) : current($tmp);
109 108
         }
@@ -123,7 +122,7 @@  discard block
 block discarded – undo
123 122
         if ($this->rdy) {
124 123
             return next($this->all);
125 124
         }
126
-        if($this->rslt->nextr()) {
125
+        if ($this->rslt->nextr()) {
127 126
             ++$this->realKey;
128 127
         }
129 128
         else {
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -125,8 +125,7 @@
 block discarded – undo
125 125
         }
126 126
         if($this->rslt->nextr()) {
127 127
             ++$this->realKey;
128
-        }
129
-        else {
128
+        } else {
130 129
             $this->realKey = null;
131 130
         }
132 131
     }
Please login to merge, or discard this patch.