From 5e6b85c772b576dbddb8a9258ecf8066c8221c4d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 8 Oct 2023 10:31:45 +0000 Subject: [PATCH] Apply fixes from StyleCI --- src/Exceptions/Handler.php | 26 ++++++++++++------------ tests/Feature/Exceptions/HandlerTest.php | 21 ++++++++++++------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 89a118a..51b465d 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -19,12 +19,12 @@ class Handler extends ExceptionHandler /** * Render an exception into an HTTP response. * - * @param Request $request - * @param Throwable $e + * @param Request $request + * @param Throwable $e * - * @return Response * @throws Throwable * + * @return Response */ public function render($request, Throwable $e) { @@ -33,12 +33,12 @@ public function render($request, Throwable $e) } return match (true) { - $e instanceof ValidationException => parent::render($request, $e), + $e instanceof ValidationException => parent::render($request, $e), $e instanceof AuthorizationException => self::throw($e, defaultErrorCode: 9998, responseCode: 403), - $e instanceof NotFoundHttpException => self::throw($e, 9997, 'Route not found!', 404), - $e instanceof QueryException => self::throw($e, 9996, $e->getPrevious()->getMessage(), 500), + $e instanceof NotFoundHttpException => self::throw($e, 9997, 'Route not found!', 404), + $e instanceof QueryException => self::throw($e, 9996, $e->getPrevious()->getMessage(), 500), $e instanceof ModelNotFoundException => self::throw($e, 9995, $e->getMessage(), 404), - $e instanceof HttpException => $request->wantsJson() ? + $e instanceof HttpException => $request->wantsJson() ? self::throw($e, defaultErrorCode: 9994) : parent::render($request, $e), default => self::throw($e) @@ -48,10 +48,10 @@ public function render($request, Throwable $e) /** * Convert the given exception to the ValravnException class. * - * @param Throwable $e - * @param int $defaultErrorCode - * @param string|null $message - * @param int|null $responseCode + * @param Throwable $e + * @param int $defaultErrorCode + * @param string|null $message + * @param int|null $responseCode * * @return JsonResponse */ @@ -66,9 +66,9 @@ private static function throw(Throwable $e, int $defaultErrorCode = 9999, string } return ValravnException::make( - $message ? : $e->getMessage(), + $message ?: $e->getMessage(), $errorCode, - $responseCode ? : $e->getCode() + $responseCode ?: $e->getCode() ) ->render(); } diff --git a/tests/Feature/Exceptions/HandlerTest.php b/tests/Feature/Exceptions/HandlerTest.php index e61e258..9543ba0 100644 --- a/tests/Feature/Exceptions/HandlerTest.php +++ b/tests/Feature/Exceptions/HandlerTest.php @@ -29,8 +29,9 @@ protected function setUp(): void /** * @test * - * @return void * @throws Throwable + * + * @return void */ public function rawErrorEnv(): void { @@ -53,8 +54,9 @@ public function rawErrorEnv(): void /** * @test * - * @return void * @throws Throwable + * + * @return void */ public function HttpExceptionMatchExpressionTest(): void { @@ -77,10 +79,12 @@ public function HttpExceptionMatchExpressionTest(): void /** * @test * - * @return void * @throws Throwable + * + * @return void */ - public function getErrorCodeFromErrorInstance(): void { + public function getErrorCodeFromErrorInstance(): void + { $e = ValravnException::make('test exception.', 27); self::assertJsonStringEqualsJsonString( @@ -88,13 +92,16 @@ public function getErrorCodeFromErrorInstance(): void { $this->handler->render(request(), $e)->content() ); } + /** * @test * - * @return void * @throws Throwable + * + * @return void */ - public function getCodeFromErrorInstance(): void { + public function getCodeFromErrorInstance(): void + { $e = new NotFoundHttpException(code: 4040); self::assertJsonStringEqualsJsonString( @@ -106,4 +113,4 @@ public function getCodeFromErrorInstance(): void { $this->handler->render(request(), $e)->getOriginalContent()['code'] ); } -} \ No newline at end of file +}