Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Oct 30, 2024
1 parent eaabfec commit cc2a2c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/Support/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -58,16 +60,16 @@ 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
{
return tap($this, function () use ($data, $message, $code, $error) {
$bizCode = $this->formatBusinessCode($code);


$this->data = $this->formatDataFields([
'status' => $this->formatStatus($bizCode),
'code' => $bizCode,
Expand Down Expand Up @@ -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
};
}
Expand Down Expand Up @@ -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;
}

Expand All @@ -251,7 +253,7 @@ protected function formatDataFields(array $data): array
$key = $alias;
}

if (! $show) {
if (!$show) {
$item = Arr::except($item, $key);
}
}
Expand Down
11 changes: 10 additions & 1 deletion tests/Unit/Fail200Test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the jiannei/laravel-response.
*
* (c) Jiannei <[email protected]>
*
* 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 () {
Expand All @@ -13,4 +22,4 @@
'data' => [],
'error' => [],
]);
});
});
11 changes: 10 additions & 1 deletion tests/Unit/Fail500Test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of the jiannei/laravel-response.
*
* (c) Jiannei <[email protected]>
*
* 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 () {
Expand All @@ -13,4 +22,4 @@
'data' => [],
'error' => [],
]);
});
});

0 comments on commit cc2a2c3

Please sign in to comment.