@@ -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 | } |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | $temp = []; |
154 | 154 | foreach ($this->table->getColumns() as $column) { |
155 | 155 | if (array_key_exists($column, $data)) { |
156 | - $temp[(string)$column] = $data[$column]; |
|
156 | + $temp[(string) $column] = $data[$column]; |
|
157 | 157 | } |
158 | 158 | if ($empty) { |
159 | - $temp[(string)$column] = null; |
|
159 | + $temp[(string) $column] = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | $entity = $this->instance( |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $lazy = []; |
184 | 184 | foreach ($this->table->getColumns() as $column) { |
185 | 185 | if (!array_key_exists($column, $data)) { |
186 | - $lazy[$column] = function ($entity) use ($column) { |
|
186 | + $lazy[$column] = function($entity) use ($column) { |
|
187 | 187 | $query = $this->db->table($this->table->getFullName()); |
188 | 188 | foreach ($this->id($entity) as $k => $v) { |
189 | 189 | $query->filter($k, $v); |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | { |
207 | 207 | $relations = []; |
208 | 208 | foreach ($this->table->getRelations() as $name => $relation) { |
209 | - $relations[$name] = function ( |
|
209 | + $relations[$name] = function( |
|
210 | 210 | $entity, |
211 | 211 | bool $queryOnly = false |
212 | 212 | ) use ( |
@@ -220,10 +220,10 @@ discard block |
||
220 | 220 | return $this->objects[spl_object_hash($entity)][4][$name] = null; |
221 | 221 | } |
222 | 222 | $value = $relation->many ? |
223 | - Collection::from(array_map(function ($v) use ($mapper) { |
|
223 | + Collection::from(array_map(function($v) use ($mapper) { |
|
224 | 224 | return $mapper->entity($v); |
225 | 225 | }, $data[$name])) |
226 | - ->filter(function ($v) use ($mapper) { |
|
226 | + ->filter(function($v) use ($mapper) { |
|
227 | 227 | return !$mapper->deleted($v); |
228 | 228 | }) : |
229 | 229 | ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name])); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | } |
233 | 233 | $query = $this->db->tableMapped($relation->table->getFullName()); |
234 | 234 | if ($relation->sql) { |
235 | - $query->where($relation->sql, $relation->par?:[]); |
|
235 | + $query->where($relation->sql, $relation->par ?: []); |
|
236 | 236 | } |
237 | 237 | if ($relation->pivot) { |
238 | 238 | $nm = null; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | } |
254 | 254 | $pk = $this->id($entity); |
255 | 255 | foreach ($pk as $k => $v) { |
256 | - $query->filter($nm . '.' . $k, $v); |
|
256 | + $query->filter($nm.'.'.$k, $v); |
|
257 | 257 | } |
258 | 258 | } else { |
259 | 259 | $temp = $this->toArray($entity, array_keys($relation->keymap)); |
@@ -265,10 +265,9 @@ discard block |
||
265 | 265 | return $query; |
266 | 266 | } |
267 | 267 | $value = $relation->many ? |
268 | - $query->iterator() : |
|
269 | - ($query[0] ?? null); |
|
268 | + $query->iterator() : ($query[0] ?? null); |
|
270 | 269 | if ($value instanceof Collection) { |
271 | - $value->filter(function ($v) use ($mapper) { |
|
270 | + $value->filter(function($v) use ($mapper) { |
|
272 | 271 | return !$mapper->deleted($v); |
273 | 272 | }); |
274 | 273 | } elseif (isset($value) && $mapper->deleted($value)) { |
@@ -501,7 +500,7 @@ discard block |
||
501 | 500 | } |
502 | 501 | } |
503 | 502 | } |
504 | - public function exists(array|object $entity): bool |
|
503 | + public function exists(array | object $entity): bool |
|
505 | 504 | { |
506 | 505 | if (is_array($entity)) { |
507 | 506 | $primary = []; |
@@ -515,7 +514,7 @@ discard block |
||
515 | 514 | return isset($this->objects[spl_object_hash($entity)]) && |
516 | 515 | $this->objects[spl_object_hash($entity)][5] === false; |
517 | 516 | } |
518 | - public function deleted(array|object $entity): bool |
|
517 | + public function deleted(array | object $entity): bool |
|
519 | 518 | { |
520 | 519 | if (is_array($entity)) { |
521 | 520 | $primary = []; |
@@ -587,7 +586,7 @@ discard block |
||
587 | 586 | return array_filter( |
588 | 587 | array_values( |
589 | 588 | array_map( |
590 | - function ($v) { |
|
589 | + function($v) { |
|
591 | 590 | return $v[5] ? null : ($v[1] ?? null); |
592 | 591 | }, |
593 | 592 | $this->objects |