Completed
Push — master ( 16dc3b...faf73e )
by Ivan
15:24
created
src/schema/Mapper.php 1 patch
Spacing   +19 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
      * @param class-string<T> $clss
28 28
      * @return void
29 29
      */
30
-    public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class)
30
+    public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class)
31 31
     {
32 32
         $this->db = $db;
33 33
         if (!$table) {
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
         $temp = [];
64 64
         foreach ($this->table->getPrimaryKey() as $column) {
65 65
             try {
66
-                $temp[(string)$column] = $entity->{$column} ?? null;
66
+                $temp[(string) $column] = $entity->{$column} ?? null;
67 67
                 /** @phpstan-ignore-next-line */
68 68
             } catch (\Throwable $ignore) {
69 69
             }
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
         // BEG: ugly hack to get relations changed directly on the object (not hydrated)
95 95
         $hack = [];
96
-        foreach ((array)$entity as $k => $v) {
96
+        foreach ((array) $entity as $k => $v) {
97 97
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
98 98
         }
99 99
         $hack = $hack['changed'] ?? [];
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         foreach ($columns as $column) {
105 105
             try {
106 106
                 if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) {
107
-                    $temp[(string)$column] = $entity->{$column};
107
+                    $temp[(string) $column] = $entity->{$column};
108 108
                 }
109 109
             } catch (\Throwable $ignore) {
110 110
             }
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         foreach ($relations as $relation) {
115 115
             try {
116 116
                 if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) {
117
-                    $temp[(string)$relation] = $entity->{$relation};
117
+                    $temp[(string) $relation] = $entity->{$relation};
118 118
                 }
119 119
             } catch (\Throwable $ignore) {
120 120
             }
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
                         $v = [];
136 136
                     }
137 137
                     if ($v instanceof Entity) {
138
-                        $v = [ $v ];
138
+                        $v = [$v];
139 139
                     }
140 140
                     if (is_array($v)) {
141 141
                         foreach ($v as $kk => $vv) {
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
         $temp = [];
185 185
         foreach ($this->table->getColumns() as $column) {
186 186
             if (array_key_exists($column, $data)) {
187
-                $temp[(string)$column] = $data[$column];
187
+                $temp[(string) $column] = $data[$column];
188 188
             } else {
189 189
                 if ($empty) {
190
-                    $temp[(string)$column] = null;
190
+                    $temp[(string) $column] = null;
191 191
                 }
192 192
             }
193 193
         }
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
         $lazy = [];
216 216
         foreach ($this->table->getColumns() as $column) {
217 217
             if (!array_key_exists($column, $data)) {
218
-                $lazy[$column] = function ($entity) use ($column) {
218
+                $lazy[$column] = function($entity) use ($column) {
219 219
                     $query = $this->db->table($this->table->getFullName());
220 220
                     foreach ($this->id($entity) as $k => $v) {
221 221
                         $query->filter($k, $v);
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
     {
239 239
         $relations = [];
240 240
         foreach ($this->table->getRelations() as $name => $relation) {
241
-            $relations[$name] = function (
241
+            $relations[$name] = function(
242 242
                 $entity,
243 243
                 bool $queryOnly = false
244 244
             ) use (
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
                         return $this->objects[spl_object_hash($entity)][4][$name] = null;
253 253
                     }
254 254
                     $value = $relation->many ?
255
-                        Collection::from(array_map(function ($v) use ($mapper) {
255
+                        Collection::from(array_map(function($v) use ($mapper) {
256 256
                             return $mapper->entity($v);
257 257
                         }, $data[$name]))
258
-                            ->filter(function ($v) use ($mapper) {
258
+                            ->filter(function($v) use ($mapper) {
259 259
                                 return !$mapper->deleted($v);
260 260
                             }) :
261 261
                         ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name]));
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                 }
265 265
                 $query = $this->db->tableMapped($relation->table->getFullName());
266 266
                 if ($relation->sql) {
267
-                    $query->where($relation->sql, $relation->par?:[]);
267
+                    $query->where($relation->sql, $relation->par ?: []);
268 268
                 }
269 269
                 if ($relation->pivot) {
270 270
                     $nm = null;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                     }
286 286
                     $pk = $this->id($entity);
287 287
                     foreach ($pk as $k => $v) {
288
-                        $query->filter($nm . '.' . $k, $v);
288
+                        $query->filter($nm.'.'.$k, $v);
289 289
                     }
290 290
                 } else {
291 291
                     $temp = $this->toArray($entity, array_keys($relation->keymap));
@@ -297,10 +297,9 @@  discard block
 block discarded – undo
297 297
                     return $query;
298 298
                 }
299 299
                 $value = $relation->many ?
300
-                    $query->iterator() :
301
-                    ($query[0] ?? null);
300
+                    $query->iterator() : ($query[0] ?? null);
302 301
                 if ($value instanceof Collection) {
303
-                    $value->filter(function ($v) use ($mapper) {
302
+                    $value->filter(function($v) use ($mapper) {
304 303
                         return !$mapper->deleted($v);
305 304
                     });
306 305
                 } elseif (isset($value) && $mapper->deleted($value)) {
@@ -578,7 +577,7 @@  discard block
 block discarded – undo
578 577
             }
579 578
         }
580 579
     }
581
-    public function exists(array|object $entity): bool
580
+    public function exists(array | object $entity): bool
582 581
     {
583 582
         if (is_array($entity)) {
584 583
             $primary = [];
@@ -592,7 +591,7 @@  discard block
 block discarded – undo
592 591
         return isset($this->objects[spl_object_hash($entity)]) &&
593 592
             $this->objects[spl_object_hash($entity)][5] === false;
594 593
     }
595
-    public function deleted(array|object $entity): bool
594
+    public function deleted(array | object $entity): bool
596 595
     {
597 596
         if (is_array($entity)) {
598 597
             $primary = [];
@@ -678,7 +677,7 @@  discard block
 block discarded – undo
678 677
         return array_filter(
679 678
             array_values(
680 679
                 array_map(
681
-                    function ($v) {
680
+                    function($v) {
682 681
                         return $v[5] ? null : ($v[1] ?? null);
683 682
                     },
684 683
                     $this->objects
Please login to merge, or discard this patch.