Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from StyleCI #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
],
];
11 changes: 10 additions & 1 deletion src/Support/Facades/Format.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.
*/

namespace Jiannei\Response\Laravel\Support\Facades;

use Illuminate\Http\JsonResponse;
Expand All @@ -24,4 +33,4 @@ protected static function getFacadeAccessor()
{
return config('response.format.class', \Jiannei\Response\Laravel\Support\Format::class);
}
}
}
1 change: 0 additions & 1 deletion src/Support/Facades/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Support/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function jsonResource(JsonResource $resource, $transformer = null, $resou
{
$data = array_merge_recursive($resource->resolve(request()), $resource->with(request()), $resource->additional);

return fractal()->item($data, $transformer ?: fn() => $data, $resourceName)->serializeWith(ArraySerializer::class)->toArray();
return fractal()->item($data, $transformer ?: fn () => $data, $resourceName)->serializeWith(ArraySerializer::class)->toArray();
}

/**
Expand All @@ -136,7 +136,7 @@ public function jsonResource(JsonResource $resource, $transformer = null, $resou
*/
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;
}

Expand Down Expand Up @@ -213,7 +213,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;
}

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

if (!$show) {
if (! $show) {
$data = Arr::except($data, $key);
}
}
Expand Down
9 changes: 0 additions & 9 deletions src/Support/Traits/JsonResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@

namespace Jiannei\Response\Laravel\Support\Traits;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\AbstractCursorPaginator;
use Illuminate\Pagination\AbstractPaginator;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Config;
use Jiannei\Response\Laravel\Support\Facades\Format;

trait JsonResponseTrait
Expand Down Expand Up @@ -168,7 +160,6 @@ public function errorInternal(string $message = ''): void
* @param array $headers
* @param int $option
* @return JsonResponse
*
*/
public function fail(string $message = '', int $code = 500, $errors = null, array $headers = [], int $option = 0): JsonResponse
{
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
]);
}
}
Expand Down
Loading