From 5b3f210ee422b686640ea2b02ffb75f8e736f750 Mon Sep 17 00:00:00 2001 From: jiannei Date: Wed, 11 Oct 2023 20:54:21 +0800 Subject: [PATCH] fix: comment --- src/Support/Facades/Format.php | 6 +++--- src/Support/Format.php | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Support/Facades/Format.php b/src/Support/Facades/Format.php index 85c1764..aa41381 100644 --- a/src/Support/Facades/Format.php +++ b/src/Support/Facades/Format.php @@ -21,9 +21,9 @@ /** * @method static JsonResponse response($data = null, string $message = '', int $code = 200, $errors = null, array $headers = [], int $option = 0, string $from = 'success') * @method static array data($data, ?string $message, int $code, $errors = null) - * @method static array paginator(AbstractPaginator|AbstractCursorPaginator $resource, $transformer = null, $resourceName = null) - * @method static array resourceCollection(ResourceCollection $collection, $transformer = null, $resourceName = null) - * @method static array jsonResource(JsonResource $resource, $transformer = null, $resourceName = null) + * @method static array paginator(AbstractPaginator|AbstractCursorPaginator $resource) + * @method static array resourceCollection(ResourceCollection $collection) + * @method static array jsonResource(JsonResource $resource) * * @see \Jiannei\Response\Laravel\Support\Format */ diff --git a/src/Support/Format.php b/src/Support/Format.php index 789eafb..4353f4c 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -83,7 +83,7 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource): { return [ 'data' => $resource->toArray()['data'], - 'meta' => $this->formatMeta($resource), + 'meta' => $this->formatMeta($resource) ]; } @@ -96,8 +96,8 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource): public function resourceCollection(ResourceCollection $collection): array { return array_filter([ - 'data' => $collection->toArray(request()), - 'meta' => $this->formatMeta($collection->resource), + 'data' => $collection->resolve(), + 'meta' => $this->formatMeta($collection->resource) ]); } @@ -109,7 +109,7 @@ public function resourceCollection(ResourceCollection $collection): array */ public function jsonResource(JsonResource $resource): array { - return value($this->formatJsonResource(), $resource); + return value($this->formatJsonResource(),$resource); } /** @@ -121,7 +121,7 @@ public function jsonResource(JsonResource $resource): array */ protected function formatMessage(int $code, ?string $message): ?string { - if (! $message && class_exists($enumClass = Config::get('response.enum'))) { + if (!$message && class_exists($enumClass = Config::get('response.enum'))) { $message = $enumClass::fromValue($code)->description; } @@ -175,8 +175,9 @@ protected function formatJsonResource(): \Closure * Format paginator data. * * @param $collection + * @return array */ - protected function formatMeta($collection) + protected function formatMeta($collection): array { return match (true) { $collection instanceof CursorPaginator => [ @@ -185,7 +186,7 @@ protected function formatMeta($collection) 'prev' => $collection->previousCursor()?->encode(), 'next' => $collection->nextCursor()?->encode(), 'count' => count($collection->items()), - ], + ] ], $collection instanceof LengthAwarePaginator => [ 'pagination' => [ @@ -226,7 +227,7 @@ protected function formatDataFields(array $data): array $formatConfig = \config('response.format.config', []); foreach ($formatConfig as $key => $config) { - if (! Arr::has($data, $key)) { + if (!Arr::has($data, $key)) { continue; } @@ -239,7 +240,7 @@ protected function formatDataFields(array $data): array $key = $alias; } - if (! $show) { + if (!$show) { $data = Arr::except($data, $key); } }