@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @param class-string<T> $clss |
| 29 | 29 | * @return void |
| 30 | 30 | */ |
| 31 | - public function __construct(DBInterface $db, string|Table|null $table = '', string $clss = Entity::class) |
|
| 31 | + public function __construct(DBInterface $db, string | Table | null $table = '', string $clss = Entity::class) |
|
| 32 | 32 | { |
| 33 | 33 | $this->db = $db; |
| 34 | 34 | if (!$table) { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $temp = []; |
| 65 | 65 | foreach ($this->table->getPrimaryKey() as $column) { |
| 66 | 66 | try { |
| 67 | - $temp[(string)$column] = $entity->{$column} ?? null; |
|
| 67 | + $temp[(string) $column] = $entity->{$column} ?? null; |
|
| 68 | 68 | /** @phpstan-ignore-next-line */ |
| 69 | 69 | } catch (\Throwable $ignore) { |
| 70 | 70 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 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'] ?? []; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | foreach ($columns as $column) { |
| 106 | 106 | try { |
| 107 | 107 | if (in_array($column, $fetched) || array_key_exists($column, $hack) || $fetch) { |
| 108 | - $temp[(string)$column] = $entity->{$column}; |
|
| 108 | + $temp[(string) $column] = $entity->{$column}; |
|
| 109 | 109 | } |
| 110 | 110 | } catch (\Throwable $ignore) { |
| 111 | 111 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | foreach ($relations as $relation) { |
| 116 | 116 | try { |
| 117 | 117 | if (array_key_exists($relation, $fetched) || array_key_exists($relation, $hack) || $fetch) { |
| 118 | - $temp[(string)$relation] = $entity->{$relation}; |
|
| 118 | + $temp[(string) $relation] = $entity->{$relation}; |
|
| 119 | 119 | } |
| 120 | 120 | } catch (\Throwable $ignore) { |
| 121 | 121 | } |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $v = []; |
| 137 | 137 | } |
| 138 | 138 | if ($v instanceof Entity) { |
| 139 | - $v = [ $v ]; |
|
| 139 | + $v = [$v]; |
|
| 140 | 140 | } |
| 141 | 141 | if (is_array($v)) { |
| 142 | 142 | foreach ($v as $kk => $vv) { |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | $temp = []; |
| 211 | 211 | foreach ($this->table->getColumns() as $column) { |
| 212 | 212 | if (array_key_exists($column, $data)) { |
| 213 | - $temp[(string)$column] = $data[$column]; |
|
| 213 | + $temp[(string) $column] = $data[$column]; |
|
| 214 | 214 | } else { |
| 215 | 215 | if ($empty) { |
| 216 | - $temp[(string)$column] = null; |
|
| 216 | + $temp[(string) $column] = null; |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | } |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $lazy = []; |
| 242 | 242 | foreach ($this->table->getColumns() as $column) { |
| 243 | 243 | if (!array_key_exists($column, $data)) { |
| 244 | - $lazy[$column] = function ($entity) use ($column) { |
|
| 244 | + $lazy[$column] = function($entity) use ($column) { |
|
| 245 | 245 | $query = $this->db->table($this->table->getFullName()); |
| 246 | 246 | foreach ($this->id($entity) as $k => $v) { |
| 247 | 247 | $query->filter($k, $v); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | { |
| 265 | 265 | $relations = []; |
| 266 | 266 | foreach ($this->table->getRelations() as $name => $relation) { |
| 267 | - $relations[$name] = function ( |
|
| 267 | + $relations[$name] = function( |
|
| 268 | 268 | $entity, |
| 269 | 269 | bool $queryOnly = false, |
| 270 | 270 | bool $fetchedOnly = false |
@@ -279,10 +279,10 @@ discard block |
||
| 279 | 279 | return $this->objects[spl_object_hash($entity)][4][$name] = null; |
| 280 | 280 | } |
| 281 | 281 | $value = $relation->many ? |
| 282 | - Collection::from(array_map(function ($v) use ($mapper) { |
|
| 282 | + Collection::from(array_map(function($v) use ($mapper) { |
|
| 283 | 283 | return $mapper->entity($v); |
| 284 | 284 | }, $data[$name])) |
| 285 | - ->filter(function ($v) use ($mapper) { |
|
| 285 | + ->filter(function($v) use ($mapper) { |
|
| 286 | 286 | return !$mapper->deleted($v); |
| 287 | 287 | }) : |
| 288 | 288 | ($mapper->deleted($data[$name]) ? null : $mapper->entity($data[$name])); |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | $query = $this->db->tableMapped($relation->table->getFullName()); |
| 296 | 296 | if ($relation->sql) { |
| 297 | - $query->where($relation->sql, $relation->par?:[]); |
|
| 297 | + $query->where($relation->sql, $relation->par ?: []); |
|
| 298 | 298 | } |
| 299 | 299 | if ($relation->pivot) { |
| 300 | 300 | $nm = null; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | $pk = $this->id($entity); |
| 317 | 317 | foreach ($pk as $k => $v) { |
| 318 | - $query->filter($nm . '.' . $k, $v); |
|
| 318 | + $query->filter($nm.'.'.$k, $v); |
|
| 319 | 319 | } |
| 320 | 320 | } else { |
| 321 | 321 | $temp = $this->toArray($entity, array_keys($relation->keymap)); |
@@ -327,10 +327,9 @@ discard block |
||
| 327 | 327 | return $query; |
| 328 | 328 | } |
| 329 | 329 | $value = $relation->many ? |
| 330 | - $query->iterator() : |
|
| 331 | - ($query[0] ?? null); |
|
| 330 | + $query->iterator() : ($query[0] ?? null); |
|
| 332 | 331 | if ($value instanceof Collection) { |
| 333 | - $value->filter(function ($v) use ($mapper) { |
|
| 332 | + $value->filter(function($v) use ($mapper) { |
|
| 334 | 333 | return !$mapper->deleted($v); |
| 335 | 334 | }); |
| 336 | 335 | } elseif (isset($value) && $mapper->deleted($value)) { |
@@ -350,7 +349,7 @@ discard block |
||
| 350 | 349 | { |
| 351 | 350 | // BEG: ugly hack to get changed columns |
| 352 | 351 | $hack = []; |
| 353 | - foreach ((array)$entity as $k => $v) { |
|
| 352 | + foreach ((array) $entity as $k => $v) { |
|
| 354 | 353 | $hack[$k[0] === "\0" ? substr($k, strrpos($k, "\0", 1) + 1) : $k] = $v; |
| 355 | 354 | } |
| 356 | 355 | $hack = $hack['changed'] ?? []; |
@@ -646,7 +645,7 @@ discard block |
||
| 646 | 645 | } |
| 647 | 646 | } |
| 648 | 647 | } |
| 649 | - public function exists(array|object $entity): bool |
|
| 648 | + public function exists(array | object $entity): bool |
|
| 650 | 649 | { |
| 651 | 650 | if (is_array($entity)) { |
| 652 | 651 | $primary = []; |
@@ -660,7 +659,7 @@ discard block |
||
| 660 | 659 | return isset($this->objects[spl_object_hash($entity)]) && |
| 661 | 660 | $this->objects[spl_object_hash($entity)][5] === false; |
| 662 | 661 | } |
| 663 | - public function deleted(array|object $entity): bool |
|
| 662 | + public function deleted(array | object $entity): bool |
|
| 664 | 663 | { |
| 665 | 664 | if (is_array($entity)) { |
| 666 | 665 | $primary = []; |
@@ -746,7 +745,7 @@ discard block |
||
| 746 | 745 | return array_filter( |
| 747 | 746 | array_values( |
| 748 | 747 | array_map( |
| 749 | - function ($v) { |
|
| 748 | + function($v) { |
|
| 750 | 749 | return $v[5] ? null : ($v[1] ?? null); |
| 751 | 750 | }, |
| 752 | 751 | $this->objects |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | $this->cached[$method] = $rslt; |
| 98 | 98 | } else { |
| 99 | - throw new DBException('Invalid relation name: ' . $method); |
|
| 99 | + throw new DBException('Invalid relation name: '.$method); |
|
| 100 | 100 | } |
| 101 | 101 | return $this->cached[$method] ?? null; |
| 102 | 102 | } |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | protected function relatedQuery(string $name): TableQueryMapped |
| 108 | 108 | { |
| 109 | 109 | if (!array_key_exists($name, $this->relations)) { |
| 110 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 110 | + throw new DBException('Invalid relation name: '.$name); |
|
| 111 | 111 | } |
| 112 | 112 | return call_user_func_array($this->relations[$name], [$this, true]); |
| 113 | 113 | } |
| 114 | 114 | protected function relatedRow(string $name): mixed |
| 115 | 115 | { |
| 116 | 116 | if (!array_key_exists($name, $this->relations)) { |
| 117 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 117 | + throw new DBException('Invalid relation name: '.$name); |
|
| 118 | 118 | } |
| 119 | 119 | return call_user_func_array($this->relations[$name], [$this]); |
| 120 | 120 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | protected function relatedRows(string $name): Collection |
| 126 | 126 | { |
| 127 | 127 | if (!array_key_exists($name, $this->relations)) { |
| 128 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 128 | + throw new DBException('Invalid relation name: '.$name); |
|
| 129 | 129 | } |
| 130 | 130 | return call_user_func_array($this->relations[$name], [$this]); |
| 131 | 131 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $temp = $this->data; |
| 135 | 135 | foreach ($this->relations as $name => $relation) { |
| 136 | 136 | try { |
| 137 | - $temp[$name] = call_user_func_array($relation, [ $this, false, true ]); |
|
| 137 | + $temp[$name] = call_user_func_array($relation, [$this, false, true]); |
|
| 138 | 138 | } catch (DBException $ignore) {} |
| 139 | 139 | } |
| 140 | 140 | return $temp; |