From d263b6b37569fc4b58a8cd288aa66621c9d28c64 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 11 Oct 2023 07:09:51 +0000 Subject: [PATCH] Apply fixes from StyleCI --- config/response.php | 4 ++-- src/Support/Facades/Format.php | 12 ++++++++++-- src/Support/Facades/Response.php | 1 - src/Support/Format.php | 8 ++++---- src/Support/Traits/JsonResponseTrait.php | 2 +- tests/TestCase.php | 4 +--- 6 files changed, 18 insertions(+), 13 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/Facades/Format.php b/src/Support/Facades/Format.php index 26031a9..a1cfb17 100644 --- a/src/Support/Facades/Format.php +++ b/src/Support/Facades/Format.php @@ -1,5 +1,14 @@ + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Jiannei\Response\Laravel\Support\Facades; use Illuminate\Http\JsonResponse; @@ -10,7 +19,6 @@ use Illuminate\Support\Facades\Facade as IlluminateFacade; /** - * * @method static JsonResponse response($data = [], int $status = 200, array $headers = [], int $options = 0) * @method static array data($data, ?string $message, int $code, $errors = null) * @method static array paginator(AbstractPaginator|AbstractCursorPaginator $resource) @@ -25,4 +33,4 @@ protected static function getFacadeAccessor() { return config('response.format.class', \Jiannei\Response\Laravel\Support\Format::class); } -} \ No newline at end of file +} diff --git a/src/Support/Facades/Response.php b/src/Support/Facades/Response.php index e4909b8..e24854b 100644 --- a/src/Support/Facades/Response.php +++ b/src/Support/Facades/Response.php @@ -12,7 +12,6 @@ namespace Jiannei\Response\Laravel\Support\Facades; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Support\Facades\Facade as IlluminateFacade; /** diff --git a/src/Support/Format.php b/src/Support/Format.php index 4656c9c..03fad7d 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -106,7 +106,7 @@ public function jsonResource(JsonResource $resource): array { $data = array_merge_recursive($resource->resolve(request()), $resource->with(request()), $resource->additional); - return fractal()->item($data, fn() => $data)->serializeWith(ArraySerializer::class)->toArray(); + return fractal()->item($data, fn () => $data)->serializeWith(ArraySerializer::class)->toArray(); } /** @@ -118,7 +118,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; } @@ -194,7 +194,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; } @@ -207,7 +207,7 @@ protected function formatDataFields(array $data): array $key = $alias; } - if (!$show) { + if (! $show) { $data = Arr::except($data, $key); } } diff --git a/src/Support/Traits/JsonResponseTrait.php b/src/Support/Traits/JsonResponseTrait.php index 631ada3..55b0e83 100644 --- a/src/Support/Traits/JsonResponseTrait.php +++ b/src/Support/Traits/JsonResponseTrait.php @@ -207,6 +207,6 @@ public function success($data = [], string $message = '', int $code = 200, array default => Arr::wrap($data) }; - return Format::response(Format::data($data,$message,$code), $code, $headers, $option); + return Format::response(Format::data($data, $message, $code), $code, $headers, $option); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index bf20a51..730dbde 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,8 +11,6 @@ namespace Jiannei\Response\Laravel\Tests; -use Jiannei\Response\Laravel\Tests\Support\Format; - abstract class TestCase extends \Orchestra\Testbench\TestCase { protected function getPackageProviders($app) @@ -47,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, ]); } }