Completed
Push — master ( f41d5c...be2ee3 )
by Ivan
10:35
created
src/schema/Mapper.php 1 patch
Spacing   +18 added lines, -19 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
      * @param class-string<T> $clss
27 27
      * @return void
28 28
      */
29
-    public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class)
29
+    public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class)
30 30
     {
31 31
         $this->db = $db;
32 32
         if (!$table) {
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $temp = [];
63 63
         foreach ($this->table->getPrimaryKey() as $column) {
64 64
             try {
65
-                $temp[(string)$column] = $entity->{$column} ?? null;
65
+                $temp[(string) $column] = $entity->{$column} ?? null;
66 66
                 /** @phpstan-ignore-next-line */
67 67
             } catch (\Throwable $ignore) {
68 68
             }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
         // BEG: ugly hack to get relations changed directly on the object (not hydrated)
94 94
         $hack = [];
95
-        foreach ((array)$entity as $k => $v) {
95
+        foreach ((array) $entity as $k => $v) {
96 96
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
97 97
         }
98 98
         $hack = $hack['changed'] ?? [];
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         foreach ($columns as $column) {
104 104
             try {
105 105
                 if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) {
106
-                    $temp[(string)$column] = $entity->{$column};
106
+                    $temp[(string) $column] = $entity->{$column};
107 107
                 }
108 108
             } catch (\Throwable $ignore) {
109 109
             }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         foreach ($relations as $relation) {
114 114
             try {
115 115
                 if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) {
116
-                    $temp[(string)$relation] = $entity->{$relation};
116
+                    $temp[(string) $relation] = $entity->{$relation};
117 117
                 }
118 118
             } catch (\Throwable $ignore) {
119 119
             }
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
         $temp = [];
153 153
         foreach ($this->table->getColumns() as $column) {
154 154
             if (array_key_exists($column, $data)) {
155
-                $temp[(string)$column] = $data[$column];
155
+                $temp[(string) $column] = $data[$column];
156 156
             }
157 157
             if ($empty) {
158
-                $temp[(string)$column] = null;
158
+                $temp[(string) $column] = null;
159 159
             }
160 160
         }
161 161
         $entity = $this->instance(
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
         $lazy = [];
182 182
         foreach ($this->table->getColumns() as $column) {
183 183
             if (!array_key_exists($column, $data)) {
184
-                $lazy[$column] = function ($entity) use ($column) {
184
+                $lazy[$column] = function($entity) use ($column) {
185 185
                     $query = $this->db->table($this->table->getFullName());
186 186
                     foreach ($this->id($entity) as $k => $v) {
187 187
                         $query->filter($k, $v);
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
     {
205 205
         $relations = [];
206 206
         foreach ($this->table->getRelations() as $name => $relation) {
207
-            $relations[$name] = function (
207
+            $relations[$name] = function(
208 208
                 $entity,
209 209
                 bool $queryOnly = false
210 210
             ) use (
@@ -218,10 +218,10 @@  discard block
 block discarded – undo
218 218
                         return $this->objects[spl_object_hash($entity)][4][$name] = null;
219 219
                     }
220 220
                     $value = $relation->many ?
221
-                        Collection::from(array_map(function ($v) use ($mapper) {
221
+                        Collection::from(array_map(function($v) use ($mapper) {
222 222
                             return $mapper->entity($v);
223 223
                         }, $data[$name]))
224
-                            ->filter(function ($v) use ($mapper) {
224
+                            ->filter(function($v) use ($mapper) {
225 225
                                 return !$mapper->deleted($v);
226 226
                             }) :
227 227
                         ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name]));
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                 }
231 231
                 $query = $this->db->tableMapped($relation->table->getFullName());
232 232
                 if ($relation->sql) {
233
-                    $query->where($relation->sql, $relation->par?:[]);
233
+                    $query->where($relation->sql, $relation->par ?: []);
234 234
                 }
235 235
                 if ($relation->pivot) {
236 236
                     $nm = null;
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
                     }
252 252
                     $pk = $this->id($entity);
253 253
                     foreach ($pk as $k => $v) {
254
-                        $query->filter($nm . '.' . $k, $v);
254
+                        $query->filter($nm.'.'.$k, $v);
255 255
                     }
256 256
                 } else {
257 257
                     $temp = $this->toArray($entity, array_keys($relation->keymap));
@@ -263,10 +263,9 @@  discard block
 block discarded – undo
263 263
                     return $query;
264 264
                 }
265 265
                 $value = $relation->many ?
266
-                    $query->iterator() :
267
-                    ($query[0] ?? null);
266
+                    $query->iterator() : ($query[0] ?? null);
268 267
                 if ($value instanceof Collection) {
269
-                    $value->filter(function ($v) use ($mapper) {
268
+                    $value->filter(function($v) use ($mapper) {
270 269
                         return !$mapper->deleted($v);
271 270
                     });
272 271
                 } elseif (isset($value) && $mapper->deleted($value)) {
@@ -499,7 +498,7 @@  discard block
 block discarded – undo
499 498
             }
500 499
         }
501 500
     }
502
-    public function exists(array|object $entity): bool
501
+    public function exists(array | object $entity): bool
503 502
     {
504 503
         if (is_array($entity)) {
505 504
             $primary = [];
@@ -512,7 +511,7 @@  discard block
 block discarded – undo
512 511
         return isset($this->objects[spl_object_hash($entity)]) &&
513 512
             $this->objects[spl_object_hash($entity)] !== false;
514 513
     }
515
-    public function deleted(array|object $entity): bool
514
+    public function deleted(array | object $entity): bool
516 515
     {
517 516
         if (is_array($entity)) {
518 517
             $primary = [];
@@ -584,7 +583,7 @@  discard block
 block discarded – undo
584 583
         return array_filter(
585 584
             array_values(
586 585
                 array_map(
587
-                    function ($v) {
586
+                    function($v) {
588 587
                         return $v[1] ?? null;
589 588
                     },
590 589
                     $this->objects
Please login to merge, or discard this patch.
src/schema/TableQueryMapped.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
     public function __construct(
21 21
         DBInterface $db,
22
-        Table|string $table,
22
+        Table | string $table,
23 23
         bool $findRelations = false,
24 24
         ?MapperInterface $mapper = null
25 25
     ) {
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public function iterator(array $fields = null, array $collectionKey = null): Collection
35 35
     {
36 36
         return Collection::from(parent::iterator($fields, $collectionKey))
37
-            ->map(function ($v) {
37
+            ->map(function($v) {
38 38
                 return $this->mapper->entity($v);
39 39
             })
40 40
             ->values();
Please login to merge, or discard this patch.
src/DB.php 1 patch
Spacing   +27 added lines, -29 removed lines patch added patch discarded remove patch
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
                 ];
75 75
             }
76 76
         }
77
-        $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null;
78
-        $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null;
79
-        $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null;
80
-        $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null;
81
-        $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ?
82
-            trim((string)$temp['path'], '/') : null;
83
-        $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null;
84
-        if (isset($temp['query']) && strlen((string)$temp['query'])) {
85
-            parse_str((string)$temp['query'], $connection['opts']);
77
+        $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null;
78
+        $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null;
79
+        $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null;
80
+        $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null;
81
+        $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ?
82
+            trim((string) $temp['path'], '/') : null;
83
+        $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null;
84
+        if (isset($temp['query']) && strlen((string) $temp['query'])) {
85
+            parse_str((string) $temp['query'], $connection['opts']);
86 86
         }
87 87
         // create the driver
88 88
         $connection['type'] = $aliases[$connection['type']] ?? $connection['type'];
89
-        $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver';
89
+        $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver';
90 90
         if (!class_exists($tmp)) {
91 91
             throw new DBException('Unknown DB backend');
92 92
         }
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         $new = '';
125 125
         $par = array_values($par);
126 126
         if (substr_count($sql, '?') === 2 && !is_array($par[0])) {
127
-            $par = [ $par ];
127
+            $par = [$par];
128 128
         }
129 129
         $parts = explode('??', $sql);
130 130
         $index = 0;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
             $index += count($tmp) - 1;
135 135
             if (isset($par[$index])) {
136 136
                 if (!is_array($par[$index])) {
137
-                    $par[$index] = [ $par[$index] ];
137
+                    $par[$index] = [$par[$index]];
138 138
                 }
139 139
                 $params = $par[$index];
140 140
                 array_splice($par, $index, 1, $params);
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                 $new .= implode(',', array_fill(0, count($params), '?'));
143 143
             }
144 144
         }
145
-        return [ $new, $par ];
145
+        return [$new, $par];
146 146
     }
147 147
     /**
148 148
      * Run a query (prepare & execute).
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     ): Collection {
192 192
         $coll = Collection::from($this->query($sql, $par, $buff));
193 193
         if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) {
194
-            $coll->map(function ($v) use ($keys) {
194
+            $coll->map(function($v) use ($keys) {
195 195
                 $new = [];
196 196
                 foreach ($v as $k => $vv) {
197 197
                     $new[call_user_func($keys, $k)] = $vv;
@@ -200,18 +200,18 @@  discard block
 block discarded – undo
200 200
             });
201 201
         }
202 202
         if ($key !== null) {
203
-            $coll->mapKey(function ($v) use ($key): int|string {
203
+            $coll->mapKey(function($v) use ($key): int | string {
204 204
                 return $v[$key];
205 205
             });
206 206
         }
207 207
         if ($skip) {
208
-            $coll->map(function ($v) use ($key) {
208
+            $coll->map(function($v) use ($key) {
209 209
                 unset($v[$key]);
210 210
                 return $v;
211 211
             });
212 212
         }
213 213
         if ($opti) {
214
-            $coll->map(function ($v) {
214
+            $coll->map(function($v) {
215 215
                 return count($v) === 1 ? current($v) : $v;
216 216
             });
217 217
         }
@@ -328,8 +328,7 @@  discard block
 block discarded – undo
328 328
     public function definition(string $table, bool $detectRelations = true) : Table
329 329
     {
330 330
         return isset($this->schema) ?
331
-            $this->schema->getTable($table) :
332
-            $this->driver->table($table, $detectRelations);
331
+            $this->schema->getTable($table) : $this->driver->table($table, $detectRelations);
333 332
     }
334 333
 
335 334
     public function hasSchema(): bool
@@ -439,11 +438,11 @@  discard block
 block discarded – undo
439 438
      * @param class-string<T>|Table|string $table
440 439
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
441 440
      */
442
-    public function getMapper(Table|string $table): MapperInterface
441
+    public function getMapper(Table | string $table): MapperInterface
443 442
     {
444 443
         if (is_string($table)) {
445
-            if (isset($this->mappers['::' . $table])) {
446
-                return $this->mappers['::' . $table];
444
+            if (isset($this->mappers['::'.$table])) {
445
+                return $this->mappers['::'.$table];
447 446
             }
448 447
             $table = $this->definition($table);
449 448
         }
@@ -452,14 +451,14 @@  discard block
 block discarded – undo
452 451
         }
453 452
         return $this->mappers[$table->getFullName()] = new Mapper($this, $table);
454 453
     }
455
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static
454
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static
456 455
     {
457 456
         if (is_string($table)) {
458 457
             $table = $this->definition($table);
459 458
         }
460 459
         $this->mappers[$table->getFullName()] = $mapper;
461 460
         if (isset($class)) {
462
-            $this->mappers['::' . $class] = $mapper;
461
+            $this->mappers['::'.$class] = $mapper;
463 462
         }
464 463
         return $this;
465 464
     }
@@ -470,11 +469,10 @@  discard block
 block discarded – undo
470 469
     ): TableQueryMapped {
471 470
         return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper);
472 471
     }
473
-    public function __call(string $method, array $args): TableQuery|TableQueryMapped
472
+    public function __call(string $method, array $args): TableQuery | TableQueryMapped
474 473
     {
475 474
         return ($args[0] ?? false) ?
476
-            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) :
477
-            $this->table($method, $args[1] ?? false);
475
+            $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false);
478 476
     }
479 477
     public function findRelation(string $start, string $end): array
480 478
     {
@@ -510,12 +508,12 @@  discard block
 block discarded – undo
510 508
                     $relations[$t] = $w;
511 509
                 }
512 510
                 if (!isset($schema[$name])) {
513
-                    $schema[$name] = [ 'edges' => [] ];
511
+                    $schema[$name] = ['edges' => []];
514 512
                 }
515 513
                 foreach ($relations as $t => $w) {
516 514
                     $schema[$name]['edges'][$t] = $w;
517 515
                     if (!isset($schema[$t])) {
518
-                        $schema[$t] = [ 'edges' => [] ];
516
+                        $schema[$t] = ['edges' => []];
519 517
                     }
520 518
                     $schema[$t]['edges'][$name] = $w;
521 519
                 }
Please login to merge, or discard this patch.
src/DBInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      * @param class-string<T>|Table|string $table
119 119
      * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>)
120 120
      */
121
-    public function getMapper(Table|string $table): MapperInterface;
121
+    public function getMapper(Table | string $table): MapperInterface;
122 122
     /*
123 123
      * @template T of Entity
124 124
      * @param Table|string $table
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @param null|class-string<T> $class
127 127
      * @return static 
128 128
      */
129
-    public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static;
129
+    public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static;
130 130
     public function tableMapped(
131 131
         string $table,
132 132
         bool $findRelations = false,
Please login to merge, or discard this patch.
src/schema/MapperInterface.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,12 +58,12 @@
 block discarded – undo
58 58
      * @param array|T $entity
59 59
      * @return bool
60 60
      */
61
-    public function deleted(array|object $entity): bool;
61
+    public function deleted(array | object $entity): bool;
62 62
     /**
63 63
      * @param array|T $entity
64 64
      * @return bool
65 65
      */
66
-    public function exists(array|object $entity): bool;
66
+    public function exists(array | object $entity): bool;
67 67
     /**
68 68
      * @return array<int,T>
69 69
      */
Please login to merge, or discard this patch.