Skip to content

Commit

Permalink
refactor: fix rector change on RedirectException (#9433)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan authored Jan 24, 2025
1 parent b18a406 commit b5e9715
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 13 additions & 7 deletions system/HTTP/Exceptions/RedirectException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
}
Expand Down
7 changes: 1 addition & 6 deletions utils/phpstan-baseline/ternary.shortNotAllowed.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 38 errors
# total 37 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b5e9715

Please sign in to comment.