Skip to content

Commit 17d6ade

Browse files
authored
refactor: Remove deprecation related to cookies (#9406)
* 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
1 parent 35321ac commit 17d6ade

File tree

8 files changed

+7
-103
lines changed

8 files changed

+7
-103
lines changed

app/Config/Security.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,4 @@ class Security extends BaseConfig
8383
* @see https://codeigniter4.github.io/userguide/libraries/security.html#redirection-on-failure
8484
*/
8585
public bool $redirect = (ENVIRONMENT === 'production');
86-
87-
/**
88-
* --------------------------------------------------------------------------
89-
* CSRF SameSite
90-
* --------------------------------------------------------------------------
91-
*
92-
* Setting for CSRF SameSite cookie token.
93-
*
94-
* Allowed values are: None - Lax - Strict - ''.
95-
*
96-
* Defaults to `Lax` as recommended in this link:
97-
*
98-
* @see https://portswigger.net/web-security/csrf/samesite-cookies
99-
*
100-
* @deprecated `Config\Cookie` $samesite property is used.
101-
*/
102-
public string $samesite = 'Lax';
10386
}

system/Cookie/CloneableCookieInterface.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ public function withExpires($expires);
5858
*/
5959
public function withExpired();
6060

61-
/**
62-
* Creates a new Cookie that will virtually never expire from the browser.
63-
*
64-
* @return static
65-
*
66-
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
67-
*/
68-
public function withNeverExpiring();
69-
7061
/**
7162
* Creates a new Cookie with a new path on the server the cookie is available.
7263
*

system/Cookie/Cookie.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,6 @@ public function withExpired()
465465
return $cookie;
466466
}
467467

468-
/**
469-
* @deprecated See https://github.com/codeigniter4/CodeIgniter4/pull/6413
470-
*/
471-
public function withNeverExpiring()
472-
{
473-
$cookie = clone $this;
474-
475-
$cookie->expires = Time::now()->getTimestamp() + 5 * YEAR;
476-
477-
return $cookie;
478-
}
479-
480468
/**
481469
* {@inheritDoc}
482470
*/

system/Cookie/CookieStore.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,6 @@ public function remove(string $name, string $prefix = '')
159159
return $store;
160160
}
161161

162-
/**
163-
* Dispatches all cookies in store.
164-
*
165-
* @deprecated Response should dispatch cookies.
166-
*/
167-
public function dispatch(): void
168-
{
169-
foreach ($this->cookies as $cookie) {
170-
$name = $cookie->getPrefixedName();
171-
$value = $cookie->getValue();
172-
$options = $cookie->getOptions();
173-
174-
if ($cookie->isRaw()) {
175-
$this->setRawCookie($name, $value, $options);
176-
} else {
177-
$this->setCookie($name, $value, $options);
178-
}
179-
}
180-
181-
$this->clear();
182-
}
183-
184162
/**
185163
* Returns all cookie instances in store.
186164
*
@@ -232,28 +210,4 @@ protected function validateCookies(array $cookies): void
232210
}
233211
}
234212
}
235-
236-
/**
237-
* Extracted call to `setrawcookie()` in order to run unit tests on it.
238-
*
239-
* @codeCoverageIgnore
240-
*
241-
* @deprecated
242-
*/
243-
protected function setRawCookie(string $name, string $value, array $options): void
244-
{
245-
setrawcookie($name, $value, $options);
246-
}
247-
248-
/**
249-
* Extracted call to `setcookie()` in order to run unit tests on it.
250-
*
251-
* @codeCoverageIgnore
252-
*
253-
* @deprecated
254-
*/
255-
protected function setCookie(string $name, string $value, array $options): void
256-
{
257-
setcookie($name, $value, $options);
258-
}
259213
}

tests/system/Cookie/CookieTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public function testCloningCookies(): void
235235
$e = $a->withValue('muffin');
236236
$f = $a->withExpires('+30 days');
237237
$g = $a->withExpired();
238-
$h = $a->withNeverExpiring();
239238
$i = $a->withDomain('localhost');
240239
$j = $a->withPath('/web');
241240
$k = $a->withSecure();
@@ -248,7 +247,6 @@ public function testCloningCookies(): void
248247
$this->assertNotSame($a, $e);
249248
$this->assertNotSame($a, $f);
250249
$this->assertNotSame($a, $g);
251-
$this->assertNotSame($a, $h);
252250
$this->assertNotSame($a, $i);
253251
$this->assertNotSame($a, $j);
254252
$this->assertNotSame($a, $k);

user_guide_src/source/changelogs/v4.6.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ Removed Deprecated Items
203203
- **View:** The deprecated property ``CodeIgniter\View\View::$currentSection`` has been removed.
204204
- **Config:** The deprecated property ``Config\Cache::$storePath`` has been removed. Use ``Config\Cache::$file['storePath']`` instead.
205205
- **Formatter:** The deprecated ``Config\Format::getFormatter()`` has been removed. Use ``CodeIgniter\Format\Format::getFormatter()`` instead.
206+
- **Security:** ``Config\Security::$samesite`` has been removed. Use ``Config\Cookie::$samesite`` instead.
207+
- **Cookie:** Methods ``dispatch()``, ``setRawCookie()``, ``setCookie()`` in ``CodeIgniter\Cookie\CookieStore`` has been removed. They are now part of ``CodeIgniter\HTTP\ResponseTrait``.
206208

207209
************
208210
Enhancements

user_guide_src/source/libraries/cookies.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ the instance with the modified instance.
228228
Dispatching Cookies in Store
229229
============================
230230

231-
.. deprecated:: 4.1.6
232-
233-
.. important:: This method is deprecated. It will be removed in future releases.
231+
.. important:: This method was deprecated as of version 4.1.6 and was removed in 4.6.0.
234232

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

370368
.. php:method:: withNeverExpiring()
371369
372-
.. deprecated:: 4.2.6
373-
374-
.. important:: This method is deprecated. It will be removed in future releases.
370+
.. important:: This method was deprecated as of version 4.2.6 and was removed in 4.6.0.
375371

376372
:param string $name:
377373
:rtype: ``Cookie``
@@ -484,6 +480,8 @@ Class Reference
484480

485481
.. php:method:: dispatch(): void
486482
483+
.. important:: This method was deprecated as of version 4.1.6 and was removed in 4.6.0.
484+
487485
:rtype: void
488486

489487
Dispatches all cookies in store.

utils/phpstan-baseline/missingType.iterableValue.neon

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1667 errors
1+
# total 1665 errors
22

33
parameters:
44
ignoreErrors:
@@ -852,16 +852,6 @@ parameters:
852852
count: 1
853853
path: ../../system/Controller.php
854854

855-
-
856-
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:setCookie\(\) has parameter \$options with no value type specified in iterable type array\.$#'
857-
count: 1
858-
path: ../../system/Cookie/CookieStore.php
859-
860-
-
861-
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:setRawCookie\(\) has parameter \$options with no value type specified in iterable type array\.$#'
862-
count: 1
863-
path: ../../system/Cookie/CookieStore.php
864-
865855
-
866856
message: '#^Method CodeIgniter\\Cookie\\CookieStore\:\:validateCookies\(\) has parameter \$cookies with no value type specified in iterable type array\.$#'
867857
count: 1

0 commit comments

Comments
 (0)