Completed
Push — master ( f53543...f899b9 )
by Ivan
12:44
created
src/schema/Mapper.php 1 patch
Spacing   +12 added lines, -13 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 $table = '', string $clss = Entity::class)
30
+    public function __construct(DBInterface $db, string | Table $table = '', string $clss = Entity::class)
31 31
     {
32 32
         $this->db = $db;
33 33
         if (!$table) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 
95 95
         // BEG: ugly hack to get relations changed directly on the object (not hydrated)
96 96
         $hack = [];
97
-        foreach ((array)$entity as $k => $v) {
97
+        foreach ((array) $entity as $k => $v) {
98 98
             $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v;
99 99
         }
100 100
         $hack = $hack['changed'] ?? [];
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
         $lazy = [];
164 164
         foreach ($this->table->getColumns() as $column) {
165 165
             if (!array_key_exists($column, $temp)) {
166
-                $lazy[$column] = function ($entity) use ($column) {
166
+                $lazy[$column] = function($entity) use ($column) {
167 167
                     $query = $this->db->table($this->table->getFullName());
168 168
                     foreach ($this->id($entity) as $k => $v) {
169 169
                         $query->filter($k, $v);
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
         }
183 183
         $relations = [];
184 184
         foreach ($this->table->getRelations() as $name => $relation) {
185
-            $relations[$name] = function (object $entity, bool $queryOnly = false) use (
185
+            $relations[$name] = function(object $entity, bool $queryOnly = false) use (
186 186
                 $name,
187 187
                 $relation,
188 188
                 $data
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
                         return $this->objects[spl_object_hash($entity)][4][$name] = null;
194 194
                     }
195 195
                     $value = $relation->many ?
196
-                        Collection::from(array_map(function ($v) use ($mapper) {
196
+                        Collection::from(array_map(function($v) use ($mapper) {
197 197
                             return $mapper->entity($v);
198 198
                         }, $data[$name]))
199
-                            ->filter(function ($v) use ($mapper) {
199
+                            ->filter(function($v) use ($mapper) {
200 200
                                 return !$mapper->deleted($v);
201 201
                             }) :
202 202
                         ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name]));
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
                 }
206 206
                 $query = $this->db->tableMapped($relation->table->getFullName());
207 207
                 if ($relation->sql) {
208
-                    $query->where($relation->sql, $relation->par?:[]);
208
+                    $query->where($relation->sql, $relation->par ?: []);
209 209
                 }
210 210
                 if ($relation->pivot) {
211 211
                     $nm = null;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                     }
227 227
                     $pk = $this->id($entity);
228 228
                     foreach ($pk as $k => $v) {
229
-                        $query->filter($nm . '.' . $k, $v);
229
+                        $query->filter($nm.'.'.$k, $v);
230 230
                     }
231 231
                 } else {
232 232
                     $temp = $this->toArray($entity, array_keys($relation->keymap));
@@ -238,10 +238,9 @@  discard block
 block discarded – undo
238 238
                     return $query;
239 239
                 }
240 240
                 $value = $relation->many ?
241
-                    $query->iterator() :
242
-                    ($query[0] ?? null);
241
+                    $query->iterator() : ($query[0] ?? null);
243 242
                 if ($value instanceof Collection) {
244
-                    $value->filter(function ($v) use ($mapper) {
243
+                    $value->filter(function($v) use ($mapper) {
245 244
                         return !$mapper->deleted($v);
246 245
                     });
247 246
                 } elseif (isset($value) && $mapper->deleted($value)) {
@@ -489,7 +488,7 @@  discard block
 block discarded – undo
489 488
         }
490 489
         return $entity;
491 490
     }
492
-    public function exists(array|object $entity): bool
491
+    public function exists(array | object $entity): bool
493 492
     {
494 493
         if (is_array($entity)) {
495 494
             $primary = [];
@@ -502,7 +501,7 @@  discard block
 block discarded – undo
502 501
         return isset($this->objects[spl_object_hash($entity)]) &&
503 502
             $this->objects[spl_object_hash($entity)] !== false;
504 503
     }
505
-    public function deleted(array|object $entity): bool
504
+    public function deleted(array | object $entity): bool
506 505
     {
507 506
         if (is_array($entity)) {
508 507
             $primary = [];
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,10 +58,10 @@
 block discarded – undo
58 58
      * @param 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 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
 }
Please login to merge, or discard this patch.