Completed
Push — master ( 43a9c4...b250e3 )
by Ivan
11:04
created
src/DB.php 1 patch
Spacing   +24 added lines, -25 removed lines patch added patch discarded remove patch
@@ -69,18 +69,18 @@  discard block
 block discarded – undo
69 69
                 ];
70 70
             }
71 71
         }
72
-        $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null;
73
-        $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null;
74
-        $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null;
75
-        $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null;
76
-        $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? trim((string)$temp['path'], '/') : null;
77
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
78
-        if (isset($temp['query']) && strlen((string)$temp['query'])) {
79
-            parse_str((string)$temp['query'], $connection['opts']);
72
+        $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null;
73
+        $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null;
74
+        $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null;
75
+        $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null;
76
+        $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? trim((string) $temp['path'], '/') : null;
77
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
78
+        if (isset($temp['query']) && strlen((string) $temp['query'])) {
79
+            parse_str((string) $temp['query'], $connection['opts']);
80 80
         }
81 81
         // create the driver
82 82
         $connection['type'] = $aliases[$connection['type']] ?? $connection['type'];
83
-        $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver';
83
+        $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver';
84 84
         if (!class_exists($tmp)) {
85 85
             throw new DBException('Unknown DB backend');
86 86
         }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         $new = '';
119 119
         $par = array_values($par);
120 120
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
121
-            $par = [ $par ];
121
+            $par = [$par];
122 122
         }
123 123
         $parts = explode('??', $sql);
124 124
         $index = 0;
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
             $index += count($tmp) - 1;
129 129
             if (isset($par[$index])) {
130 130
                 if (!is_array($par[$index])) {
131
-                    $par[$index] = [ $par[$index] ];
131
+                    $par[$index] = [$par[$index]];
132 132
                 }
133 133
                 $params = $par[$index];
134 134
                 array_splice($par, $index, 1, $params);
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                 $new .= implode(',', array_fill(0, count($params), '?'));
137 137
             }
138 138
         }
139
-        return [ $new, $par ];
139
+        return [$new, $par];
140 140
     }
141 141
     /**
142 142
      * Run a query (prepare & execute).
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
     ): Collection {
186 186
         $coll = Collection::from($this->query($sql, $par, $buff));
187 187
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
188
-            $coll->map(function ($v) use ($keys) {
188
+            $coll->map(function($v) use ($keys) {
189 189
                 $new = [];
190 190
                 foreach ($v as $k => $vv) {
191 191
                     $new[call_user_func($keys, $k)] = $vv;
@@ -194,18 +194,18 @@  discard block
 block discarded – undo
194 194
             });
195 195
         }
196 196
         if ($key !== null) {
197
-            $coll->mapKey(function ($v) use ($key) {
197
+            $coll->mapKey(function($v) use ($key) {
198 198
                 return $v[$key];
199 199
             });
200 200
         }
201 201
         if ($skip) {
202
-            $coll->map(function ($v) use ($key) {
202
+            $coll->map(function($v) use ($key) {
203 203
                 unset($v[$key]);
204 204
                 return $v;
205 205
             });
206 206
         }
207 207
         if ($opti) {
208
-            $coll->map(function ($v) {
208
+            $coll->map(function($v) {
209 209
                 return count($v) === 1 ? current($v) : $v;
210 210
             });
211 211
         }
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
      */
325 325
     public function getSchema(bool $asPlainArray = true): array
326 326
     {
327
-        return !$asPlainArray ? $this->tables : array_map(function ($table) {
327
+        return !$asPlainArray ? $this->tables : array_map(function($table) {
328 328
             return [
329 329
                 'name' => $table->getName(),
330 330
                 'schema' => $table->getSchema(),
331 331
                 'pkey' => $table->getPrimaryKey(),
332 332
                 'comment' => $table->getComment(),
333
-                'columns' => array_map(function ($column) {
333
+                'columns' => array_map(function($column) {
334 334
                     return [
335 335
                         'name' => $column->getName(),
336 336
                         'type' => $column->getType(),
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
                         'nullable' => $column->isNullable()
342 342
                     ];
343 343
                 }, $table->getFullColumns()),
344
-                'relations' => array_map(function ($rel) {
344
+                'relations' => array_map(function($rel) {
345 345
                     $relation = clone $rel;
346
-                    $relation = (array)$relation;
346
+                    $relation = (array) $relation;
347 347
                     $relation['table'] = $rel->table->getName();
348 348
                     if ($rel->pivot) {
349 349
                         $relation['pivot'] = $rel->pivot->getName();
@@ -405,11 +405,10 @@  discard block
 block discarded – undo
405 405
     {
406 406
         return new TableQueryMapped($this, $this->definition($table), $findRelations);
407 407
     }
408
-    public function __call(string $method, array $args): TableQuery|TableQueryMapped
408
+    public function __call(string $method, array $args): TableQuery | TableQueryMapped
409 409
     {
410 410
         return ($args[0] ?? false) ?
411
-            $this->tableMapped($method, $args[1] ?? false) :
412
-            $this->table($method, $args[1] ?? false);
411
+            $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false);
413 412
     }
414 413
     public function findRelation(string $start, string $end): array
415 414
     {
@@ -442,12 +441,12 @@  discard block
 block discarded – undo
442 441
                     $relations[$t] = $w;
443 442
                 }
444 443
                 if (!isset($schema[$name])) {
445
-                    $schema[$name] = [ 'edges' => [] ];
444
+                    $schema[$name] = ['edges' => []];
446 445
                 }
447 446
                 foreach ($relations as $t => $w) {
448 447
                     $schema[$name]['edges'][$t] = $w;
449 448
                     if (!isset($schema[$t])) {
450
-                        $schema[$t] = [ 'edges' => [] ];
449
+                        $schema[$t] = ['edges' => []];
451 450
                     }
452 451
                     $schema[$t]['edges'][$name] = $w;
453 452
                 }
Please login to merge, or discard this patch.