Skip to content
This repository was archived by the owner on Feb 14, 2023. It is now read-only.

Commit bfbf4d9

Browse files
committed
Codestyle fix
1 parent c5bedcf commit bfbf4d9

File tree

18 files changed

+78
-42
lines changed

18 files changed

+78
-42
lines changed

src/Concerns/Errors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function isError(bool $ignore_status_code = false): bool
3838
}
3939
}
4040

41-
protected function isErrorCode(int $code = null): bool
41+
protected function isErrorCode(?int $code = null): bool
4242
{
4343
return $code === 0 || $code >= 400;
4444
}

src/Exceptions/Laravel/BaseHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function with(): array
7777
return [];
7878
}
7979

80-
protected function response($data, int $status_code = null, array $with = [], array $headers = []): JsonResponse
80+
protected function response($data, ?int $status_code = null, array $with = [], array $headers = []): JsonResponse
8181
{
8282
$with = array_merge($this->with(), $with);
8383

src/Exceptions/Laravel/Eight/ApiHandler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function render($request, Throwable $e)
3636
return $this->response(
3737
Router::toResponse($request, $response)
3838
);
39-
} elseif ($e instanceof Responsable) {
39+
}
40+
41+
if ($e instanceof Responsable) {
4042
return $this->response($e->toResponse($request));
4143
}
4244

@@ -54,9 +56,13 @@ public function render($request, Throwable $e)
5456

5557
if ($e instanceof HttpResponseException) {
5658
return $this->response($e);
57-
} elseif ($e instanceof AuthenticationException) {
59+
}
60+
61+
if ($e instanceof AuthenticationException) {
5862
return $this->response($e, 403);
59-
} elseif ($e instanceof ValidationException) {
63+
}
64+
65+
if ($e instanceof ValidationException) {
6066
return $this->convertValidationExceptionToResponse($e, $request);
6167
}
6268

src/Exceptions/Laravel/Eight/Handler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public function render($request, Throwable $e)
3434
{
3535
if (method_exists($e, 'render') && $response = $e->render($request)) {
3636
return Router::toResponse($request, $response);
37-
} elseif ($e instanceof Responsable) {
37+
}
38+
39+
if ($e instanceof Responsable) {
3840
return $e->toResponse($request);
3941
}
4042

@@ -52,9 +54,13 @@ public function render($request, Throwable $e)
5254

5355
if ($e instanceof HttpResponseException) {
5456
return $e->getResponse();
55-
} elseif ($e instanceof AuthenticationException) {
57+
}
58+
59+
if ($e instanceof AuthenticationException) {
5660
return $this->unauthenticated($request, $e);
57-
} elseif ($e instanceof ValidationException) {
61+
}
62+
63+
if ($e instanceof ValidationException) {
5864
return $this->convertValidationExceptionToResponse($e, $request);
5965
}
6066

src/Exceptions/Laravel/Nine/ApiHandler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ public function render($request, Throwable $e)
3636
return $this->response(
3737
Router::toResponse($request, $response)
3838
);
39-
} elseif ($e instanceof Responsable) {
39+
}
40+
41+
if ($e instanceof Responsable) {
4042
return $this->response($e->toResponse($request));
4143
}
4244

@@ -54,9 +56,13 @@ public function render($request, Throwable $e)
5456

5557
if ($e instanceof HttpResponseException) {
5658
return $this->response($e);
57-
} elseif ($e instanceof AuthenticationException) {
59+
}
60+
61+
if ($e instanceof AuthenticationException) {
5862
return $this->response($e, 403);
59-
} elseif ($e instanceof ValidationException) {
63+
}
64+
65+
if ($e instanceof ValidationException) {
6066
return $this->convertValidationExceptionToResponse($e, $request);
6167
}
6268

src/Exceptions/Laravel/Nine/Handler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public function render($request, Throwable $e)
3434
{
3535
if (method_exists($e, 'render') && $response = $e->render($request)) {
3636
return Router::toResponse($request, $response);
37-
} elseif ($e instanceof Responsable) {
37+
}
38+
39+
if ($e instanceof Responsable) {
3840
return $e->toResponse($request);
3941
}
4042

@@ -52,9 +54,13 @@ public function render($request, Throwable $e)
5254

5355
if ($e instanceof HttpResponseException) {
5456
return $e->getResponse();
55-
} elseif ($e instanceof AuthenticationException) {
57+
}
58+
59+
if ($e instanceof AuthenticationException) {
5660
return $this->unauthenticated($request, $e);
57-
} elseif ($e instanceof ValidationException) {
61+
}
62+
63+
if ($e instanceof ValidationException) {
5864
return $this->convertValidationExceptionToResponse($e, $request);
5965
}
6066

src/Exceptions/Laravel/Seven/ApiHandler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,23 @@ public function render($request, Throwable $e)
3636
return $this->response(
3737
Router::toResponse($request, $response)
3838
);
39-
} elseif ($e instanceof Responsable) {
39+
}
40+
41+
if ($e instanceof Responsable) {
4042
return $this->response($e->toResponse($request));
4143
}
4244

4345
$e = $this->prepareException($e);
4446

4547
if ($e instanceof HttpResponseException) {
4648
return $this->response($e);
47-
} elseif ($e instanceof AuthenticationException) {
49+
}
50+
51+
if ($e instanceof AuthenticationException) {
4852
return $this->response($e, 403);
49-
} elseif ($e instanceof ValidationException) {
53+
}
54+
55+
if ($e instanceof ValidationException) {
5056
return $this->convertValidationExceptionToResponse($e, $request);
5157
}
5258

src/Exceptions/Laravel/Seven/Handler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,23 @@ public function render($request, Throwable $e)
3434
{
3535
if (method_exists($e, 'render') && $response = $e->render($request)) {
3636
return Router::toResponse($request, $response);
37-
} elseif ($e instanceof Responsable) {
37+
}
38+
39+
if ($e instanceof Responsable) {
3840
return $e->toResponse($request);
3941
}
4042

4143
$e = $this->prepareException($e);
4244

4345
if ($e instanceof HttpResponseException) {
4446
return $e->getResponse();
45-
} elseif ($e instanceof AuthenticationException) {
47+
}
48+
49+
if ($e instanceof AuthenticationException) {
4650
return $this->unauthenticated($request, $e);
47-
} elseif ($e instanceof ValidationException) {
51+
}
52+
53+
if ($e instanceof ValidationException) {
4854
return $this->convertValidationExceptionToResponse($e, $request);
4955
}
5056

src/Parsers/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Throwable;
2424

2525
/**
26-
* @property \Exception|\Throwable $data
26+
* @property \Exception|Throwable $data
2727
*/
2828
class Exception extends Parser
2929
{

src/Parsers/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getStatusCode(): int
5353
: ($this->status_code ?: 200);
5454
}
5555

56-
public function setStatusCode(int $code = null): Parseable
56+
public function setStatusCode(?int $code = null): Parseable
5757
{
5858
$this->status_code = $code;
5959

src/Services/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function headers(array $headers = []): Responsable
9292
return $this;
9393
}
9494

95-
public function statusCode(int $code = null): Responsable
95+
public function statusCode(?int $code = null): Responsable
9696
{
9797
$this->status_code = $code;
9898

@@ -139,7 +139,7 @@ protected function getWrapped(Parseable $parser)
139139
}
140140

141141
/**
142-
* @param \DragonCode\Contracts\ApiResponse\Parseable $parser
142+
* @param \DragonCode\Contracts\ApiResponse\Parseable $parser
143143
*
144144
* @return \DragonCode\ApiResponse\Wrappers\Wrapper|string
145145
*/

src/Support/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function setWith(array $with = []): self
7474
return $this;
7575
}
7676

77-
public function setStatusCode(int $status = null): self
77+
public function setStatusCode(?int $status = null): self
7878
{
7979
$this->status_code = $status;
8080

src/Wrappers/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function resolveData()
4242
}
4343

4444
/**
45-
* @param mixed $message
45+
* @param mixed $message
4646
*
4747
* @return array|int|string|null
4848
*/

src/helpers.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
/**
2222
* Return a new response from the application.
2323
*
24-
* @param mixed|null $data Any value to be returned.
25-
* @param int|null $status_code Will be detected automatically (200 or 400). If specified, this value will take precedence.
26-
* @param array $with Any additional value added to the response.
27-
* @param array $headers Additional headers passed with the response.
24+
* @param mixed|null $data any value to be returned
25+
* @param int|null $status_code Will be detected automatically (200 or 400). If specified, this value will take precedence.
26+
* @param array $with any additional value added to the response
27+
* @param array $headers additional headers passed with the response
2828
*
2929
* @return Symfony\Component\HttpFoundation\JsonResponse
3030
*/
3131
function api_response(
3232
$data = null,
33-
int $status_code = null,
33+
?int $status_code = null,
3434
array $with = [],
3535
array $headers = []
3636
): JsonResponse {

tests/Fixtures/Concerns/Resoursable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ protected function failedResource(): Failed
4646
return Failed::make($this->laravelModel());
4747
}
4848

49-
protected function successResourceResponse(int $status_code = null): Response
49+
protected function successResourceResponse(?int $status_code = null): Response
5050
{
5151
return $this->response($this->successResource(), $status_code);
5252
}
5353

54-
protected function createdResourceResponse(int $status_code = null): Response
54+
protected function createdResourceResponse(?int $status_code = null): Response
5555
{
5656
return $this->response($this->createdResource(), $status_code);
5757
}
5858

59-
protected function failedResourceResponse(int $status_code = null): Response
59+
protected function failedResourceResponse(?int $status_code = null): Response
6060
{
6161
return $this->response($this->failedResource(), $status_code);
6262
}

tests/Fixtures/Concerns/Responsable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/** @mixin \Tests\Laravel\TestCase */
2323
trait Responsable
2424
{
25-
protected function response($data = null, int $status_code = null, array $with = []): Response
25+
protected function response($data = null, ?int $status_code = null, array $with = []): Response
2626
{
2727
return new Response($data, $status_code, $with);
2828
}

tests/Fixtures/Concerns/Validationable.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
trait Validationable
2727
{
2828
/**
29-
* @param array $data
30-
* @param int|null $status_code
29+
* @param array $data
30+
* @param int|null $status_code
3131
*
3232
* @throws \Illuminate\Validation\ValidationException
3333
*
3434
* @return \Tests\Fixtures\Entities\Response
3535
*/
36-
protected function validationResponse(array $data, int $status_code = null): Response
36+
protected function validationResponse(array $data, ?int $status_code = null): Response
3737
{
3838
return $this->response(
3939
$this->validateException($data),
@@ -42,7 +42,7 @@ protected function validationResponse(array $data, int $status_code = null): Res
4242
}
4343

4444
/**
45-
* @param array $data
45+
* @param array $data
4646
*
4747
* @return \Illuminate\Contracts\Validation\Validator
4848
*/
@@ -56,7 +56,7 @@ protected function validation(array $data): ValidatorContract
5656
}
5757

5858
/**
59-
* @param array $data
59+
* @param array $data
6060
*
6161
* @throws \Illuminate\Validation\ValidationException
6262
*

tests/Fixtures/Entities/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Response
2727
/** @var \Symfony\Component\HttpFoundation\JsonResponse */
2828
protected $response;
2929

30-
public function __construct($data = null, int $status_code = null, array $with = [], array $headers = [])
30+
public function __construct($data = null, ?int $status_code = null, array $with = [], array $headers = [])
3131
{
3232
$this->response = $this->parseResponse($data, $status_code, $with, $headers);
3333
}
@@ -52,7 +52,7 @@ public function instance(): JsonResponse
5252
return $this->response;
5353
}
5454

55-
protected function parseResponse($data = null, int $status_code = null, array $with = [], array $headers = [])
55+
protected function parseResponse($data = null, ?int $status_code = null, array $with = [], array $headers = [])
5656
{
5757
if (Instance::of($data, [JsonResponse::class, MainResponse::class, TestResponse::class])) {
5858
return $data;

0 commit comments

Comments
 (0)