From 375afba6446d247fa4a979975afdf3566a1f55c9 Mon Sep 17 00:00:00 2001 From: jiannei Date: Sat, 14 Oct 2023 10:33:41 +0800 Subject: [PATCH] perf: data format --- src/Support/Format.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Support/Format.php b/src/Support/Format.php index 97e42dc..825e06e 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -126,15 +126,14 @@ public function jsonResource(JsonResource $resource): array */ protected function formatData($data): array|object { - $formattedData = match (true) { + return match (true) { $data instanceof ResourceCollection => $this->resourceCollection($data), $data instanceof JsonResource => $this->jsonResource($data), $data instanceof AbstractPaginator || $data instanceof AbstractCursorPaginator => $this->paginator($data), $data instanceof Arrayable || (is_object($data) && method_exists($data, 'toArray')) => $data->toArray(), + empty($data) => (object) $data, default => Arr::wrap($data) }; - - return $formattedData ?: (object) $data; } /**