diff --git a/src/Support/Format.php b/src/Support/Format.php index 1b39b98..2d0ed5f 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -34,7 +34,9 @@ class Format implements ResponseFormat protected int $statusCode = 200; - public function __construct(protected array $config = []) {} + public function __construct(protected array $config = []) + { + } /** * Return a new JSON response from the application. @@ -58,8 +60,9 @@ public function get(): ?array /** * Core format. * - * @param null $data - * @param null $error + * @param null $data + * @param null $error + * * @return Format */ public function data(mixed $data = null, string $message = '', int|\BackedEnum $code = 200, $error = null): static @@ -67,7 +70,6 @@ public function data(mixed $data = null, string $message = '', int|\BackedEnum $ return tap($this, function () use ($data, $message, $code, $error) { $bizCode = $this->formatBusinessCode($code); - $this->data = $this->formatDataFields([ 'status' => $this->formatStatus($bizCode), 'code' => $bizCode, @@ -133,7 +135,7 @@ protected function formatMessage(int $code, string $message = ''): ?string $localizationKey = implode('.', [Config::get('response.locale', 'enums'), $code]); return match (true) { - ! $message && Lang::has($localizationKey) => Lang::get($localizationKey), + !$message && Lang::has($localizationKey) => Lang::get($localizationKey), default => $message }; } @@ -238,7 +240,7 @@ protected function formatDataFields(array $data): array { return tap($data, function (&$item) { foreach ($this->config as $key => $config) { - if (! Arr::has($item, $key)) { + if (!Arr::has($item, $key)) { continue; } @@ -251,7 +253,7 @@ protected function formatDataFields(array $data): array $key = $alias; } - if (! $show) { + if (!$show) { $item = Arr::except($item, $key); } } diff --git a/tests/Unit/Fail200Test.php b/tests/Unit/Fail200Test.php index bfe8072..2da6319 100644 --- a/tests/Unit/Fail200Test.php +++ b/tests/Unit/Fail200Test.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. + */ + use Jiannei\Response\Laravel\Support\Facades\Response; test('fail with 200 status code', function () { @@ -13,4 +22,4 @@ 'data' => [], 'error' => [], ]); -}); \ No newline at end of file +}); diff --git a/tests/Unit/Fail500Test.php b/tests/Unit/Fail500Test.php index a84f017..79cab0c 100644 --- a/tests/Unit/Fail500Test.php +++ b/tests/Unit/Fail500Test.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. + */ + use Jiannei\Response\Laravel\Support\Facades\Response; test('fail with 500 status code', function () { @@ -13,4 +22,4 @@ 'data' => [], 'error' => [], ]); -}); \ No newline at end of file +});