Skip to content

Commit d8dbf73

Browse files
committed
Apply fixes from StyleCI
1 parent 57dba89 commit d8dbf73

File tree

6 files changed

+61
-45
lines changed

6 files changed

+61
-45
lines changed

src/Http/Middleware/Etag.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ class Etag
1919
/**
2020
* Implement Etag support.
2121
*
22-
* @param \Illuminate\Http\Request $request the HTTP request
23-
* @param \Closure $next closure for the response
22+
* @param \Illuminate\Http\Request $request the HTTP request
23+
* @param \Closure $next closure for the response
24+
*
2425
* @return mixed
2526
*/
2627
public function handle(Request $request, Closure $next)
2728
{
2829
// If this was not a get or head request, just return
29-
if (! $request->isMethod('get') && ! $request->isMethod('head')) {
30+
if (!$request->isMethod('get') && !$request->isMethod('head')) {
3031
return $next($request);
3132
}
3233

src/Http/Middleware/ThrottleRequests.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ public function __construct(RateLimiter $limiter)
4242
/**
4343
* Handle an incoming request.
4444
*
45-
* @param \Illuminate\Http\Request $request
46-
* @param int|string $maxAttempts
47-
* @param float|int $decayMinutes
48-
* @param string $prefix
45+
* @param \Illuminate\Http\Request $request
46+
* @param int|string $maxAttempts
47+
* @param float|int $decayMinutes
48+
* @param string $prefix
49+
*
4950
* @return \Symfony\Component\HttpFoundation\Response
5051
*
5152
* @throws \Illuminate\Http\Exceptions\ThrottleRequestsException
@@ -73,8 +74,9 @@ public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes
7374
/**
7475
* Resolve the number of attempts if the user is authenticated or not.
7576
*
76-
* @param \Illuminate\Http\Request $request
77-
* @param int|string $maxAttempts
77+
* @param \Illuminate\Http\Request $request
78+
* @param int|string $maxAttempts
79+
*
7880
* @return int
7981
*/
8082
protected function resolveMaxAttempts($request, $maxAttempts)
@@ -83,7 +85,7 @@ protected function resolveMaxAttempts($request, $maxAttempts)
8385
$maxAttempts = explode('|', $maxAttempts, 2)[$request->user() ? 1 : 0];
8486
}
8587

86-
if (! is_numeric($maxAttempts) && $request->user()) {
88+
if (!is_numeric($maxAttempts) && $request->user()) {
8789
$maxAttempts = $request->user()->{$maxAttempts};
8890
}
8991

@@ -93,7 +95,8 @@ protected function resolveMaxAttempts($request, $maxAttempts)
9395
/**
9496
* Resolve request signature.
9597
*
96-
* @param \Illuminate\Http\Request $request
98+
* @param \Illuminate\Http\Request $request
99+
*
97100
* @return string
98101
*
99102
* @throws \RuntimeException
@@ -110,8 +113,9 @@ protected function resolveRequestSignature($request)
110113
/**
111114
* Create a 'too many attempts' exception.
112115
*
113-
* @param string $key
114-
* @param int $maxAttempts
116+
* @param string $key
117+
* @param int $maxAttempts
118+
*
115119
* @return \Illuminate\Http\Exceptions\ThrottleRequestsException
116120
*/
117121
protected function buildException($key, $maxAttempts)
@@ -132,7 +136,8 @@ protected function buildException($key, $maxAttempts)
132136
/**
133137
* Get the number of seconds until the next retry.
134138
*
135-
* @param string $key
139+
* @param string $key
140+
*
136141
* @return int
137142
*/
138143
protected function getTimeUntilNextRetry($key)
@@ -143,9 +148,10 @@ protected function getTimeUntilNextRetry($key)
143148
/**
144149
* Add the limit header information to the given response.
145150
*
146-
* @param int $maxAttempts
147-
* @param int $remainingAttempts
148-
* @param int|null $retryAfter
151+
* @param int $maxAttempts
152+
* @param int $remainingAttempts
153+
* @param int|null $retryAfter
154+
*
149155
* @return \Symfony\Component\HttpFoundation\Response
150156
*/
151157
protected function addHeaders(Response $response, $maxAttempts, $remainingAttempts, $retryAfter = null)
@@ -160,9 +166,10 @@ protected function addHeaders(Response $response, $maxAttempts, $remainingAttemp
160166
/**
161167
* Get the limit headers information.
162168
*
163-
* @param int $maxAttempts
164-
* @param int $remainingAttempts
165-
* @param int|null $retryAfter
169+
* @param int $maxAttempts
170+
* @param int $remainingAttempts
171+
* @param int|null $retryAfter
172+
*
166173
* @return array
167174
*/
168175
protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = null)
@@ -172,7 +179,7 @@ protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = nu
172179
'X-RateLimit-Remaining' => $remainingAttempts,
173180
];
174181

175-
if (! is_null($retryAfter)) {
182+
if (!is_null($retryAfter)) {
176183
$headers['Retry-After'] = $retryAfter;
177184
$headers['X-RateLimit-Reset'] = $this->availableAt($retryAfter);
178185
}
@@ -183,9 +190,10 @@ protected function getHeaders($maxAttempts, $remainingAttempts, $retryAfter = nu
183190
/**
184191
* Calculate the number of remaining attempts.
185192
*
186-
* @param string $key
187-
* @param int $maxAttempts
188-
* @param int|null $retryAfter
193+
* @param string $key
194+
* @param int $maxAttempts
195+
* @param int|null $retryAfter
196+
*
189197
* @return int
190198
*/
191199
protected function calculateRemainingAttempts($key, $maxAttempts, $retryAfter = null)

src/Support/Facades/Format.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
/**
2323
* @method static \Jiannei\Response\Laravel\Support\Format data(mixed $data = null, string $message = '', int|\BackedEnum $code = 200, $error = null)
24-
* @method static array|null get()
25-
* @method static array paginator(AbstractPaginator|AbstractCursorPaginator|Paginator $resource)
26-
* @method static array resourceCollection(ResourceCollection $collection)
27-
* @method static array jsonResource(JsonResource $resource)
28-
* @method static JsonResponse response()
24+
* @method static array|null get()
25+
* @method static array paginator(AbstractPaginator|AbstractCursorPaginator|Paginator $resource)
26+
* @method static array resourceCollection(ResourceCollection $collection)
27+
* @method static array jsonResource(JsonResource $resource)
28+
* @method static JsonResponse response()
2929
*
3030
* @see \Jiannei\Response\Laravel\Support\Format
3131
*/

src/Support/Format.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class Format implements ResponseFormat
3434

3535
protected int $statusCode = 200;
3636

37-
public function __construct(protected array $config = []) {}
37+
public function __construct(protected array $config = [])
38+
{
39+
}
3840

3941
/**
4042
* Return a new JSON response from the application.
@@ -58,8 +60,9 @@ public function get(): ?array
5860
/**
5961
* Core format.
6062
*
61-
* @param null $data
62-
* @param null $error
63+
* @param null $data
64+
* @param null $error
65+
*
6366
* @return Format
6467
*/
6568
public function data(mixed $data = null, string $message = '', int|\BackedEnum $code = 200, $error = null): static
@@ -132,7 +135,7 @@ protected function formatMessage(int $code, string $message = ''): ?string
132135
$localizationKey = implode('.', [Config::get('response.locale', 'enums'), $code]);
133136

134137
return match (true) {
135-
! $message && Lang::has($localizationKey) => Lang::get($localizationKey),
138+
!$message && Lang::has($localizationKey) => Lang::get($localizationKey),
136139
default => $message
137140
};
138141
}
@@ -237,7 +240,7 @@ protected function formatDataFields(array $data): array
237240
{
238241
return tap($data, function (&$item) {
239242
foreach ($this->config as $key => $config) {
240-
if (! Arr::has($item, $key)) {
243+
if (!Arr::has($item, $key)) {
241244
continue;
242245
}
243246

@@ -250,7 +253,7 @@ protected function formatDataFields(array $data): array
250253
$key = $alias;
251254
}
252255

253-
if (! $show) {
256+
if (!$show) {
254257
$item = Arr::except($item, $key);
255258
}
256259
}

src/Support/Traits/ExceptionTrait.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ trait ExceptionTrait
2727
/**
2828
* Custom Normal Exception response.
2929
*
30-
* @param Throwable|Exception $e
30+
* @param Throwable|Exception $e
31+
*
3132
* @return JsonResponse
3233
*/
3334
protected function prepareJsonResponse($request, $e)
@@ -36,7 +37,7 @@ protected function prepareJsonResponse($request, $e)
3637
// 或者是 ajax 请求,header 中包含 X-Requested-With:XMLHttpRequest;
3738
$exceptionConfig = Config::get('response.exception.'.get_class($e));
3839

39-
if ($exceptionConfig === false) {
40+
if (false === $exceptionConfig) {
4041
return parent::prepareJsonResponse($request, $e);
4142
}
4243

@@ -78,14 +79,15 @@ protected function buildFailedValidationResponse(Request $request, array $errors
7879
/**
7980
* Custom Failed Validation Response for Laravel.
8081
*
81-
* @param Request $request
82+
* @param Request $request
83+
*
8284
* @return JsonResponse
8385
*/
8486
protected function invalidJson($request, ValidationException $exception)
8587
{
8688
$exceptionConfig = Config::get('response.exception.'.ValidationException::class);
8789

88-
return $exceptionConfig !== false ? Response::fail(
90+
return false !== $exceptionConfig ? Response::fail(
8991
$exception->validator->errors()->first(),
9092
Arr::get($exceptionConfig, 'code', 422),
9193
$exception->errors()
@@ -95,14 +97,15 @@ protected function invalidJson($request, ValidationException $exception)
9597
/**
9698
* Custom Failed Authentication Response for Laravel.
9799
*
98-
* @param Request $request
100+
* @param Request $request
101+
*
99102
* @return \Illuminate\Http\RedirectResponse|JsonResponse
100103
*/
101104
protected function unauthenticated($request, AuthenticationException $exception)
102105
{
103106
$exceptionConfig = Config::get('response.exception.'.AuthenticationException::class);
104107

105-
return $exceptionConfig !== false && $request->expectsJson()
108+
return false !== $exceptionConfig && $request->expectsJson()
106109
? Response::errorUnauthorized($exceptionConfig['message'] ?? $exception->getMessage())
107110
: parent::unauthenticated($request, $exception);
108111
}

src/Support/Traits/JsonResponseTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait JsonResponseTrait
1919
/**
2020
* Respond with an accepted response and associate a location and/or content if provided.
2121
*
22-
* @param array $data
22+
* @param array $data
2323
*/
2424
public function accepted($data = [], string $message = '', string $location = ''): JsonResponse
2525
{
@@ -33,7 +33,7 @@ public function accepted($data = [], string $message = '', string $location = ''
3333
/**
3434
* Respond with a created response and associate a location if provided.
3535
*
36-
* @param null $data
36+
* @param null $data
3737
*/
3838
public function created($data = [], string $message = '', string $location = ''): JsonResponse
3939
{
@@ -112,7 +112,7 @@ public function errorMethodNotAllowed(string $message = ''): JsonResponse
112112
/**
113113
* Return an fail response.
114114
*
115-
* @param null $errors
115+
* @param null $errors
116116
*/
117117
public function fail(string $message = '', int|\BackedEnum $code = 500, $errors = null): JsonResponse
118118
{
@@ -122,7 +122,8 @@ public function fail(string $message = '', int|\BackedEnum $code = 500, $errors
122122
/**
123123
* Return a success response.
124124
*
125-
* @param mixed $data
125+
* @param mixed $data
126+
*
126127
* @return JsonResponse
127128
*/
128129
public function success($data = [], string $message = '', int|\BackedEnum $code = 200)

0 commit comments

Comments
 (0)