Skip to content

Commit d14b5c1

Browse files
Use ??= more
1 parent e550bdd commit d14b5c1

File tree

8 files changed

+13
-52
lines changed

8 files changed

+13
-52
lines changed

JsonResponse.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function __construct(mixed $data = null, int $status = 200, array $header
4444
throw new \TypeError(sprintf('"%s": If $json is set to true, argument $data must be a string or object implementing __toString(), "%s" given.', __METHOD__, get_debug_type($data)));
4545
}
4646

47-
if (null === $data) {
48-
$data = new \ArrayObject();
49-
}
47+
$data ??= new \ArrayObject();
5048

5149
$json ? $this->setJson($data) : $this->setData($data);
5250
}

Request.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,7 @@ public function getScriptName(): string
819819
*/
820820
public function getPathInfo(): string
821821
{
822-
if (null === $this->pathInfo) {
823-
$this->pathInfo = $this->preparePathInfo();
824-
}
825-
826-
return $this->pathInfo;
822+
return $this->pathInfo ??= $this->preparePathInfo();
827823
}
828824

829825
/**
@@ -840,11 +836,7 @@ public function getPathInfo(): string
840836
*/
841837
public function getBasePath(): string
842838
{
843-
if (null === $this->basePath) {
844-
$this->basePath = $this->prepareBasePath();
845-
}
846-
847-
return $this->basePath;
839+
return $this->basePath ??= $this->prepareBasePath();
848840
}
849841

850842
/**
@@ -877,11 +869,7 @@ public function getBaseUrl(): string
877869
*/
878870
private function getBaseUrlReal(): string
879871
{
880-
if (null === $this->baseUrl) {
881-
$this->baseUrl = $this->prepareBaseUrl();
882-
}
883-
884-
return $this->baseUrl;
872+
return $this->baseUrl ??= $this->prepareBaseUrl();
885873
}
886874

887875
/**
@@ -982,11 +970,7 @@ public function getHttpHost(): string
982970
*/
983971
public function getRequestUri(): string
984972
{
985-
if (null === $this->requestUri) {
986-
$this->requestUri = $this->prepareRequestUri();
987-
}
988-
989-
return $this->requestUri;
973+
return $this->requestUri ??= $this->prepareRequestUri();
990974
}
991975

992976
/**
@@ -1315,9 +1299,7 @@ public function setFormat(?string $format, string|array $mimeTypes)
13151299
*/
13161300
public function getRequestFormat(?string $default = 'html'): ?string
13171301
{
1318-
if (null === $this->format) {
1319-
$this->format = $this->attributes->get('_format');
1320-
}
1302+
$this->format ??= $this->attributes->get('_format');
13211303

13221304
return $this->format ?? $default;
13231305
}
@@ -2037,9 +2019,7 @@ private function normalizeAndFilterClientIps(array $clientIps, string $ip): arra
20372019
unset($clientIps[$key]);
20382020

20392021
// Fallback to this when the client IP falls into the range of trusted proxies
2040-
if (null === $firstTrustedIp) {
2041-
$firstTrustedIp = $clientIp;
2042-
}
2022+
$firstTrustedIp ??= $clientIp;
20432023
}
20442024
}
20452025

ResponseHeaderBag.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ public function setCookie(Cookie $cookie)
168168
*/
169169
public function removeCookie(string $name, ?string $path = '/', string $domain = null)
170170
{
171-
if (null === $path) {
172-
$path = '/';
173-
}
171+
$path ??= '/';
174172

175173
unset($this->cookies[$domain][$path][$name]);
176174

Session/Storage/Handler/NativeFileSessionHandler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ class NativeFileSessionHandler extends \SessionHandler
3030
*/
3131
public function __construct(string $savePath = null)
3232
{
33-
if (null === $savePath) {
34-
$savePath = \ini_get('session.save_path');
35-
}
36-
37-
$baseDir = $savePath;
33+
$baseDir = $savePath ??= \ini_get('session.save_path');
3834

3935
if ($count = substr_count($savePath, ';')) {
4036
if ($count > 2) {

Session/Storage/MockArraySessionStorage.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ public function setMetadataBag(MetadataBag $bag = null)
176176
if (1 > \func_num_args()) {
177177
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
178178
}
179-
if (null === $bag) {
180-
$bag = new MetadataBag();
181-
}
182-
183-
$this->metadataBag = $bag;
179+
$this->metadataBag = $bag ?? new MetadataBag();
184180
}
185181

186182
/**

Session/Storage/MockFileSessionStorage.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class MockFileSessionStorage extends MockArraySessionStorage
3232
*/
3333
public function __construct(string $savePath = null, string $name = 'MOCKSESSID', MetadataBag $metaBag = null)
3434
{
35-
if (null === $savePath) {
36-
$savePath = sys_get_temp_dir();
37-
}
35+
$savePath ??= sys_get_temp_dir();
3836

3937
if (!is_dir($savePath) && !@mkdir($savePath, 0777, true) && !is_dir($savePath)) {
4038
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $savePath));

Session/Storage/NativeSessionStorage.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,8 @@ public function setMetadataBag(MetadataBag $metaBag = null)
304304
if (1 > \func_num_args()) {
305305
trigger_deprecation('symfony/http-foundation', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
306306
}
307-
if (null === $metaBag) {
308-
$metaBag = new MetadataBag();
309-
}
307+
$this->metadataBag = $metaBag ?? new MetadataBag();
310308

311-
$this->metadataBag = $metaBag;
312309
}
313310

314311
/**

Tests/RequestTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,7 @@ public function nonstandardRequestsData()
23412341
*/
23422342
public function testNonstandardRequests($requestUri, $queryString, $expectedPathInfo, $expectedUri, $expectedBasePath = '', $expectedBaseUrl = null)
23432343
{
2344-
if (null === $expectedBaseUrl) {
2345-
$expectedBaseUrl = $expectedBasePath;
2346-
}
2344+
$expectedBaseUrl ??= $expectedBasePath;
23472345

23482346
$server = [
23492347
'HTTP_HOST' => 'host:8080',

0 commit comments

Comments
 (0)