Completed
Push — master ( c90248...850e70 )
by Ivan
02:22
created
src/DB.php 2 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -117,7 +117,6 @@  discard block
 block discarded – undo
117 117
     /**
118 118
      * Run a query (prepare & execute).
119 119
      * @param string $sql  SQL query
120
-     * @param array  $data parameters (optional)
121 120
      * @return ResultInterface the result of the execution
122 121
      */
123 122
     public function query(string $sql, $par = null) : ResultInterface
@@ -170,7 +169,6 @@  discard block
 block discarded – undo
170 169
      * Run a SELECT query and get a single row
171 170
      * @param string   $sql      SQL query
172 171
      * @param array    $par      parameters
173
-     * @param callable $keys     an optional mutator to pass each row's keys through (the column names)
174 172
      * @param bool     $opti     if a single column is returned - do not use an array wrapper (defaults to `true`)
175 173
      * @return Collection the result of the execution
176 174
      */
@@ -184,7 +182,6 @@  discard block
 block discarded – undo
184 182
      * @param array    $par      parameters
185 183
      * @param string   $key      column name to use as the array index
186 184
      * @param bool     $skip     do not include the column used as index in the value (defaults to `false`)
187
-     * @param callable $keys     an optional mutator to pass each row's keys through (the column names)
188 185
      * @param bool     $opti     if a single column is returned - do not use an array wrapper (defaults to `true`)
189 186
      * @return Collection the result of the execution
190 187
      */
Please login to merge, or discard this patch.
Spacing   +14 added lines, -16 removed lines patch added patch discarded remove patch
@@ -73,8 +73,7 @@  discard block
 block discarded – undo
73 73
         }
74 74
         $connection['name'] = $connectionString;
75 75
         $connection['type'] = isset($aliases[$connection['type']]) ?
76
-            $aliases[$connection['type']] :
77
-            $connection['type'];
76
+            $aliases[$connection['type']] : $connection['type'];
78 77
         $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver';
79 78
         return new $tmp($connection);
80 79
     }
@@ -94,7 +93,7 @@  discard block
 block discarded – undo
94 93
         $new = '';
95 94
         $par = array_values($par);
96 95
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
97
-            $par = [ $par ];
96
+            $par = [$par];
98 97
         }
99 98
         $parts = explode('??', $sql);
100 99
         $index = 0;
@@ -104,7 +103,7 @@  discard block
 block discarded – undo
104 103
             $index += count($tmp) - 1;
105 104
             if (isset($par[$index])) {
106 105
                 if (!is_array($par[$index])) {
107
-                    $par[$index] = [ $par[$index] ];
106
+                    $par[$index] = [$par[$index]];
108 107
                 }
109 108
                 $params = $par[$index];
110 109
                 array_splice($par, $index, 1, $params);
@@ -112,7 +111,7 @@  discard block
 block discarded – undo
112 111
                 $new .= implode(',', array_fill(0, count($params), '?'));
113 112
             }
114 113
         }
115
-        return [ $new, $par ];
114
+        return [$new, $par];
116 115
     }
117 116
     /**
118 117
      * Run a query (prepare & execute).
@@ -144,7 +143,7 @@  discard block
 block discarded – undo
144 143
     {
145 144
         $coll = Collection::from($this->query($sql, $par));
146 145
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
147
-            $coll->map(function ($v) use ($keys) {
146
+            $coll->map(function($v) use ($keys) {
148 147
                 $new = [];
149 148
                 foreach ($v as $k => $vv) {
150 149
                     $new[call_user_func($keys, $k)] = $vv;
@@ -153,16 +152,16 @@  discard block
 block discarded – undo
153 152
             });
154 153
         }
155 154
         if ($key) {
156
-            $coll->mapKey(function ($v) use ($key) { return $v[$key]; });
155
+            $coll->mapKey(function($v) use ($key) { return $v[$key]; });
157 156
         }
158 157
         if ($skip) {
159
-            $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; });
158
+            $coll->map(function($v) use ($key) { unset($v[$key]); return $v; });
160 159
         }
161 160
         if ($opti) {
162
-            $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; });
161
+            $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; });
163 162
         }
164 163
         if ($keys) {
165
-            $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; });
164
+            $coll->map(function($v) use ($key) { unset($v[$key]); return $v; });
166 165
         }
167 166
         return $coll;
168 167
     }
@@ -237,8 +236,7 @@  discard block
 block discarded – undo
237 236
     public function definition(string $table, bool $detectRelations = true) : Table
238 237
     {
239 238
         return isset($this->tables[$table]) ?
240
-            $this->tables[$table] :
241
-            $this->driver->table($table, $detectRelations);
239
+            $this->tables[$table] : $this->driver->table($table, $detectRelations);
242 240
     }
243 241
     /**
244 242
      * Parse all tables from the database.
@@ -255,12 +253,12 @@  discard block
 block discarded – undo
255 253
      */
256 254
     public function getSchema($asPlainArray = true)
257 255
     {
258
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
256
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
259 257
             return [
260 258
                 'name' => $table->getName(),
261 259
                 'pkey' => $table->getPrimaryKey(),
262 260
                 'comment' => $table->getComment(),
263
-                'columns' => array_map(function ($column) {
261
+                'columns' => array_map(function($column) {
264 262
                     return [
265 263
                         'name' => $column->getName(),
266 264
                         'type' => $column->getType(),
@@ -270,13 +268,13 @@  discard block
 block discarded – undo
270 268
                         'nullable' => $column->isNullable()
271 269
                     ];
272 270
                 }, $table->getFullColumns()),
273
-                'relations' => array_map(function ($rel) {
271
+                'relations' => array_map(function($rel) {
274 272
                     $relation = clone $rel;
275 273
                     $relation->table = $relation->table->getName();
276 274
                     if ($relation->pivot) {
277 275
                         $relation->pivot = $relation->pivot->getName();
278 276
                     }
279
-                    return (array)$relation;
277
+                    return (array) $relation;
280 278
                 }, $table->getRelations())
281 279
             ];
282 280
         }, $this->tables);
Please login to merge, or discard this patch.
src/driver/postgre/Result.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -15,6 +15,9 @@
 block discarded – undo
15 15
     protected $iid = null;
16 16
     protected $aff = 0;
17 17
 
18
+    /**
19
+     * @param integer $aff
20
+     */
18 21
     public function __construct($statement, $iid, $aff)
19 22
     {
20 23
         $this->statement = $statement;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
     }
63 63
     public function next()
64 64
     {
65
-        $this->fetched ++;
65
+        $this->fetched++;
66 66
         $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC);
67 67
     }
68 68
     public function valid()
Please login to merge, or discard this patch.
src/driver/sqlite/Result.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -15,6 +15,10 @@
 block discarded – undo
15 15
     protected $iid = null;
16 16
     protected $aff = 0;
17 17
 
18
+    /**
19
+     * @param integer $iid
20
+     * @param integer $aff
21
+     */
18 22
     public function __construct(\SQLite3Result $statement, $iid, $aff)
19 23
     {
20 24
         $this->statement = $statement;
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
     }
63 63
     public function next()
64 64
     {
65
-        $this->fetched ++;
65
+        $this->fetched++;
66 66
         $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC);
67 67
     }
68 68
     public function valid()
Please login to merge, or discard this patch.
src/DriverAbstract.php 2 patches
Doc Comments   +7 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,6 @@  discard block
 block discarded – undo
35 35
     /**
36 36
      * Run a query (prepare & execute).
37 37
      * @param string $sql  SQL query
38
-     * @param array  $data parameters (optional)
39 38
      * @return ResultInterface the result of the execution
40 39
      */
41 40
     public function query(string $sql, $par = null) : ResultInterface
@@ -50,6 +49,13 @@  discard block
 block discarded – undo
50 49
     {
51 50
         return $this->connection['name'];
52 51
     }
52
+
53
+    /**
54
+     * @param string $key
55
+     * @param string $default
56
+     *
57
+     * @return string
58
+     */
53 59
     public function option($key, $default = null)
54 60
     {
55 61
         return isset($this->connection['opts'][$key]) ? $this->connection['opts'][$key] : $default;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
         $new = '';
13 13
         $par = array_values($par);
14 14
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
15
-            $par = [ $par ];
15
+            $par = [$par];
16 16
         }
17 17
         $parts = explode('??', $sql);
18 18
         $index = 0;
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
             $index += count($tmp) - 1;
23 23
             if (isset($par[$index])) {
24 24
                 if (!is_array($par[$index])) {
25
-                    $par[$index] = [ $par[$index] ];
25
+                    $par[$index] = [$par[$index]];
26 26
                 }
27 27
                 $params = $par[$index];
28 28
                 array_splice($par, $index, 1, $params);
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
                 $new .= implode(',', array_fill(0, count($params), '?'));
31 31
             }
32 32
         }
33
-        return [ $new, $par ];
33
+        return [$new, $par];
34 34
     }
35 35
     /**
36 36
      * Run a query (prepare & execute).
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
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     /**
57 57
      * Create an instance
58 58
      * @param  DBInterface        $db         the database connection
59
-     * @param  Table|string  $definition     the name or definition of the main table in the query
59
+     * @param Table $table
60 60
      */
61 61
     public function __construct(DBInterface $db, $table)
62 62
     {
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     }
192 192
     /**
193 193
      * Group by a column (or columns)
194
-     * @param  string|array        $column the column name (or names) to group by
194
+     * @param  string        $column the column name (or names) to group by
195 195
      * @return $this
196 196
      */
197 197
     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
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 
4 4
 use vakata\database\DBInterface;
5 5
 use vakata\database\DBException;
6
-use vakata\database\ResultInterface;
7 6
 
8 7
 /**
9 8
  * A database query class
Please login to merge, or discard this patch.
Spacing   +67 added lines, -70 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
     /**
43 43
      * @var int[]
44 44
      */
45
-    protected $li_of = [0,0];
45
+    protected $li_of = [0, 0];
46 46
     protected $fields = [];
47 47
     /**
48 48
      * @var array
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     public function __construct(DBInterface $db, $table)
62 62
     {
63 63
         $this->db = $db;
64
-        $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table);
64
+        $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table);
65 65
         $this->columns($this->definition->getColumns());
66 66
     }
67 67
     public function __clone()
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $column = explode('.', $column, 2);
83 83
         if (count($column) === 1) {
84
-            $column = [ $this->definition->getName(), $column[0] ];
84
+            $column = [$this->definition->getName(), $column[0]];
85 85
         }
86 86
         if ($column[0] === $this->definition->getName()) {
87 87
             $col = $this->definition->getColumn($column[1]);
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
                     throw new DBException('Invalid column name in related table');
101 101
                 }
102 102
             } else {
103
-                throw new DBException('Invalid foreign table name: ' . implode(',', $column));
103
+                throw new DBException('Invalid foreign table name: '.implode(',', $column));
104 104
             }
105 105
         }
106
-        return [ 'name' => implode('.', $column), 'data' => $col ];
106
+        return ['name' => implode('.', $column), 'data' => $col];
107 107
     }
108 108
     protected function normalizeValue(TableColumn $col, $value)
109 109
     {
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                 }
143 143
                 return $value;
144 144
             case 'int':
145
-                return (int)$value;
145
+                return (int) $value;
146 146
             default:
147 147
                 return $value;
148 148
         }
@@ -159,18 +159,16 @@  discard block
 block discarded – undo
159 159
         list($name, $column) = array_values($this->getColumn($column));
160 160
         if (is_null($value)) {
161 161
             return $negate ?
162
-                $this->where($name . ' IS NOT NULL') :
163
-                $this->where($name . ' IS NULL');
162
+                $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL');
164 163
         }
165 164
         if (!is_array($value)) {
166 165
             return $negate ?
167 166
                 $this->where(
168
-                    $name . ' <> ?',
169
-                    [ $this->normalizeValue($column, $value) ]
170
-                ) :
171
-                $this->where(
172
-                    $name . ' = ?',
173
-                    [ $this->normalizeValue($column, $value) ]
167
+                    $name.' <> ?',
168
+                    [$this->normalizeValue($column, $value)]
169
+                ) : $this->where(
170
+                    $name.' = ?',
171
+                    [$this->normalizeValue($column, $value)]
174 172
                 );
175 173
         }
176 174
         if (isset($value['beg']) && isset($value['end'])) {
@@ -181,8 +179,7 @@  discard block
 block discarded – undo
181 179
                         $this->normalizeValue($column, $value['beg']),
182 180
                         $this->normalizeValue($column, $value['end'])
183 181
                     ]
184
-                ) :
185
-                $this->where(
182
+                ) : $this->where(
186 183
                     $name.' BETWEEN ? AND ?',
187 184
                     [
188 185
                         $this->normalizeValue($column, $value['beg']),
@@ -192,12 +189,12 @@  discard block
 block discarded – undo
192 189
         }
193 190
         return $negate ?
194 191
             $this->where(
195
-                $name . ' NOT IN (??)',
196
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
192
+                $name.' NOT IN (??)',
193
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
197 194
             ) :
198 195
             $this->where(
199
-                $name . ' IN (??)',
200
-                [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ]
196
+                $name.' IN (??)',
197
+                [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)]
201 198
             );
202 199
     }
203 200
     /**
@@ -208,7 +205,7 @@  discard block
 block discarded – undo
208 205
      */
209 206
     public function sort(string $column, bool $desc = false) : TableQuery
210 207
     {
211
-        return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC'));
208
+        return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC'));
212 209
     }
213 210
     /**
214 211
      * Group by a column (or columns)
@@ -218,7 +215,7 @@  discard block
 block discarded – undo
218 215
     public function group($column) : TableQuery
219 216
     {
220 217
         if (!is_array($column)) {
221
-            $column = [ $column ];
218
+            $column = [$column];
222 219
         }
223 220
         foreach ($column as $k => $v) {
224 221
             $column[$k] = $this->getColumn($v)['name'];
@@ -259,7 +256,7 @@  discard block
 block discarded – undo
259 256
         $this->withr = [];
260 257
         $this->order = [];
261 258
         $this->having = [];
262
-        $this->li_of = [0,0];
259
+        $this->li_of = [0, 0];
263 260
         $this->qiterator = null;
264 261
         return $this;
265 262
     }
@@ -272,7 +269,7 @@  discard block
 block discarded – undo
272 269
     public function groupBy(string $sql, array $params = []) : TableQuery
273 270
     {
274 271
         $this->qiterator = null;
275
-        $this->group = [ $sql, $params ];
272
+        $this->group = [$sql, $params];
276 273
         return $this;
277 274
     }
278 275
     /**
@@ -285,7 +282,7 @@  discard block
 block discarded – undo
285 282
      */
286 283
     public function join($table, array $fields, string $name = null, bool $multiple = true)
287 284
     {
288
-        $table = $table instanceof Table ? $table : $this->db->definition((string)$table);
285
+        $table = $table instanceof Table ? $table : $this->db->definition((string) $table);
289 286
         $name = $name ?? $table->getName();
290 287
         if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) {
291 288
             throw new DBException('Alias / table name already in use');
@@ -294,7 +291,7 @@  discard block
 block discarded – undo
294 291
         foreach ($fields as $k => $v) {
295 292
             $k = explode('.', $k, 2);
296 293
             $k = count($k) == 2 ? $k[1] : $k[0];
297
-            $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name'];
294
+            $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name'];
298 295
         }
299 296
         return $this;
300 297
     }
@@ -307,7 +304,7 @@  discard block
 block discarded – undo
307 304
     public function where(string $sql, array $params = []) : TableQuery
308 305
     {
309 306
         $this->qiterator = null;
310
-        $this->where[] = [ $sql, $params ];
307
+        $this->where[] = [$sql, $params];
311 308
         return $this;
312 309
     }
313 310
     /**
@@ -319,7 +316,7 @@  discard block
 block discarded – undo
319 316
     public function having(string $sql, array $params = []) : TableQuery
320 317
     {
321 318
         $this->qiterator = null;
322
-        $this->having[] = [ $sql, $params ];
319
+        $this->having[] = [$sql, $params];
323 320
         return $this;
324 321
     }
325 322
     /**
@@ -331,7 +328,7 @@  discard block
 block discarded – undo
331 328
     public function order(string $sql, array $params = []) : TableQuery
332 329
     {
333 330
         $this->qiterator = null;
334
-        $this->order = [ $sql, $params ];
331
+        $this->order = [$sql, $params];
335 332
         return $this;
336 333
     }
337 334
     /**
@@ -343,7 +340,7 @@  discard block
 block discarded – undo
343 340
     public function limit(int $limit, int $offset = 0) : TableQuery
344 341
     {
345 342
         $this->qiterator = null;
346
-        $this->li_of = [ $limit, $offset ];
343
+        $this->li_of = [$limit, $offset];
347 344
         return $this;
348 345
     }
349 346
     /**
@@ -360,22 +357,22 @@  discard block
 block discarded – undo
360 357
         $relations = $this->withr;
361 358
         foreach ($this->definition->getRelations() as $k => $v) {
362 359
             foreach ($this->where as $vv) {
363
-                if (strpos($vv[0], $k . '.') !== false) {
360
+                if (strpos($vv[0], $k.'.') !== false) {
364 361
                     $relations[] = $k;
365 362
                 }
366 363
             }
367
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
364
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
368 365
                 $relations[] = $k;
369 366
             }
370 367
         }
371 368
 
372 369
         foreach ($this->joins as $k => $v) {
373
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
370
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
374 371
             $tmp = [];
375 372
             foreach ($v->keymap as $kk => $vv) {
376 373
                 $tmp[] = $kk.' = '.$vv;
377 374
             }
378
-            $sql .= implode(' AND ', $tmp) . ' ';
375
+            $sql .= implode(' AND ', $tmp).' ';
379 376
         }
380 377
         foreach (array_unique($relations) as $k) {
381 378
             $v = $this->definition->getRelation($k);
@@ -385,13 +382,13 @@  discard block
 block discarded – undo
385 382
                 foreach ($v->keymap as $kk => $vv) {
386 383
                     $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' ';
387 384
                 }
388
-                $sql .= implode(' AND ', $tmp) . ' ';
385
+                $sql .= implode(' AND ', $tmp).' ';
389 386
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
390 387
                 $tmp = [];
391 388
                 foreach ($v->pivot_keymap as $kk => $vv) {
392 389
                     $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' ';
393 390
                 }
394
-                $sql .= implode(' AND ', $tmp) . ' ';
391
+                $sql .= implode(' AND ', $tmp).' ';
395 392
             } else {
396 393
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON ';
397 394
                 $tmp = [];
@@ -399,30 +396,30 @@  discard block
 block discarded – undo
399 396
                     $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' ';
400 397
                 }
401 398
                 if ($v->sql) {
402
-                    $tmp[] = $v->sql . ' ';
399
+                    $tmp[] = $v->sql.' ';
403 400
                     $par = array_merge($par, $v->par ?? []);
404 401
                 }
405
-                $sql .= implode(' AND ', $tmp) . ' ';
402
+                $sql .= implode(' AND ', $tmp).' ';
406 403
             }
407 404
         }
408 405
         if (count($this->where)) {
409 406
             $sql .= 'WHERE ';
410 407
             $tmp = [];
411 408
             foreach ($this->where as $v) {
412
-                $tmp[] = '(' . $v[0] . ')';
409
+                $tmp[] = '('.$v[0].')';
413 410
                 $par = array_merge($par, $v[1]);
414 411
             }
415 412
             $sql .= implode(' AND ', $tmp).' ';
416 413
         }
417 414
         if (count($this->group)) {
418
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
415
+            $sql .= 'GROUP BY '.$this->group[0].' ';
419 416
             $par = array_merge($par, $this->group[1]);
420 417
         }
421 418
         if (count($this->having)) {
422 419
             $sql .= 'HAVING ';
423 420
             $tmp = [];
424 421
             foreach ($this->having as $v) {
425
-                $tmp[] = '(' . $v[0] . ')';
422
+                $tmp[] = '('.$v[0].')';
426 423
                 $par = array_merge($par, $v[1]);
427 424
             }
428 425
             $sql .= implode(' AND ', $tmp).' ';
@@ -453,7 +450,7 @@  discard block
 block discarded – undo
453 450
                     throw new DBException('Invalid foreign table name');
454 451
                 }
455 452
                 foreach ($cols as $col) {
456
-                    $fields[] = $table . '.' . $col;
453
+                    $fields[] = $table.'.'.$col;
457 454
                 }
458 455
                 unset($fields[$k]);
459 456
             }
@@ -493,37 +490,37 @@  discard block
 block discarded – undo
493 490
         $relations = $this->withr;
494 491
         foreach ($this->definition->getRelations() as $k => $v) {
495 492
             foreach ($this->fields as $field) {
496
-                if (strpos($field, $k . '.') === 0) {
493
+                if (strpos($field, $k.'.') === 0) {
497 494
                     $relations[] = $k;
498 495
                 }
499 496
             }
500 497
             foreach ($this->where as $v) {
501
-                if (strpos($v[0], $k . '.') !== false) {
498
+                if (strpos($v[0], $k.'.') !== false) {
502 499
                     $relations[] = $k;
503 500
                 }
504 501
             }
505
-            if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) {
502
+            if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) {
506 503
                 $relations[] = $k;
507 504
             }
508 505
         }
509 506
         $select = [];
510 507
         foreach ($this->fields as $k => $field) {
511
-            $select[] = $field . (!is_numeric($k) ? ' ' . $k : '');
508
+            $select[] = $field.(!is_numeric($k) ? ' '.$k : '');
512 509
         }
513 510
         foreach ($this->withr as $relation) {
514 511
             foreach ($this->definition->getRelation($relation)->table->getColumns() as $column) {
515
-                $select[] = $relation . '.' . $column . ' ' . $relation . '___' . $column;
512
+                $select[] = $relation.'.'.$column.' '.$relation.'___'.$column;
516 513
             }
517 514
         }
518 515
         $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' ';
519 516
         $par = [];
520 517
         foreach ($this->joins as $k => $v) {
521
-            $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON ';
518
+            $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON ';
522 519
             $tmp = [];
523 520
             foreach ($v->keymap as $kk => $vv) {
524 521
                 $tmp[] = $kk.' = '.$vv;
525 522
             }
526
-            $sql .= implode(' AND ', $tmp) . ' ';
523
+            $sql .= implode(' AND ', $tmp).' ';
527 524
         }
528 525
         foreach (array_unique($relations) as $relation) {
529 526
             $v = $this->definition->getRelation($relation);
@@ -533,13 +530,13 @@  discard block
 block discarded – undo
533 530
                 foreach ($v->keymap as $kk => $vv) {
534 531
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' ';
535 532
                 }
536
-                $sql .= implode(' AND ', $tmp) . ' ';
533
+                $sql .= implode(' AND ', $tmp).' ';
537 534
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
538 535
                 $tmp = [];
539 536
                 foreach ($v->pivot_keymap as $kk => $vv) {
540 537
                     $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' ';
541 538
                 }
542
-                $sql .= implode(' AND ', $tmp) . ' ';
539
+                $sql .= implode(' AND ', $tmp).' ';
543 540
             } else {
544 541
                 $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON ';
545 542
                 $tmp = [];
@@ -547,30 +544,30 @@  discard block
 block discarded – undo
547 544
                     $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' ';
548 545
                 }
549 546
                 if ($v->sql) {
550
-                    $tmp[] = $v->sql . ' ';
547
+                    $tmp[] = $v->sql.' ';
551 548
                     $par = array_merge($par, $v->par ?? []);
552 549
                 }
553
-                $sql .= implode(' AND ', $tmp) . ' ';
550
+                $sql .= implode(' AND ', $tmp).' ';
554 551
             }
555 552
         }
556 553
         if (count($this->where)) {
557 554
             $sql .= 'WHERE ';
558 555
             $tmp = [];
559 556
             foreach ($this->where as $v) {
560
-                $tmp[] = '(' . $v[0] . ')';
557
+                $tmp[] = '('.$v[0].')';
561 558
                 $par = array_merge($par, $v[1]);
562 559
             }
563 560
             $sql .= implode(' AND ', $tmp).' ';
564 561
         }
565 562
         if (count($this->group)) {
566
-            $sql .= 'GROUP BY ' . $this->group[0] . ' ';
563
+            $sql .= 'GROUP BY '.$this->group[0].' ';
567 564
             $par = array_merge($par, $this->group[1]);
568 565
         }
569 566
         if (count($this->having)) {
570 567
             $sql .= 'HAVING ';
571 568
             $tmp = [];
572 569
             foreach ($this->having as $v) {
573
-                $tmp[] = '(' . $v[0] . ')';
570
+                $tmp[] = '('.$v[0].')';
574 571
                 $par = array_merge($par, $v[1]);
575 572
             }
576 573
             $sql .= implode(' AND ', $tmp).' ';
@@ -579,36 +576,36 @@  discard block
 block discarded – undo
579 576
         //    $sql .= 'GROUP BY '.$table.'.'.implode(', '.$table.'.', $primary).' ';
580 577
         //}
581 578
         if (count($this->order)) {
582
-            $sql .= 'ORDER BY ' . $this->order[0] . ' ';
579
+            $sql .= 'ORDER BY '.$this->order[0].' ';
583 580
             $par = array_merge($par, $this->order[1]);
584 581
         }
585 582
         $porder = [];
586 583
         foreach ($primary as $field) {
587 584
             $porder[] = $this->getColumn($field)['name'];
588 585
         }
589
-        $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' ';
586
+        $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' ';
590 587
 
591 588
         if ($this->li_of[0]) {
592 589
             if ($this->db->driver() === 'oracle') {
593
-                if ((int)($this->db->settings()->options['version'] ?? 0) >= 12) {
594
-                    $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY';
590
+                if ((int) ($this->db->settings()->options['version'] ?? 0) >= 12) {
591
+                    $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY';
595 592
                 } else {
596
-                    $f = array_map(function ($v) {
593
+                    $f = array_map(function($v) {
597 594
                         $v = explode(' ', trim($v), 2);
598 595
                         if (count($v) === 2) { return $v[1]; }
599 596
                         $v = explode('.', $v[0], 2);
600 597
                         return count($v) === 2 ? $v[1] : $v[0];
601 598
                     }, $select);
602
-                    $sql = "SELECT " . implode(', ', $f) . " 
599
+                    $sql = "SELECT ".implode(', ', $f)." 
603 600
                             FROM (
604 601
                                 SELECT tbl__.*, rownum rnum__ FROM (
605
-                                    " . $sql . "
602
+                                    " . $sql."
606 603
                                 ) tbl__ 
607
-                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . "
604
+                                WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])."
608 605
                             ) WHERE rnum__ > " . $this->li_of[1];
609 606
                 }
610 607
             } else {
611
-                $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1];
608
+                $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1];
612 609
             }
613 610
         }
614 611
         return $this->qiterator = new TableQueryIterator(
@@ -616,7 +613,7 @@  discard block
 block discarded – undo
616 613
             $this->definition->getPrimaryKey(),
617 614
             array_combine(
618 615
                 $this->withr,
619
-                array_map(function ($relation) {
616
+                array_map(function($relation) {
620 617
                     return $this->definition->getRelation($relation);
621 618
                 }, $this->withr)
622 619
             )
@@ -663,7 +660,7 @@  discard block
 block discarded – undo
663 660
                 $ret[$k] = str_repeat(' ', 255);
664 661
                 $par[] = &$ret[$k];
665 662
             }
666
-            $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?'));
663
+            $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?'));
667 664
             $this->db->query($sql, $par);
668 665
             return $ret;
669 666
         } else {
@@ -695,7 +692,7 @@  discard block
 block discarded – undo
695 692
         }
696 693
         $sql = 'UPDATE '.$table.' SET ';
697 694
         $par = [];
698
-        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
695
+        $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' ';
699 696
         $par = array_merge($par, array_values($update));
700 697
         if (count($this->where)) {
701 698
             $sql .= 'WHERE ';
@@ -704,7 +701,7 @@  discard block
 block discarded – undo
704 701
                 $tmp[] = $v[0];
705 702
                 $par = array_merge($par, $v[1]);
706 703
             }
707
-            $sql .= implode(' AND ', $tmp) . ' ';
704
+            $sql .= implode(' AND ', $tmp).' ';
708 705
         }
709 706
         if (count($this->order)) {
710 707
             $sql .= $this->order[0];
@@ -728,7 +725,7 @@  discard block
 block discarded – undo
728 725
                 $tmp[] = $v[0];
729 726
                 $par = array_merge($par, $v[1]);
730 727
             }
731
-            $sql .= implode(' AND ', $tmp) . ' ';
728
+            $sql .= implode(' AND ', $tmp).' ';
732 729
         }
733 730
         if (count($this->order)) {
734 731
             $sql .= $this->order[0];
Please login to merge, or discard this patch.
src/driver/postgre/Statement.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
             $data = array();
24 24
         }
25 25
         $temp = (is_array($data) && count($data)) ?
26
-            \pg_query_params($this->driver, $this->statement, $data) :
27
-            \pg_query_params($this->driver, $this->statement, array());
26
+            \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array());
28 27
         if (!$temp) {
29 28
             throw new DBException('Could not execute query : '.\pg_last_error($this->driver).' <'.$this->statement.'>');
30 29
         }
Please login to merge, or discard this patch.
src/driver/oracle/Result.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
     }
65 65
     public function next()
66 66
     {
67
-        $this->fetched ++;
67
+        $this->fetched++;
68 68
         $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS);
69 69
     }
70 70
     public function valid()
Please login to merge, or discard this patch.
src/driver/oracle/Driver.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 
76 76
     public function begin() : bool
77 77
     {
78
-         return $this->transaction = true;
78
+            return $this->transaction = true;
79 79
     }
80 80
     public function commit() : bool
81 81
     {
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
                     }
200 200
                     return $new;
201 201
                 })
202
-                 as $relation
202
+                    as $relation
203 203
             ) {
204 204
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
205 205
                 $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME'];
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -125,16 +125,16 @@  discard block
 block discarded – undo
125 125
         $columns = Collection::from($this
126 126
             ->query(
127 127
                 "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?",
128
-                [ strtoupper($table), $this->name() ]
128
+                [strtoupper($table), $this->name()]
129 129
             ))
130
-            ->map(function ($v) {
130
+            ->map(function($v) {
131 131
                 $new = [];
132 132
                 foreach ($v as $kk => $vv) {
133 133
                     $new[strtoupper($kk)] = $vv;
134 134
                 }
135 135
                 return $new;
136 136
             })
137
-            ->mapKey(function ($v) { return $v['COLUMN_NAME']; })
137
+            ->mapKey(function($v) { return $v['COLUMN_NAME']; })
138 138
             ->toArray();
139 139
         if (!count($columns)) {
140 140
             throw new DBException('Table not found by name');
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
             ->query(
145 145
                 "SELECT constraint_name FROM all_constraints
146 146
                 WHERE table_name = ? AND constraint_type = ? AND owner = ?",
147
-                [ strtoupper($table), 'P', $owner ]
147
+                [strtoupper($table), 'P', $owner]
148 148
             ))
149
-            ->map(function ($v) {
149
+            ->map(function($v) {
150 150
                 $new = [];
151 151
                 foreach ($v as $kk => $vv) {
152 152
                     $new[strtoupper($kk)] = $vv;
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
                 ->query(
162 162
                     "SELECT column_name FROM all_cons_columns
163 163
                     WHERE table_name = ? AND constraint_name = ? AND owner = ?",
164
-                    [ strtoupper($table), $pkname, $owner ]
164
+                    [strtoupper($table), $pkname, $owner]
165 165
                 ))
166
-                ->map(function ($v) {
166
+                ->map(function($v) {
167 167
                     $new = [];
168 168
                     foreach ($v as $kk => $vv) {
169 169
                         $new[strtoupper($kk)] = $vv;
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
191 191
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ?
192 192
                     ORDER BY cc.POSITION",
193
-                    [ $owner, $owner, $pkname, 'R' ]
193
+                    [$owner, $owner, $pkname, 'R']
194 194
                 ))
195
-                ->map(function ($v) {
195
+                ->map(function($v) {
196 196
                     $new = [];
197 197
                     foreach ($v as $kk => $vv) {
198 198
                         $new[strtoupper($kk)] = $vv;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                  as $relation
203 203
             ) {
204 204
                 $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME'];
205
-                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME'];
205
+                $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME'];
206 206
             }
207 207
             foreach ($relations as $data) {
208 208
                 $rtable = $this->table($data['table'], true); // ?? $this->addTableByName($data['table'], false);
@@ -226,9 +226,9 @@  discard block
 block discarded – undo
226 226
                                 ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND
227 227
                                 cc.COLUMN_NAME IN (??)
228 228
                             ORDER BY POSITION",
229
-                            [ $owner, $owner, $data['table'], 'R', $columns ]
229
+                            [$owner, $owner, $data['table'], 'R', $columns]
230 230
                         ))
231
-                        ->map(function ($v) {
231
+                        ->map(function($v) {
232 232
                             $new = [];
233 233
                             foreach ($v as $kk => $vv) {
234 234
                                 $new[strtoupper($kk)] = $vv;
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
                     $rcolumns = Collection::from($this
247 247
                         ->query(
248 248
                             "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
249
-                            [ $owner, current($foreign['keymap']) ]
249
+                            [$owner, current($foreign['keymap'])]
250 250
                         ))
251
-                        ->map(function ($v) {
251
+                        ->map(function($v) {
252 252
                             $new = [];
253 253
                             foreach ($v as $kk => $vv) {
254 254
                                 $new[strtoupper($kk)] = $vv;
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
                     $relname = $foreign['table'];
264 264
                     $cntr = 1;
265 265
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
266
-                        $relname = $foreign['table'] . '_' . (++ $cntr);
266
+                        $relname = $foreign['table'].'_'.(++$cntr);
267 267
                     }
268 268
                     $definition->addRelation(
269 269
                         new TableRelation(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
                     $relname = $data['table'];
280 280
                     $cntr = 1;
281 281
                     while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
282
-                        $relname = $data['table'] . '_' . (++ $cntr);
282
+                        $relname = $data['table'].'_'.(++$cntr);
283 283
                     }
284 284
                     $definition->addRelation(
285 285
                         new TableRelation(
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
                     LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME
304 304
                     WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ?
305 305
                     ORDER BY cc.POSITION",
306
-                    [ $owner, $owner, strtoupper($table), 'R' ]
306
+                    [$owner, $owner, strtoupper($table), 'R']
307 307
                 ))
308
-                ->map(function ($v) {
308
+                ->map(function($v) {
309 309
                     $new = [];
310 310
                     foreach ($v as $kk => $vv) {
311 311
                         $new[strtoupper($kk)] = $vv;
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
                 $rcolumns = Collection::from($this
322 322
                     ->query(
323 323
                         "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION",
324
-                        [ $owner, current($data['keymap']) ]
324
+                        [$owner, current($data['keymap'])]
325 325
                     ))
326
-                    ->map(function ($v) {
326
+                    ->map(function($v) {
327 327
                         $new = [];
328 328
                         foreach ($v as $kk => $vv) {
329 329
                             $new[strtoupper($kk)] = $vv;
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                 $relname = $data['table'];
339 339
                 $cntr = 1;
340 340
                 while ($definition->hasRelation($relname) || $definition->getName() == $relname) {
341
-                    $relname = $data['table'] . '_' . (++ $cntr);
341
+                    $relname = $data['table'].'_'.(++$cntr);
342 342
                 }
343 343
                 $definition->addRelation(
344 344
                     new TableRelation(
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
                 "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?",
360 360
                 [$this->connection['name']]
361 361
             ))
362
-            ->map(function ($v) {
362
+            ->map(function($v) {
363 363
                 $new = [];
364 364
                 foreach ($v as $kk => $vv) {
365 365
                     $new[strtoupper($kk)] = $vv;
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
                 return $new;
368 368
             })
369 369
             ->pluck('TABLE_NAME')
370
-            ->map(function ($v) {
370
+            ->map(function($v) {
371 371
                 return $this->table($v);
372 372
             })
373 373
             ->toArray();
Please login to merge, or discard this patch.
src/driver/sqlite/Driver.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
         parse_str($temp[1], $connection['opts']);
23 23
         $connection['name'] = $temp[0];
24 24
         if (!is_file($connection['name']) && is_file('/'.$connection['name'])) {
25
-           $connection['name'] = '/'.$connection['name'];
25
+            $connection['name'] = '/'.$connection['name'];
26 26
         }
27 27
         $this->connection = $connection;
28 28
     }
Please login to merge, or discard this patch.