From 7b7d1c08d091873bdcf44e621f2f01dc9aa276a4 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Oct 2023 04:30:43 +0000 Subject: [PATCH] Apply fixes from StyleCI --- config/response.php | 4 ++-- src/Support/Format.php | 36 ++++++++++++++++++------------------ tests/TestCase.php | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config/response.php b/config/response.php index d255651..5ac5189 100644 --- a/config/response.php +++ b/config/response.php @@ -59,8 +59,8 @@ 'code' => ['alias' => 'code', 'show' => true], 'message' => ['alias' => 'message', 'show' => true], 'error' => ['alias' => 'error', 'show' => true], - 'data' => ['alias' => 'data', 'show' => true,], - 'data.data' => ['alias' => 'data.data', 'show' => true,],// rows/items/list + 'data' => ['alias' => 'data', 'show' => true], + 'data.data' => ['alias' => 'data.data', 'show' => true], // rows/items/list ], ], ]; diff --git a/src/Support/Format.php b/src/Support/Format.php index e9217b8..9c7e09e 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -74,17 +74,17 @@ public function format(?array $data, ?string $message, int $code, $errors = null */ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource) { - $fractal = fractal()->collection($resource, function ($item) { + $fractal = fractal()->collection($resource, function ($item) { return $item->toArray(); })->serializeWith(DataArraySerializer::class); return tap($fractal, function (Fractal $item) use ($resource) { if ($resource instanceof CursorPaginator) { return $item->withCursor(new Cursor( - $resource->cursor()?->encode(), - $resource->previousCursor()?->encode(), - $resource->nextCursor()?->encode(), - count($resource->items())) + $resource->cursor()?->encode(), + $resource->previousCursor()?->encode(), + $resource->nextCursor()?->encode(), + count($resource->items())) ); } @@ -100,8 +100,8 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource) 'current_page' => $resource->currentPage(), 'links' => [ 'previous' => $resource->previousPageUrl(), - 'next' => $resource->nextPageUrl() - ] + 'next' => $resource->nextPageUrl(), + ], ], ]); } @@ -118,17 +118,17 @@ public function paginator(AbstractPaginator|AbstractCursorPaginator $resource) */ public function resourceCollection(ResourceCollection $collection): array { - $fractal = fractal()->collection($collection->resource,function (JsonResource $resource){ + $fractal = fractal()->collection($collection->resource, function (JsonResource $resource) { return array_merge_recursive($resource->resolve(request()), $resource->with(request()), $resource->additional); })->serializeWith(DataArraySerializer::class); return tap($fractal, function (Fractal $item) use ($collection) { if ($collection->resource instanceof CursorPaginator) { return $item->withCursor(new Cursor( - $collection->resource->cursor()?->encode(), - $collection->resource->previousCursor()?->encode(), - $collection->resource->nextCursor()?->encode(), - count($collection->resource->items())) + $collection->resource->cursor()?->encode(), + $collection->resource->previousCursor()?->encode(), + $collection->resource->nextCursor()?->encode(), + count($collection->resource->items())) ); } @@ -144,8 +144,8 @@ public function resourceCollection(ResourceCollection $collection): array 'current_page' => $collection->resource->currentPage(), 'links' => [ 'previous' => $collection->resource->previousPageUrl(), - 'next' => $collection->resource->nextPageUrl() - ] + 'next' => $collection->resource->nextPageUrl(), + ], ], ]); } @@ -161,7 +161,7 @@ public function resourceCollection(ResourceCollection $collection): array */ public function jsonResource(JsonResource $resource) { - return fractal()->item($resource->resource,function (JsonResource $resource){ + return fractal()->item($resource->resource, function (JsonResource $resource) { return array_merge_recursive($resource->resolve(request()), $resource->with(request()), $resource->additional); })->serializeWith(ArraySerializer::class); } @@ -175,7 +175,7 @@ public function jsonResource(JsonResource $resource) */ 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; } @@ -224,7 +224,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; } @@ -237,7 +237,7 @@ protected function formatDataFields(array $data): array $key = $alias; } - if (!$show) { + if (! $show) { $data = Arr::except($data, $key); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 1c43831..730dbde 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -45,7 +45,7 @@ protected function defineEnvironment($app) $app['config']->set('response.enum', \Jiannei\Response\Laravel\Tests\Repositories\Enums\ResponseCodeEnum::class); if ($this instanceof FormatTest) { $app['config']->set('response.format', [ - 'class' => \Jiannei\Response\Laravel\Tests\Support\Format::class + 'class' => \Jiannei\Response\Laravel\Tests\Support\Format::class, ]); } }