diff --git a/config/response.php b/config/response.php index b571b63..ccad8ca 100644 --- a/config/response.php +++ b/config/response.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -33,7 +33,6 @@ 'code' => 422, ], \Illuminate\Auth\AuthenticationException::class => [ - ], \Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class => [ 'message' => '', diff --git a/src/Contract/ResponseFormat.php b/src/Contract/ResponseFormat.php index 3625c1f..7ed99ba 100644 --- a/src/Contract/ResponseFormat.php +++ b/src/Contract/ResponseFormat.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Http/Middleware/Etag.php b/src/Http/Middleware/Etag.php index 99e403d..5fa3115 100644 --- a/src/Http/Middleware/Etag.php +++ b/src/Http/Middleware/Etag.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -19,14 +19,15 @@ class Etag /** * Implement Etag support. * - * @param \Illuminate\Http\Request $request the HTTP request - * @param \Closure $next closure for the response + * @param \Illuminate\Http\Request $request the HTTP request + * @param \Closure $next closure for the response + * * @return mixed */ public function handle(Request $request, Closure $next) { // If this was not a get or head request, just return - if (! $request->isMethod('get') && ! $request->isMethod('head')) { + if (!$request->isMethod('get') && !$request->isMethod('head')) { return $next($request); } diff --git a/src/Http/Middleware/SetAcceptHeader.php b/src/Http/Middleware/SetAcceptHeader.php index 4c439a3..5cadebf 100644 --- a/src/Http/Middleware/SetAcceptHeader.php +++ b/src/Http/Middleware/SetAcceptHeader.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Http/Middleware/ThrottleRequests.php b/src/Http/Middleware/ThrottleRequests.php index f216cfb..11c18fa 100644 --- a/src/Http/Middleware/ThrottleRequests.php +++ b/src/Http/Middleware/ThrottleRequests.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -42,10 +42,11 @@ public function __construct(RateLimiter $limiter) /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param int|string $maxAttempts - * @param float|int $decayMinutes - * @param string $prefix + * @param \Illuminate\Http\Request $request + * @param int|string $maxAttempts + * @param float|int $decayMinutes + * @param string $prefix + * * @return \Symfony\Component\HttpFoundation\Response * * @throws \Illuminate\Http\Exceptions\ThrottleRequestsException @@ -73,8 +74,9 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes /** * Resolve the number of attempts if the user is authenticated or not. * - * @param \Illuminate\Http\Request $request - * @param int|string $maxAttempts + * @param \Illuminate\Http\Request $request + * @param int|string $maxAttempts + * * @return int */ protected function resolveMaxAttempts($request, $maxAttempts) @@ -83,7 +85,7 @@ protected function resolveMaxAttempts($request, $maxAttempts) $maxAttempts = explode('|', $maxAttempts, 2)[$request->user() ? 1 : 0]; } - if (! is_numeric($maxAttempts) && $request->user()) { + if (!is_numeric($maxAttempts) && $request->user()) { $maxAttempts = $request->user()->{$maxAttempts}; } @@ -93,7 +95,8 @@ protected function resolveMaxAttempts($request, $maxAttempts) /** * Resolve request signature. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request + * * @return string * * @throws \RuntimeException @@ -110,8 +113,9 @@ protected function resolveRequestSignature($request) /** * Create a 'too many attempts' exception. * - * @param string $key - * @param int $maxAttempts + * @param string $key + * @param int $maxAttempts + * * @return \Illuminate\Http\Exceptions\ThrottleRequestsException */ protected function buildException($key, $maxAttempts) @@ -132,7 +136,8 @@ protected function buildException($key, $maxAttempts) /** * Get the number of seconds until the next retry. * - * @param string $key + * @param string $key + * * @return int */ protected function getTimeUntilNextRetry($key) @@ -143,9 +148,10 @@ protected function getTimeUntilNextRetry($key) /** * Add the limit header information to the given response. * - * @param int $maxAttempts - * @param int $remainingAttempts - * @param int|null $retryAfter + * @param int $maxAttempts + * @param int $remainingAttempts + * @param int|null $retryAfter + * * @return \Symfony\Component\HttpFoundation\Response */ protected function addHeaders(Response $response, $maxAttempts, $remainingAttempts, $retryAfter = null) @@ -160,9 +166,10 @@ protected function addHeaders(Response $response, $maxAttempts, $remainingAttemp /** * Get the limit headers information. * - * @param int $maxAttempts - * @param int $remainingAttempts - * @param int|null $retryAfter + * @param int $maxAttempts + * @param int $remainingAttempts + * @param int|null $retryAfter + * * @return array */ protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = null) @@ -172,7 +179,7 @@ protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = nu 'X-RateLimit-Remaining' => $remainingAttempts, ]; - if (! is_null($retryAfter)) { + if (!is_null($retryAfter)) { $headers['Retry-After'] = $retryAfter; $headers['X-RateLimit-Reset'] = $this->availableAt($retryAfter); } @@ -183,9 +190,10 @@ protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = nu /** * Calculate the number of remaining attempts. * - * @param string $key - * @param int $maxAttempts - * @param int|null $retryAfter + * @param string $key + * @param int $maxAttempts + * @param int|null $retryAfter + * * @return int */ protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter = null) diff --git a/src/Providers/LaravelServiceProvider.php b/src/Providers/LaravelServiceProvider.php index 421d3b5..d7e2112 100644 --- a/src/Providers/LaravelServiceProvider.php +++ b/src/Providers/LaravelServiceProvider.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Providers/LumenServiceProvider.php b/src/Providers/LumenServiceProvider.php index a1c5048..72c1e65 100644 --- a/src/Providers/LumenServiceProvider.php +++ b/src/Providers/LumenServiceProvider.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Response.php b/src/Response.php index 91721a9..88017ca 100644 --- a/src/Response.php +++ b/src/Response.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Support/Facades/Format.php b/src/Support/Facades/Format.php index 41ea4ab..ab11c57 100644 --- a/src/Support/Facades/Format.php +++ b/src/Support/Facades/Format.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -21,11 +21,11 @@ /** * @method static \Jiannei\Response\Laravel\Support\Format data(mixed $data = null, string $message = '', int|\BackedEnum $code = 200, $error = null) - * @method static array|null get() - * @method static array paginator(AbstractPaginator|AbstractCursorPaginator|Paginator $resource) - * @method static array resourceCollection(ResourceCollection $collection) - * @method static array jsonResource(JsonResource $resource) - * @method static JsonResponse response() + * @method static array|null get() + * @method static array paginator(AbstractPaginator|AbstractCursorPaginator|Paginator $resource) + * @method static array resourceCollection(ResourceCollection $collection) + * @method static array jsonResource(JsonResource $resource) + * @method static JsonResponse response() * * @see \Jiannei\Response\Laravel\Support\Format */ diff --git a/src/Support/Facades/Response.php b/src/Support/Facades/Response.php index e75baf4..7056c9e 100644 --- a/src/Support/Facades/Response.php +++ b/src/Support/Facades/Response.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/src/Support/Format.php b/src/Support/Format.php index b9c5c83..211b012 100644 --- a/src/Support/Format.php +++ b/src/Support/Format.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -60,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 @@ -132,7 +133,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 }; } @@ -235,7 +236,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; } @@ -248,7 +249,7 @@ protected function formatDataFields(array $data): array $key = $alias; } - if (! $show) { + if (!$show) { $item = Arr::except($item, $key); } } diff --git a/src/Support/Traits/ExceptionTrait.php b/src/Support/Traits/ExceptionTrait.php index fe9a5d8..57db6be 100644 --- a/src/Support/Traits/ExceptionTrait.php +++ b/src/Support/Traits/ExceptionTrait.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -27,7 +27,8 @@ trait ExceptionTrait /** * Custom Normal Exception response. * - * @param Throwable|Exception $e + * @param Throwable|Exception $e + * * @return JsonResponse */ protected function prepareJsonResponse($request, $e) @@ -36,7 +37,7 @@ protected function prepareJsonResponse($request, $e) // 或者是 ajax 请求,header 中包含 X-Requested-With:XMLHttpRequest; $exceptionConfig = Config::get('response.exception.'.get_class($e)); - if ($exceptionConfig === false) { + if (false === $exceptionConfig) { return parent::prepareJsonResponse($request, $e); } @@ -78,14 +79,15 @@ protected function buildFailedValidationResponse(Request $request, array $errors /** * Custom Failed Validation Response for Laravel. * - * @param Request $request + * @param Request $request + * * @return JsonResponse */ protected function invalidJson($request, ValidationException $exception) { $exceptionConfig = Config::get('response.exception.'.ValidationException::class); - return $exceptionConfig !== false ? Response::fail( + return false !== $exceptionConfig ? Response::fail( $exception->validator->errors()->first(), Arr::get($exceptionConfig, 'code', 422), $exception->errors() @@ -95,14 +97,15 @@ protected function invalidJson($request, ValidationException $exception) /** * Custom Failed Authentication Response for Laravel. * - * @param Request $request - * @return \Illuminate\Http\RedirectResponse | JsonResponse + * @param Request $request + * + * @return \Illuminate\Http\RedirectResponse|JsonResponse */ protected function unauthenticated($request, AuthenticationException $exception) { $exceptionConfig = Config::get('response.exception.'.AuthenticationException::class); - return $exceptionConfig !== false && $request->expectsJson() + return false !== $exceptionConfig && $request->expectsJson() ? Response::errorUnauthorized($exceptionConfig['message'] ?? $exception->getMessage()) : parent::unauthenticated($request, $exception); } diff --git a/src/Support/Traits/JsonResponseTrait.php b/src/Support/Traits/JsonResponseTrait.php index 824112f..4ea29eb 100644 --- a/src/Support/Traits/JsonResponseTrait.php +++ b/src/Support/Traits/JsonResponseTrait.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -19,7 +19,7 @@ trait JsonResponseTrait /** * Respond with an accepted response and associate a location and/or content if provided. * - * @param array $data + * @param array $data */ public function accepted($data = [], string $message = '', string $location = ''): JsonResponse { @@ -33,7 +33,7 @@ public function accepted($data = [], string $message = '', string $location = '' /** * Respond with a created response and associate a location if provided. * - * @param null $data + * @param null $data */ public function created($data = [], string $message = '', string $location = ''): JsonResponse { @@ -112,7 +112,7 @@ public function errorMethodNotAllowed(string $message = ''): JsonResponse /** * Return an fail response. * - * @param null $errors + * @param null $errors */ public function fail(string $message = '', int|\BackedEnum $code = 500, $errors = null): JsonResponse { @@ -122,7 +122,8 @@ public function fail(string $message = '', int|\BackedEnum $code = 500, $errors /** * Return a success response. * - * @param mixed $data + * @param mixed $data + * * @return JsonResponse */ public function success($data = [], string $message = '', int|\BackedEnum $code = 200) diff --git a/tests/Enums/ResponseEnum.php b/tests/Enums/ResponseEnum.php index 72b9316..c196093 100644 --- a/tests/Enums/ResponseEnum.php +++ b/tests/Enums/ResponseEnum.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index bc7a86e..bbb01a6 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Models/User.php b/tests/Models/User.php index b0c5cd8..6b84e6e 100644 --- a/tests/Models/User.php +++ b/tests/Models/User.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Pest.php b/tests/Pest.php index 09758ae..9d870b2 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Resources/UserCollection.php b/tests/Resources/UserCollection.php index ed4ef45..d6b1a25 100644 --- a/tests/Resources/UserCollection.php +++ b/tests/Resources/UserCollection.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Resources/UserResource.php b/tests/Resources/UserResource.php index 5475afb..d6efcb3 100644 --- a/tests/Resources/UserResource.php +++ b/tests/Resources/UserResource.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Support/Format.php b/tests/Support/Format.php index 3180a4c..e1ff809 100644 --- a/tests/Support/Format.php +++ b/tests/Support/Format.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/TestCase.php b/tests/TestCase.php index f1440e9..0299167 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -51,7 +51,7 @@ protected function defineEnvironment($app) if ($this instanceof \P\Tests\Unit\CustomFormatTest) { $app['config']->set('response.format', [ - 'class' => \Jiannei\Response\Laravel\Tests\Support\Format::class, + 'class' => Support\Format::class, 'config' => [ // key => config 'status' => ['alias' => 'status', 'show' => false], diff --git a/tests/Unit/CustomFormatTest.php b/tests/Unit/CustomFormatTest.php index 9090636..2ad23c1 100644 --- a/tests/Unit/CustomFormatTest.php +++ b/tests/Unit/CustomFormatTest.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -20,7 +20,7 @@ ->and($response->getData(true)['extra'])->toHaveKey('time'); }); -/** +/* * 'class' => \Jiannei\Response\Laravel\Tests\Support\Format::class, * 'config' => [ * // key => config diff --git a/tests/Unit/FailTest.php b/tests/Unit/FailTest.php index ee54e3a..c00cc82 100644 --- a/tests/Unit/FailTest.php +++ b/tests/Unit/FailTest.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/Unit/SuccessTest.php b/tests/Unit/SuccessTest.php index a29fd27..31e685c 100644 --- a/tests/Unit/SuccessTest.php +++ b/tests/Unit/SuccessTest.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -199,7 +199,7 @@ }); test('success with message', function () { - //返回指定的 Message + // 返回指定的 Message $response = Response::success(message: '成功'); expect($response->status())->toEqual(200) diff --git a/tests/database/factories/UserFactory.php b/tests/database/factories/UserFactory.php index e866a74..54e9cc6 100644 --- a/tests/database/factories/UserFactory.php +++ b/tests/database/factories/UserFactory.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/database/migrations/2020_05_30_115810_create_users_table.php b/tests/database/migrations/2020_05_30_115810_create_users_table.php index 37e7bd2..0e4c25d 100644 --- a/tests/database/migrations/2020_05_30_115810_create_users_table.php +++ b/tests/database/migrations/2020_05_30_115810_create_users_table.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. diff --git a/tests/lang/zh_CN/enums.php b/tests/lang/zh_CN/enums.php index 3f5895e..294d12d 100644 --- a/tests/lang/zh_CN/enums.php +++ b/tests/lang/zh_CN/enums.php @@ -3,7 +3,7 @@ /* * This file is part of the jiannei/laravel-response. * - * (c) Jiannei + * (c) Jiannei * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE.