Skip to content

Commit 24dd055

Browse files
committed
apply Copilot review
1 parent 7a64888 commit 24dd055

6 files changed

Lines changed: 37 additions & 9 deletions

File tree

system/HTTP/Exceptions/RedirectException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class RedirectException extends RuntimeException implements ExceptionInterface, ResponsableInterface, HTTPExceptionInterface
2828
{
2929
/**
30-
* Status code applied to a Response that arrives without a 3xx redirect status.
30+
* Status code applied to a Response whose status is outside the 301-308 range.
3131
*/
3232
protected int $defaultStatusCode = 302;
3333

tests/system/HTTP/RedirectExceptionTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public function testResponseWithoutStatusCode(): void
7676
$this->assertSame(302, $response->getStatusCode());
7777
}
7878

79+
public function testResponseWithoutStatusCodeUsesSubclassDefault(): void
80+
{
81+
$exception = new class (service('response')->setHeader('Location', 'location')) extends RedirectException {
82+
protected int $defaultStatusCode = 307;
83+
};
84+
85+
$response = $exception->getResponse();
86+
87+
$this->assertSame('location', $response->getHeaderLine('location'));
88+
$this->assertSame(307, $response->getStatusCode());
89+
}
90+
7991
public function testLoggingLocationHeader(): void
8092
{
8193
Time::setTestNow('2023-11-25 12:00:00');

user_guide_src/source/changelogs/v4.8.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +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.
45+
- **HTTP:** ``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property. The status applied to a ``Response`` passed to the constructor whose status is outside the 301-308 range now comes from the new ``protected int $defaultStatusCode = 302`` property. Subclasses that overrode ``$code`` to change that status must override ``$defaultStatusCode`` instead.
4646
- **Testing:** Tests using the ``FeatureTestTrait`` must now use uppercase HTTP method names when performing a request when using the ``call()`` method directly
4747
(e.g., ``$this->call('GET', '/path')`` instead of ``$this->call('get', '/path')``). Additionally, setting method-based routes using ``withRoutes()`` must
4848
also use uppercase method names (e.g., ``$this->withRoutes([['GET', 'home', 'Home::index']])``).

user_guide_src/source/installation/upgrade_480.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,27 @@ the URI. Such calls must now pass a ``URI``:
8282
Any other call that omitted ``$uri`` or passed ``null`` already failed with
8383
``Call to a member function getHost() on null``, so it needs no migration.
8484

85+
RedirectException Default Status Code
86+
======================================
87+
88+
``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property to store the status applied to a
89+
``Response`` whose status is outside the 301-308 range. If you have a subclass that overrode ``$code`` for this purpose, override the new
90+
``$defaultStatusCode`` property instead:
91+
92+
.. code-block:: php
93+
94+
// Before
95+
class MyRedirectException extends RedirectException
96+
{
97+
protected $code = 307;
98+
}
99+
100+
// After
101+
class MyRedirectException extends RedirectException
102+
{
103+
protected int $defaultStatusCode = 307;
104+
}
105+
85106
*********************
86107
Breaking Enhancements
87108
*********************

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 689 errors
1+
# total 688 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 21 errors
1+
# total 20 errors
22

33
parameters:
44
ignoreErrors:
@@ -72,11 +72,6 @@ parameters:
7272
count: 1
7373
path: ../../system/Exceptions/PageNotFoundException.php
7474

75-
-
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\.$#'
77-
count: 1
78-
path: ../../system/HTTP/IncomingRequest.php
79-
8075
-
8176
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\.$#'
8277
count: 1

0 commit comments

Comments
 (0)