Skip to content

Commit 40f5065

Browse files
committed
null coalescing assignment operator
1 parent 140a849 commit 40f5065

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

src/Http/Request.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use function is_array;
1515

16-
use const Mvc5\{ BODY, HEADERS, HOST, STATUS, URI };
16+
use const Mvc5\{ BODY, HEADERS, HOST, URI };
1717

1818
class Request
1919
extends Model
@@ -29,11 +29,9 @@ class Request
2929
*/
3030
function __construct($config = [])
3131
{
32-
!isset($config[BODY]) &&
33-
$config[BODY] = new Stream('php://temp', 'wb+');
32+
$config[BODY] ??= new Stream('php://temp', 'wb+');
3433

35-
!isset($config[HEADERS]) &&
36-
$config[HEADERS] = new HttpHeaders;
34+
$config[HEADERS] ??= new HttpHeaders;
3735

3836
is_array($config[HEADERS]) &&
3937
$config[HEADERS] = new HttpHeaders($config[HEADERS]);

src/Http/Response.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ class Response
2828
*/
2929
function __construct($config = [])
3030
{
31-
!isset($config[BODY]) &&
32-
$config[BODY] = new Stream('php://memory', 'wb+');
33-
34-
!isset($config[HEADERS]) &&
35-
$config[HEADERS] = new HttpHeaders;
31+
$config[BODY] ??= new Stream('php://memory', 'wb+');
3632

33+
$config[HEADERS] ??= new HttpHeaders;
3734
is_array($config[HEADERS]) &&
3835
$config[HEADERS] = new HttpHeaders($config[HEADERS]);
3936

src/Http/ServerRequest.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,30 @@ class ServerRequest
3737
*/
3838
function __construct($config = [])
3939
{
40-
!isset($config[SERVER]) &&
41-
$config[SERVER] = normalizeServer($_SERVER);
40+
$config[SERVER] ??= normalizeServer($_SERVER);
4241

4342
$server = $config[SERVER];
4443

45-
!isset($config[HEADERS]) &&
46-
$config[HEADERS] = marshalHeadersFromSapi($server);
44+
$config[HEADERS] ??= marshalHeadersFromSapi($server);
4745

4846
is_array($config[HEADERS]) &&
4947
$config[HEADERS] = new HttpHeaders($config[HEADERS]);
5048

51-
!isset($config[URI]) &&
52-
$config[URI] = new Uri(marshalUriFromSapi($server, $config[HEADERS]->all()));
49+
$config[URI] ??= new Uri(marshalUriFromSapi($server, $config[HEADERS]->all()));
5350

54-
!isset($config[COOKIES]) &&
55-
$config[COOKIES] = new HttpCookies(isset($config[HEADERS]['cookie']) ?
56-
parseCookieHeader($config[HEADERS]['cookie']) : $_COOKIE);
51+
$config[COOKIES] ??= new HttpCookies(isset($config[HEADERS]['cookie']) ?
52+
parseCookieHeader($config[HEADERS]['cookie']) : $_COOKIE);
5753

5854
is_array($config[COOKIES]) &&
5955
$config[COOKIES] = new HttpCookies($config[COOKIES]);
6056

61-
!isset($config[ARGS]) && $config[ARGS] = $_GET;
62-
!isset($config[ATTRIBUTES]) && $config[ATTRIBUTES] = [];
63-
!isset($config[BODY]) && $config[BODY] = new PhpInputStream;
64-
!isset($config[DATA]) && $config[DATA] = $_POST;
65-
!isset($config[FILES]) && $config[FILES] = normalizeUploadedFiles($_FILES);
66-
!isset($config[METHOD]) && $config[METHOD] = $server['REQUEST_METHOD'] ?? 'GET';
67-
!isset($config[VERSION]) && $config[VERSION] = substr($server['SERVER_PROTOCOL'] ?? 'HTTP/1.1', strlen('HTTP/'));
57+
$config[ARGS] ??= $_GET;
58+
$config[ATTRIBUTES] ??= [];
59+
$config[BODY] ??= new PhpInputStream;
60+
$config[DATA] ??= $_POST;
61+
$config[FILES] ??= normalizeUploadedFiles($_FILES);
62+
$config[METHOD] ??= $server['REQUEST_METHOD'] ?? 'GET';
63+
$config[VERSION] ??= substr($server['SERVER_PROTOCOL'] ?? 'HTTP/1.1', strlen('HTTP/'));
6864

6965
parent::__construct($config);
7066
}

0 commit comments

Comments
 (0)