Skip to content

Commit

Permalink
refactor: Remove deprecation related to cookies (#9406)
Browse files Browse the repository at this point in the history
* refactor: Remove deprecated `Config\Security::$samesite`

* refactor: Remove deprecated methods in `CookieStore`

* docs: Update changelog

* refactor: Update phpstan baseline

* docs: Update userguide

* refactor: Remove deprecated  `Cookie::withNeverExpiring()`

* docs: Update changelog, userguide
  • Loading branch information
neznaika0 authored Jan 14, 2025
1 parent 35321ac commit 17d6ade
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 103 deletions.
17 changes: 0 additions & 17 deletions app/Config/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,4 @@ class Security extends BaseConfig
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
*/
public bool $redirect = (ENVIRONMENT === 'production');

/**
* --------------------------------------------------------------------------
* CSRF SameSite
* --------------------------------------------------------------------------
*
* Setting for CSRF SameSite cookie token.
*
* Allowed values are: None - Lax - Strict - ''.
*
* Defaults to `Lax` as recommended in this link:
*
* @see https://portswigger.net/web-security/csrf/samesite-cookies
*
* @deprecated `Config\Cookie` $samesite property is used.
*/
public string $samesite = 'Lax';
}
9 changes: 0 additions & 9 deletions system/Cookie/CloneableCookieInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ public function withExpires($expires);
*/
public function withExpired();

/**
* Creates a new Cookie that will virtually never expire from the browser.
*
* @return static
*
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
*/
public function withNeverExpiring();

/**
* Creates a new Cookie with a new path on the server the cookie is available.
*
Expand Down
12 changes: 0 additions & 12 deletions system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,6 @@ public function withExpired()
return $cookie;
}

/**
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
*/
public function withNeverExpiring()
{
$cookie = clone $this;

$cookie->expires = Time::now()->getTimestamp() + 5 * YEAR;

return $cookie;
}

/**
* {@inheritDoc}
*/
Expand Down
46 changes: 0 additions & 46 deletions system/Cookie/CookieStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,6 @@ public function remove(string $name, string $prefix = '')
return $store;
}

/**
* Dispatches all cookies in store.
*
* @deprecated Response should dispatch cookies.
*/
public function dispatch(): void
{
foreach ($this->cookies as $cookie) {
$name = $cookie->getPrefixedName();
$value = $cookie->getValue();
$options = $cookie->getOptions();

if ($cookie->isRaw()) {
$this->setRawCookie($name, $value, $options);
} else {
$this->setCookie($name, $value, $options);
}
}

$this->clear();
}

/**
* Returns all cookie instances in store.
*
Expand Down Expand Up @@ -232,28 +210,4 @@ protected function validateCookies(array $cookies): void
}
}
}

/**
* Extracted call to `setrawcookie()` in order to run unit tests on it.
*
* @codeCoverageIgnore
*
* @deprecated
*/
protected function setRawCookie(string $name, string $value, array $options): void
{
setrawcookie($name, $value, $options);
}

/**
* Extracted call to `setcookie()` in order to run unit tests on it.
*
* @codeCoverageIgnore
*
* @deprecated
*/
protected function setCookie(string $name, string $value, array $options): void
{
setcookie($name, $value, $options);
}
}
2 changes: 0 additions & 2 deletions tests/system/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ public function testCloningCookies(): void
$e = $a->withValue('muffin');
$f = $a->withExpires('+30 days');
$g = $a->withExpired();
$h = $a->withNeverExpiring();
$i = $a->withDomain('localhost');
$j = $a->withPath('/web');
$k = $a->withSecure();
Expand All @@ -248,7 +247,6 @@ public function testCloningCookies(): void
$this->assertNotSame($a, $e);
$this->assertNotSame($a, $f);
$this->assertNotSame($a, $g);
$this->assertNotSame($a, $h);
$this->assertNotSame($a, $i);
$this->assertNotSame($a, $j);
$this->assertNotSame($a, $k);
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ Removed Deprecated Items
- **View:** The deprecated property ``CodeIgniter\View\View::$currentSection`` has been removed.
- **Config:** The deprecated property ``Config\Cache::$storePath`` has been removed. Use ``Config\Cache::$file['storePath']`` instead.
- **Formatter:** The deprecated ``Config\Format::getFormatter()`` has been removed. Use ``CodeIgniter\Format\Format::getFormatter()`` instead.
- **Security:** ``Config\Security::$samesite`` has been removed. Use ``Config\Cookie::$samesite`` instead.
- **Cookie:** Methods ``dispatch()``, ``setRawCookie()``, ``setCookie()`` in ``CodeIgniter\Cookie\CookieStore`` has been removed. They are now part of ``CodeIgniter\HTTP\ResponseTrait``.

************
Enhancements
Expand Down
10 changes: 4 additions & 6 deletions user_guide_src/source/libraries/cookies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,7 @@ the instance with the modified instance.
Dispatching Cookies in Store
============================

.. deprecated:: 4.1.6

.. important:: This method is deprecated. It will be removed in future releases.
.. important:: This method was deprecated as of version 4.1.6 and was removed in 4.6.0.

More often than not, you do not need to concern yourself in manually sending cookies. CodeIgniter will do this
for you. However, if you really need to manually send cookies, you can use the ``dispatch`` method. Just like
Expand Down Expand Up @@ -369,9 +367,7 @@ Class Reference

.. php:method:: withNeverExpiring()
.. deprecated:: 4.2.6

.. important:: This method is deprecated. It will be removed in future releases.
.. important:: This method was deprecated as of version 4.2.6 and was removed in 4.6.0.

:param string $name:
:rtype: ``Cookie``
Expand Down Expand Up @@ -484,6 +480,8 @@ Class Reference

.. php:method:: dispatch(): void
.. important:: This method was deprecated as of version 4.1.6 and was removed in 4.6.0.

:rtype: void

Dispatches all cookies in store.
Expand Down
12 changes: 1 addition & 11 deletions utils/phpstan-baseline/missingType.iterableValue.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 1667 errors
# total 1665 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -852,16 +852,6 @@ parameters:
count: 1
path: ../../system/Controller.php

-
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:setCookie\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Cookie/CookieStore.php

-
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:setRawCookie\(\) has parameter \$options with no value type specified in iterable type array\.$#'
count: 1
path: ../../system/Cookie/CookieStore.php

-
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:validateCookies\(\) has parameter \$cookies with no value type specified in iterable type array\.$#'
count: 1
Expand Down

0 comments on commit 17d6ade

Please sign in to comment.