Skip to content

Commit bd18ac0

Browse files
committed
refactor: do nor override Exception's $code in RedirectException
1 parent 1d2489c commit bd18ac0

4 files changed

Lines changed: 6 additions & 12 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/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1492 errors
1+
# total 1491 errors
22

33
includes:
44
- argument.type.neon

utils/phpstan-baseline/property.phpDocType.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 41 errors
1+
# total 40 errors
22

33
parameters:
44
ignoreErrors:
@@ -137,11 +137,6 @@ parameters:
137137
count: 1
138138
path: ../../system/Exceptions/PageNotFoundException.php
139139

140-
-
141-
message: '#^PHPDoc type int of property CodeIgniter\\HTTP\\Exceptions\\RedirectException\:\:\$code is not the same as PHPDoc type mixed of overridden property Exception\:\:\$code\.$#'
142-
count: 1
143-
path: ../../system/HTTP/Exceptions/RedirectException.php
144-
145140
-
146141
message: '#^PHPDoc type string of property CodeIgniter\\HTTP\\Files\\UploadedFile\:\:\$originalMimeType is not the same as PHPDoc type string\|null of overridden property CodeIgniter\\Files\\File\:\:\$originalMimeType\.$#'
147142
count: 1

0 commit comments

Comments
 (0)