Skip to content

Commit 4caf92b

Browse files
Remove all "nullable-by-default-value" setters
1 parent 1e1b6ce commit 4caf92b

File tree

7 files changed

+22
-7
lines changed

7 files changed

+22
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* The HTTP cache store uses the `xxh128` algorithm
8+
* Deprecate calling `JsonResponse::setCallback()`, `Response::setExpires/setLastModified/setEtag()`, `MockArraySessionStorage/NativeSessionStorage::setMetadataBag()`, `NativeSessionStorage::setSaveHandler()` without arguments
89

910
6.1
1011
---

JsonResponse.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public static function fromJsonString(string $data, int $status = 200, array $he
7979
*/
8080
public function setCallback(string $callback = null): static
8181
{
82+
if (1 > \func_num_args()) {
83+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
84+
}
8285
if (null !== $callback) {
8386
// partially taken from https://geekality.net/2011/08/03/valid-javascript-identifier/
8487
// partially taken from https://github.com/willdurand/JsonpCallbackValidator

Response.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ public function getExpires(): ?\DateTimeInterface
720720
*/
721721
public function setExpires(\DateTimeInterface $date = null): static
722722
{
723+
if (1 > \func_num_args()) {
724+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
725+
}
723726
if (null === $date) {
724727
$this->headers->remove('Expires');
725728

@@ -899,6 +902,9 @@ public function getLastModified(): ?\DateTimeInterface
899902
*/
900903
public function setLastModified(\DateTimeInterface $date = null): static
901904
{
905+
if (1 > \func_num_args()) {
906+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
907+
}
902908
if (null === $date) {
903909
$this->headers->remove('Last-Modified');
904910

@@ -937,6 +943,9 @@ public function getEtag(): ?string
937943
*/
938944
public function setEtag(string $etag = null, bool $weak = false): static
939945
{
946+
if (1 > \func_num_args()) {
947+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
948+
}
940949
if (null === $etag) {
941950
$this->headers->remove('Etag');
942951
} else {

Session/Storage/MockArraySessionStorage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ public function isStarted(): bool
173173

174174
public function setMetadataBag(MetadataBag $bag = null)
175175
{
176+
if (1 > \func_num_args()) {
177+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
178+
}
176179
if (null === $bag) {
177180
$bag = new MetadataBag();
178181
}

Session/Storage/NativeSessionStorage.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ public function getBag(string $name): SessionBagInterface
301301

302302
public function setMetadataBag(MetadataBag $metaBag = null)
303303
{
304+
if (1 > \func_num_args()) {
305+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
306+
}
304307
if (null === $metaBag) {
305308
$metaBag = new MetadataBag();
306309
}
@@ -377,10 +380,8 @@ public function setOptions(array $options)
377380
*/
378381
public function setSaveHandler(AbstractProxy|\SessionHandlerInterface $saveHandler = null)
379382
{
380-
if (!$saveHandler instanceof AbstractProxy &&
381-
!$saveHandler instanceof \SessionHandlerInterface &&
382-
null !== $saveHandler) {
383-
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
383+
if (1 > \func_num_args()) {
384+
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
384385
}
385386

386387
// Wrap $saveHandler in proxy and prevent double wrapping of proxy

Tests/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ public function testHasVary()
995995
public function testSetEtag()
996996
{
997997
$response = new Response('', 200, ['ETag' => '"12345"']);
998-
$response->setEtag();
998+
$response->setEtag(null);
999999

10001000
$this->assertNull($response->headers->get('Etag'), '->setEtag() removes Etags when call with null');
10011001
}

Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ public function testSetSaveHandler()
206206
{
207207
$this->iniSet('session.save_handler', 'files');
208208
$storage = $this->getStorage();
209-
$storage->setSaveHandler();
210-
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
211209
$storage->setSaveHandler(null);
212210
$this->assertInstanceOf(SessionHandlerProxy::class, $storage->getSaveHandler());
213211
$storage->setSaveHandler(new SessionHandlerProxy(new NativeFileSessionHandler()));

0 commit comments

Comments
 (0)