Skip to content

Commit 8285da4

Browse files
javiereguiluzderrabus
authored andcommitted
Simplify some code with null coalesce operator
1 parent c4d9e00 commit 8285da4

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ public function getRequestFormat($default = 'html')
13711371
$this->format = $this->attributes->get('_format');
13721372
}
13731373

1374-
return null === $this->format ? $default : $this->format;
1374+
return $this->format ?? $default;
13751375
}
13761376

13771377
/**

RequestStack.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ public function getParentRequest()
9494
{
9595
$pos = \count($this->requests) - 2;
9696

97-
if (!isset($this->requests[$pos])) {
98-
return null;
99-
}
100-
101-
return $this->requests[$pos];
97+
return $this->requests[$pos] ?? null;
10298
}
10399
}

ResponseHeaderBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public function hasCacheControlDirective($key)
176176
*/
177177
public function getCacheControlDirective($key)
178178
{
179-
return \array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
179+
return $this->computedCacheControl[$key] ?? null;
180180
}
181181

182182
public function setCookie(Cookie $cookie)

Session/Storage/MetadataBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,6 @@ private function stampCreated(int $lifetime = null): void
163163
{
164164
$timeStamp = time();
165165
$this->meta[self::CREATED] = $this->meta[self::UPDATED] = $this->lastUsed = $timeStamp;
166-
$this->meta[self::LIFETIME] = (null === $lifetime) ? ini_get('session.cookie_lifetime') : $lifetime;
166+
$this->meta[self::LIFETIME] = $lifetime ?? ini_get('session.cookie_lifetime');
167167
}
168168
}

0 commit comments

Comments
 (0)