Completed
Push — master ( 4c0a9e...451460 )
by Ivan
14:51 queued 14s
created
src/DBInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@
 block discarded – undo
48 48
     public function getSchema(): Schema;
49 49
     public function setSchema(Schema $schema): static;
50 50
     public function table(string $table, bool $findRelations = false): TableQuery;
51
-    public function getMapper(Table|string $table): MapperInterface;
52
-    public function setMapper(Table|string $table, MapperInterface $mapper): static;
51
+    public function getMapper(Table | string $table): MapperInterface;
52
+    public function setMapper(Table | string $table, MapperInterface $mapper): static;
53 53
     public function tableMapped(
54 54
         string $table,
55 55
         bool $findRelations = false,
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +24 added lines, -26 removed lines patch added patch discarded remove patch
@@ -69,19 +69,19 @@  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']) ?
77
-            trim((string)$temp['path'], '/') : null;
78
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
79
-        if (isset($temp['query']) && strlen((string)$temp['query'])) {
80
-            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']) ?
77
+            trim((string) $temp['path'], '/') : null;
78
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
79
+        if (isset($temp['query']) && strlen((string) $temp['query'])) {
80
+            parse_str((string) $temp['query'], $connection['opts']);
81 81
         }
82 82
         // create the driver
83 83
         $connection['type'] = $aliases[$connection['type']] ?? $connection['type'];
84
-        $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver';
84
+        $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver';
85 85
         if (!class_exists($tmp)) {
86 86
             throw new DBException('Unknown DB backend');
87 87
         }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         $new = '';
122 122
         $par = array_values($par);
123 123
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
124
-            $par = [ $par ];
124
+            $par = [$par];
125 125
         }
126 126
         $parts = explode('??', $sql);
127 127
         $index = 0;
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
             $index += count($tmp) - 1;
132 132
             if (isset($par[$index])) {
133 133
                 if (!is_array($par[$index])) {
134
-                    $par[$index] = [ $par[$index] ];
134
+                    $par[$index] = [$par[$index]];
135 135
                 }
136 136
                 $params = $par[$index];
137 137
                 array_splice($par, $index, 1, $params);
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
                 $new .= implode(',', array_fill(0, count($params), '?'));
140 140
             }
141 141
         }
142
-        return [ $new, $par ];
142
+        return [$new, $par];
143 143
     }
144 144
     /**
145 145
      * Run a query (prepare & execute).
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
     ): Collection {
189 189
         $coll = Collection::from($this->query($sql, $par, $buff));
190 190
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
191
-            $coll->map(function ($v) use ($keys) {
191
+            $coll->map(function($v) use ($keys) {
192 192
                 $new = [];
193 193
                 foreach ($v as $k => $vv) {
194 194
                     $new[call_user_func($keys, $k)] = $vv;
@@ -197,18 +197,18 @@  discard block
 block discarded – undo
197 197
             });
198 198
         }
199 199
         if ($key !== null) {
200
-            $coll->mapKey(function ($v) use ($key) {
200
+            $coll->mapKey(function($v) use ($key) {
201 201
                 return $v[$key];
202 202
             });
203 203
         }
204 204
         if ($skip) {
205
-            $coll->map(function ($v) use ($key) {
205
+            $coll->map(function($v) use ($key) {
206 206
                 unset($v[$key]);
207 207
                 return $v;
208 208
             });
209 209
         }
210 210
         if ($opti) {
211
-            $coll->map(function ($v) {
211
+            $coll->map(function($v) {
212 212
                 return count($v) === 1 ? current($v) : $v;
213 213
             });
214 214
         }
@@ -317,8 +317,7 @@  discard block
 block discarded – undo
317 317
     public function definition(string $table, bool $detectRelations = true) : Table
318 318
     {
319 319
         return isset($this->schema) ?
320
-            $this->schema->getTable($table) :
321
-            $this->driver->table($table, $detectRelations);
320
+            $this->schema->getTable($table) : $this->driver->table($table, $detectRelations);
322 321
     }
323 322
 
324 323
     public function hasSchema(): bool
@@ -363,14 +362,14 @@  discard block
 block discarded – undo
363 362
     {
364 363
         return new TableQuery($this, $this->definition($table), $findRelations);
365 364
     }
366
-    public function getMapper(Table|string $table): MapperInterface
365
+    public function getMapper(Table | string $table): MapperInterface
367 366
     {
368 367
         if (is_string($table)) {
369 368
             $table = $this->definition($table);
370 369
         }
371 370
         return $this->mappers[$table->getFullName()] ?? $this->mappers['*'];
372 371
     }
373
-    public function setMapper(Table|string $table, MapperInterface $mapper): static
372
+    public function setMapper(Table | string $table, MapperInterface $mapper): static
374 373
     {
375 374
         if (is_string($table)) {
376 375
             $table = $this->definition($table);
@@ -386,11 +385,10 @@  discard block
 block discarded – undo
386 385
     {
387 386
         return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper);
388 387
     }
389
-    public function __call(string $method, array $args): TableQuery|TableQueryMapped
388
+    public function __call(string $method, array $args): TableQuery | TableQueryMapped
390 389
     {
391 390
         return ($args[0] ?? false) ?
392
-            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) :
393
-            $this->table($method, $args[1] ?? false);
391
+            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false);
394 392
     }
395 393
     public function findRelation(string $start, string $end): array
396 394
     {
@@ -426,12 +424,12 @@  discard block
 block discarded – undo
426 424
                     $relations[$t] = $w;
427 425
                 }
428 426
                 if (!isset($schema[$name])) {
429
-                    $schema[$name] = [ 'edges' => [] ];
427
+                    $schema[$name] = ['edges' => []];
430 428
                 }
431 429
                 foreach ($relations as $t => $w) {
432 430
                     $schema[$name]['edges'][$t] = $w;
433 431
                     if (!isset($schema[$t])) {
434
-                        $schema[$t] = [ 'edges' => [] ];
432
+                        $schema[$t] = ['edges' => []];
435 433
                     }
436 434
                     $schema[$t]['edges'][$name] = $w;
437 435
                 }
Please login to merge, or discard this patch.
src/schema/Mapper.php 1 patch
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function collection(TableQueryIterator $iterator, Table $definition) : Collection
65 65
     {
66 66
         return Collection::from($iterator)
67
-            ->map(function ($v) use ($definition) {
67
+            ->map(function($v) use ($definition) {
68 68
                 return $this->entity($definition, $v);
69 69
             });
70 70
     }
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         $definition = $entity->definition();
149 149
         foreach ($definition->getColumns() as $column) {
150 150
             if (!array_key_exists($column, $data)) {
151
-                $entity->__lazyProperty($column, function () use ($definition, $primary, $column) {
151
+                $entity->__lazyProperty($column, function() use ($definition, $primary, $column) {
152 152
                     $query = $this->db->table($definition->getFullName());
153 153
                     foreach ($primary as $k => $v) {
154 154
                         $query->filter($k, $v);
@@ -163,12 +163,12 @@  discard block
 block discarded – undo
163 163
                 $name,
164 164
                 array_key_exists($name, $data) && isset($data[$name]) ?
165 165
                     ($relation->many ?
166
-                        array_map(function ($v) use ($relation, $mapper) {
166
+                        array_map(function($v) use ($relation, $mapper) {
167 167
                             return $mapper->entity($relation->table, $v);
168 168
                         }, $data[$name]) :
169 169
                         $mapper->entity($relation->table, $data[$name])
170 170
                     ) :
171
-                    function (
171
+                    function(
172 172
                         array $columns = null,
173 173
                         string $order = null,
174 174
                         bool $desc = false
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
                             $query->columns($columns);
184 184
                         }
185 185
                         if ($relation->sql) {
186
-                            $query->where($relation->sql, $relation->par?:[]);
186
+                            $query->where($relation->sql, $relation->par ?: []);
187 187
                         }
188 188
                         if ($relation->pivot) {
189 189
                             $nm = null;
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
                                 );
204 204
                             }
205 205
                             foreach ($definition->getPrimaryKey() as $v) {
206
-                                $query->filter($nm . '.' . $v, $data[$v] ?? null);
206
+                                $query->filter($nm.'.'.$v, $data[$v] ?? null);
207 207
                             }
208 208
                         } else {
209 209
                             foreach ($relation->keymap as $k => $v) {
@@ -214,8 +214,7 @@  discard block
 block discarded – undo
214 214
                             $query->sort($order, $desc);
215 215
                         }
216 216
                         return $relation->many ?
217
-                            $query->iterator() :
218
-                            $query[0];
217
+                            $query->iterator() : $query[0];
219 218
                     }
220 219
             );
221 220
         }
Please login to merge, or discard this patch.