From 10ba614d8a1088b8f012bb1d0a6bf8a672bc805d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Fri, 24 Jan 2025 23:32:38 +0800 Subject: [PATCH] refactor: fix rector change on RedirectException --- composer.json | 2 +- system/HTTP/Exceptions/RedirectException.php | 20 ++++++++++++------- .../ternary.shortNotAllowed.neon | 7 +------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index c762845f9a7e..a0e5f0b5d081 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpunit/phpcov": "^9.0.2 || ^10.0", "phpunit/phpunit": "^10.5.16 || ^11.2", "predis/predis": "^1.1 || ^2.3", - "rector/rector": "2.0.6", + "rector/rector": "2.0.7", "shipmonk/phpstan-baseline-per-identifier": "^2.0" }, "replace": { diff --git a/system/HTTP/Exceptions/RedirectException.php b/system/HTTP/Exceptions/RedirectException.php index 792ffe921d70..abb9be1e9e35 100644 --- a/system/HTTP/Exceptions/RedirectException.php +++ b/system/HTTP/Exceptions/RedirectException.php @@ -51,7 +51,8 @@ public function __construct($message = '', int $code = 0, ?Throwable $previous = if ($message instanceof ResponseInterface) { $this->response = $message; - $message = ''; + + $message = ''; if ($this->response->getHeaderLine('Location') === '' && $this->response->getHeaderLine('Refresh') === '') { throw new LogicException( @@ -70,14 +71,19 @@ public function __construct($message = '', int $code = 0, ?Throwable $previous = public function getResponse(): ResponseInterface { if (! $this->response instanceof ResponseInterface) { - $this->response = service('response') - ->redirect(base_url($this->getMessage()), 'auto', $this->getCode()); + $this->response = service('response')->redirect( + base_url($this->getMessage()), + 'auto', + $this->getCode(), + ); } - service('logger')->info( - 'REDIRECTED ROUTE at ' - . ($this->response->getHeaderLine('Location') ?: substr($this->response->getHeaderLine('Refresh'), 6)), - ); + $location = $this->response->getHeaderLine('Location'); + + service(('logger'))->info(sprintf( + 'REDIRECTED ROUTE at %s', + $location !== '' ? $location : substr($this->response->getHeaderLine('Refresh'), 6), + )); return $this->response; } diff --git a/utils/phpstan-baseline/ternary.shortNotAllowed.neon b/utils/phpstan-baseline/ternary.shortNotAllowed.neon index 59dca6cac690..8fbe74a182db 100644 --- a/utils/phpstan-baseline/ternary.shortNotAllowed.neon +++ b/utils/phpstan-baseline/ternary.shortNotAllowed.neon @@ -1,4 +1,4 @@ -# total 38 errors +# total 37 errors parameters: ignoreErrors: @@ -47,11 +47,6 @@ parameters: count: 1 path: ../../system/HTTP/CURLRequest.php - - - message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#' - count: 1 - path: ../../system/HTTP/Exceptions/RedirectException.php - - message: '#^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$#' count: 2