Skip to content

Commit efd9cd0

Browse files
committed
Use null coalescing operator instead of ternary operator
1 parent 4e212ee commit efd9cd0

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

components/property_access.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ enable this feature by using :class:`Symfony\\Component\\PropertyAccess\\Propert
237237
{
238238
$property = lcfirst(substr($name, 3));
239239
if ('get' === substr($name, 0, 3)) {
240-
return isset($this->children[$property])
241-
? $this->children[$property]
242-
: null;
240+
return $this->children[$property] ?? null;
243241
} elseif ('set' === substr($name, 0, 3)) {
244242
$value = 1 == count($args) ? $args[0] : null;
245243
$this->children[$property] = $value;
@@ -334,9 +332,7 @@ see `Enable other Features`_::
334332
{
335333
$property = lcfirst(substr($name, 3));
336334
if ('get' === substr($name, 0, 3)) {
337-
return isset($this->children[$property])
338-
? $this->children[$property]
339-
: null;
335+
return $this->children[$property] ?? null;
340336
} elseif ('set' === substr($name, 0, 3)) {
341337
$value = 1 == count($args) ? $args[0] : null;
342338
$this->children[$property] = $value;

create_framework/http_foundation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ First, if the ``name`` query parameter is not defined in the URL query string,
2525
you will get a PHP warning; so let's fix it::
2626

2727
// framework/index.php
28-
$name = isset($_GET['name']) ? $_GET['name'] : 'World';
28+
$name = $_GET['name'] ?? 'World';
2929

3030
printf('Hello %s', $name);
3131

3232
Then, this *application is not secure*. Can you believe it? Even this simple
3333
snippet of PHP code is vulnerable to one of the most widespread Internet
3434
security issue, XSS (Cross-Site Scripting). Here is a more secure version::
3535

36-
$name = isset($_GET['name']) ? $_GET['name'] : 'World';
36+
$name = $_GET['name'] ?? 'World';
3737

3838
header('Content-Type: text/html; charset=utf-8');
3939

frontend/custom_version_strategy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ version string::
8383
$this->hashes = $this->loadManifest();
8484
}
8585

86-
return isset($this->hashes[$path]) ? $this->hashes[$path] : '';
86+
return $this->hashes[$path] ?? '';
8787
}
8888

8989
public function applyVersion($path)

0 commit comments

Comments
 (0)