@@ -539,7 +539,7 @@ |
||
| 539 | 539 | (isset($value) && is_array($value) && !in_array($e, $value, true)) || |
| 540 | 540 | (($value instanceof Collection) && !$value->contains($e)) |
| 541 | 541 | ) |
| 542 | - ) { |
|
| 542 | + ) { |
|
| 543 | 543 | $mapper->delete($e, true); |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -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 | } 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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)) { |
@@ -320,7 +319,7 @@ discard block |
||
| 320 | 319 | { |
| 321 | 320 | // BEG: ugly hack to get changed columns |
| 322 | 321 | $hack = []; |
| 323 | - foreach ((array)$entity as $k => $v) { |
|
| 322 | + foreach ((array) $entity as $k => $v) { |
|
| 324 | 323 | $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v; |
| 325 | 324 | } |
| 326 | 325 | $hack = $hack['changed'] ?? []; |
@@ -611,7 +610,7 @@ discard block |
||
| 611 | 610 | } |
| 612 | 611 | } |
| 613 | 612 | } |
| 614 | - public function exists(array|object $entity): bool |
|
| 613 | + public function exists(array | object $entity): bool |
|
| 615 | 614 | { |
| 616 | 615 | if (is_array($entity)) { |
| 617 | 616 | $primary = []; |
@@ -625,7 +624,7 @@ discard block |
||
| 625 | 624 | return isset($this->objects[spl_object_hash($entity)]) && |
| 626 | 625 | $this->objects[spl_object_hash($entity)][5] === false; |
| 627 | 626 | } |
| 628 | - public function deleted(array|object $entity): bool |
|
| 627 | + public function deleted(array | object $entity): bool |
|
| 629 | 628 | { |
| 630 | 629 | if (is_array($entity)) { |
| 631 | 630 | $primary = []; |
@@ -711,7 +710,7 @@ discard block |
||
| 711 | 710 | return array_filter( |
| 712 | 711 | array_values( |
| 713 | 712 | array_map( |
| 714 | - function ($v) { |
|
| 713 | + function($v) { |
|
| 715 | 714 | return $v[5] ? null : ($v[1] ?? null); |
| 716 | 715 | }, |
| 717 | 716 | $this->objects |