Skip to content

Commit 594b20f

Browse files
committed
apply Copilot review
1 parent f236527 commit 594b20f

4 files changed

Lines changed: 35 additions & 2 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
@@ -27,6 +27,27 @@ Previously, returning a non-integer value from a command run through ``spark`` w
2727
Starting with v4.8.0, this behavior is still supported but will trigger a deprecation notice. Commands should now return an integer exit code
2828
to ensure proper behavior across all platforms.
2929

30+
RedirectException Default Status Code
31+
======================================
32+
33+
``CodeIgniter\HTTP\Exceptions\RedirectException`` no longer redeclares the inherited ``$code`` property to store the status applied to a
34+
``Response`` whose status is outside the 301-308 range. If you have a subclass that overrode ``$code`` for this purpose, override the new
35+
``$defaultStatusCode`` property instead:
36+
37+
.. code-block:: php
38+
39+
// Before
40+
class MyRedirectException extends RedirectException
41+
{
42+
protected $code = 307;
43+
}
44+
45+
// After
46+
class MyRedirectException extends RedirectException
47+
{
48+
protected int $defaultStatusCode = 307;
49+
}
50+
3051
*********************
3152
Breaking Enhancements
3253
*********************

0 commit comments

Comments
 (0)