Skip to content

Commit

Permalink
perf: data format
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Oct 14, 2023
1 parent 0ad1762 commit 375afba
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Support/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 375afba

Please sign in to comment.