From 88b7653f4915ea27c24b1f30d98041410edc9392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Be=C3=9Fler?= Date: Thu, 16 Jan 2025 14:38:33 +0100 Subject: [PATCH 1/2] Removed custom modelToArray function --- src/SimpleDTO.php | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/SimpleDTO.php b/src/SimpleDTO.php index 4f39567..ef5f4f8 100644 --- a/src/SimpleDTO.php +++ b/src/SimpleDTO.php @@ -482,7 +482,6 @@ private function formatArrayableValue(mixed $value): array|int|string $value instanceof UnitEnum => $value->name, $value instanceof Carbon || $value instanceof CarbonImmutable => $value->toISOString(true), $value instanceof Collection => $this->transformCollectionToArray($value), - $value instanceof Model => $this->transformModelToArray($value), $value instanceof SimpleDTO => $this->transformDTOToArray($value), $value instanceof Arrayable => $value->toArray(), is_object($value) => (array) $value, @@ -499,18 +498,6 @@ private function transformCollectionToArray(Collection $collection): array })->toArray(); } - private function transformModelToArray(Model $model): array - { - $result = []; - foreach ($model->getAttributes() as $key => $value) { - $result[$key] = $this->isArrayable($value) - ? $this->formatArrayableValue($value) - : $value; - } - - return $result; - } - private function transformDTOToArray(SimpleDTO $dto): array { $result = []; From 3a7c95dc2dfeba102b56b40c51965acf83eb779a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Be=C3=9Fler?= Date: Thu, 16 Jan 2025 14:42:49 +0100 Subject: [PATCH 2/2] Pint --- src/SimpleDTO.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/SimpleDTO.php b/src/SimpleDTO.php index ef5f4f8..ac43663 100644 --- a/src/SimpleDTO.php +++ b/src/SimpleDTO.php @@ -491,11 +491,9 @@ private function formatArrayableValue(mixed $value): array|int|string private function transformCollectionToArray(Collection $collection): array { - return $collection->map(function ($item) { - return $this->isArrayable($item) + return $collection->map(fn ($item) => $this->isArrayable($item) ? $this->formatArrayableValue($item) - : $item; - })->toArray(); + : $item)->toArray(); } private function transformDTOToArray(SimpleDTO $dto): array