Skip to content

Commit 7a64888

Browse files
committed
refactor: do not override Exception's $code in RedirectException
1 parent 4fcc5ff commit 7a64888

3 files changed

Lines changed: 6 additions & 7 deletions

File tree

system/HTTP/Exceptions/RedirectException.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
class RedirectException extends RuntimeException implements ExceptionInterface, ResponsableInterface, HTTPExceptionInterface
2828
{
2929
/**
30-
* HTTP status code for redirects
31-
*
32-
* @var int
30+
* Status code applied to a Response that arrives without a 3xx redirect status.
3331
*/
34-
protected $code = 302;
32+
protected int $defaultStatusCode = 302;
3533

3634
protected ?ResponseInterface $response = null;
3735

@@ -61,7 +59,7 @@ public function __construct($message = '', int $code = 0, ?Throwable $previous =
6159
}
6260

6361
if ($this->response->getStatusCode() < 301 || $this->response->getStatusCode() > 308) {
64-
$this->response->setStatusCode($this->code);
62+
$this->response->setStatusCode($this->defaultStatusCode);
6563
}
6664
}
6765

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Behavior Changes
4242
- **Filters:** HTTP method matching for method-based filters is now case-sensitive. The keys in ``Config\Filters::$methods`` must exactly match the request method
4343
(e.g., ``GET``, ``POST``). Lowercase method names (e.g., ``post``) will no longer match.
4444
- **HTTP:** Routes defined with ``$routes->add()`` now also match HTTP ``QUERY`` requests. If the route has CSRF protection, remember that CSRF verification does not protect safe methods such as ``GET`` and ``QUERY``.
45+
- **HTTP:** ``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property. The status applied to a ``Response`` passed to the constructor without a 3xx status now comes from the new ``protected int $defaultStatusCode = 302`` property. Subclasses that overrode ``$code`` to change that status must override ``$defaultStatusCode`` instead.
4546
- **Testing:** Tests using the ``FeatureTestTrait`` must now use uppercase HTTP method names when performing a request when using the ``call()`` method directly
4647
(e.g., ``$this->call('GET', '/path')`` instead of ``$this->call('get', '/path')``). Additionally, setting method-based routes using ``withRoutes()`` must
4748
also use uppercase method names (e.g., ``$this->withRoutes([['GET', 'home', 'Home::index']])``).

utils/phpstan-baseline/property.phpDocType.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ parameters:
7373
path: ../../system/Exceptions/PageNotFoundException.php
7474

7575
-
76-
message: '#^PHPDoc type int of property CodeIgniter\\HTTP\\Exceptions\\RedirectException\:\:\$code is not the same as PHPDoc type mixed of overridden property Exception\:\:\$code\.$#'
76+
message: '#^PHPDoc type CodeIgniter\\HTTP\\URI of property CodeIgniter\\HTTP\\IncomingRequest\:\:\$uri is not the same as PHPDoc type CodeIgniter\\HTTP\\URI\|null of overridden property CodeIgniter\\HTTP\\OutgoingRequest\:\:\$uri\.$#'
7777
count: 1
78-
path: ../../system/HTTP/Exceptions/RedirectException.php
78+
path: ../../system/HTTP/IncomingRequest.php
7979

8080
-
8181
message: '#^PHPDoc type string of property CodeIgniter\\Session\\Handlers\\FileHandler\:\:\$savePath is not the same as PHPDoc type array\<string, mixed\>\|string of overridden property CodeIgniter\\Session\\Handlers\\BaseHandler\:\:\$savePath\.$#'

0 commit comments

Comments
 (0)