@@ -27,7 +27,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
189 | 189 | if ($empty) { |
190 | - $temp[(string)$column] = null; |
|
190 | + $temp[(string) $column] = null; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | $entity = $this->instance( |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $lazy = []; |
215 | 215 | foreach ($this->table->getColumns() as $column) { |
216 | 216 | if (!array_key_exists($column, $data)) { |
217 | - $lazy[$column] = function ($entity) use ($column) { |
|
217 | + $lazy[$column] = function($entity) use ($column) { |
|
218 | 218 | $query = $this->db->table($this->table->getFullName()); |
219 | 219 | foreach ($this->id($entity) as $k => $v) { |
220 | 220 | $query->filter($k, $v); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | { |
238 | 238 | $relations = []; |
239 | 239 | foreach ($this->table->getRelations() as $name => $relation) { |
240 | - $relations[$name] = function ( |
|
240 | + $relations[$name] = function( |
|
241 | 241 | $entity, |
242 | 242 | bool $queryOnly = false |
243 | 243 | ) use ( |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | return $this->objects[spl_object_hash($entity)][4][$name] = null; |
252 | 252 | } |
253 | 253 | $value = $relation->many ? |
254 | - Collection::from(array_map(function ($v) use ($mapper) { |
|
254 | + Collection::from(array_map(function($v) use ($mapper) { |
|
255 | 255 | return $mapper->entity($v); |
256 | 256 | }, $data[$name])) |
257 | - ->filter(function ($v) use ($mapper) { |
|
257 | + ->filter(function($v) use ($mapper) { |
|
258 | 258 | return !$mapper->deleted($v); |
259 | 259 | }) : |
260 | 260 | ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name])); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | $query = $this->db->tableMapped($relation->table->getFullName()); |
265 | 265 | if ($relation->sql) { |
266 | - $query->where($relation->sql, $relation->par?:[]); |
|
266 | + $query->where($relation->sql, $relation->par ?: []); |
|
267 | 267 | } |
268 | 268 | if ($relation->pivot) { |
269 | 269 | $nm = null; |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | $pk = $this->id($entity); |
286 | 286 | foreach ($pk as $k => $v) { |
287 | - $query->filter($nm . '.' . $k, $v); |
|
287 | + $query->filter($nm.'.'.$k, $v); |
|
288 | 288 | } |
289 | 289 | } else { |
290 | 290 | $temp = $this->toArray($entity, array_keys($relation->keymap)); |
@@ -296,10 +296,9 @@ discard block |
||
296 | 296 | return $query; |
297 | 297 | } |
298 | 298 | $value = $relation->many ? |
299 | - $query->iterator() : |
|
300 | - ($query[0] ?? null); |
|
299 | + $query->iterator() : ($query[0] ?? null); |
|
301 | 300 | if ($value instanceof Collection) { |
302 | - $value->filter(function ($v) use ($mapper) { |
|
301 | + $value->filter(function($v) use ($mapper) { |
|
303 | 302 | return !$mapper->deleted($v); |
304 | 303 | }); |
305 | 304 | } elseif (isset($value) && $mapper->deleted($value)) { |
@@ -551,7 +550,7 @@ discard block |
||
551 | 550 | } |
552 | 551 | } |
553 | 552 | } |
554 | - public function exists(array|object $entity): bool |
|
553 | + public function exists(array | object $entity): bool |
|
555 | 554 | { |
556 | 555 | if (is_array($entity)) { |
557 | 556 | $primary = []; |
@@ -565,7 +564,7 @@ discard block |
||
565 | 564 | return isset($this->objects[spl_object_hash($entity)]) && |
566 | 565 | $this->objects[spl_object_hash($entity)][5] === false; |
567 | 566 | } |
568 | - public function deleted(array|object $entity): bool |
|
567 | + public function deleted(array | object $entity): bool |
|
569 | 568 | { |
570 | 569 | if (is_array($entity)) { |
571 | 570 | $primary = []; |
@@ -643,7 +642,7 @@ discard block |
||
643 | 642 | return array_filter( |
644 | 643 | array_values( |
645 | 644 | array_map( |
646 | - function ($v) { |
|
645 | + function($v) { |
|
647 | 646 | return $v[5] ? null : ($v[1] ?? null); |
648 | 647 | }, |
649 | 648 | $this->objects |