Skip to content

Commit d9b4872

Browse files
minor symfony#29009 SCA: simplify some ifs in favour of null coalescing operator (kalessil, vladimir.reznichenko)
This PR was merged into the 4.1 branch. Discussion ---------- SCA: simplify some ifs in favour of null coalescing operator | Q | A | ------------- | --- | Branch? | 4.1 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Some of ifs were replaced with null coalescing operator in order to simplify control flow. Commits ------- 636a872 SCA: reverted code style changes c926b1a SCA: reverted code style changes 300b31f SCA: applied requested code style changes 0180cb9 SCA: simplify some ifs in favour of null coalescing operator
2 parents 6dde5b9 + 636a872 commit d9b4872

File tree

9 files changed

+9
-42
lines changed

9 files changed

+9
-42
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
283283
$contextKey = null;
284284
// Context serializer listener
285285
if (false === $firewall['stateless']) {
286-
$contextKey = $id;
287-
if (isset($firewall['context'])) {
288-
$contextKey = $firewall['context'];
289-
}
290-
286+
$contextKey = $firewall['context'] ?? $id;
291287
$listeners[] = new Reference($this->createContextListener($container, $contextKey));
292288
$sessionStrategyId = 'security.authentication.session_strategy';
293289
} else {

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ public function setColumnStyle($columnIndex, $name)
180180
*/
181181
public function getColumnStyle($columnIndex)
182182
{
183-
if (isset($this->columnStyles[$columnIndex])) {
184-
return $this->columnStyles[$columnIndex];
185-
}
186-
187-
return $this->getStyle();
183+
return $this->columnStyles[$columnIndex] ?? $this->getStyle();
188184
}
189185

190186
/**

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,7 @@ public function mirror($originDir, $targetDir, \Traversable $iterator = null, $o
557557
}
558558
}
559559

560-
$copyOnWindows = false;
561-
if (isset($options['copy_on_windows'])) {
562-
$copyOnWindows = $options['copy_on_windows'];
563-
}
560+
$copyOnWindows = $options['copy_on_windows'] ?? false;
564561

565562
if (null === $iterator) {
566563
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;

src/Symfony/Component/Intl/Globals/IntlGlobals.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ public static function getErrorMessage()
100100
*/
101101
public static function getErrorName($code)
102102
{
103-
if (isset(self::$errorCodes[$code])) {
104-
return self::$errorCodes[$code];
105-
}
106-
107-
return '[BOGUS UErrorCode]';
103+
return self::$errorCodes[$code] ?? '[BOGUS UErrorCode]';
108104
}
109105

110106
/**

src/Symfony/Component/Messenger/Asynchronous/Routing/SenderLocator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ public static function getValueFromMessageRouting(array $mapping, $message)
5757
if ($interfaceMapping = array_intersect_key($mapping, class_implements($message))) {
5858
return current($interfaceMapping);
5959
}
60-
if (isset($mapping['*'])) {
61-
return $mapping['*'];
62-
}
6360

64-
return null;
61+
return $mapping['*'] ?? null;
6562
}
6663
}

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
254254
});
255255

256256
// extract fragment
257-
$fragment = '';
258-
if (isset($defaults['_fragment'])) {
259-
$fragment = $defaults['_fragment'];
260-
}
257+
$fragment = $defaults['_fragment'] ?? '';
261258

262259
if (isset($extra['_fragment'])) {
263260
$fragment = $extra['_fragment'];

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,7 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
326326
$val = $this->parseXml($subnode, $context);
327327

328328
if ('item' === $subnode->nodeName && isset($val['@key'])) {
329-
if (isset($val['#'])) {
330-
$value[$val['@key']] = $val['#'];
331-
} else {
332-
$value[$val['@key']] = $val;
333-
}
329+
$value[$val['@key']] = $val['#'] ?? $val;
334330
} else {
335331
$value[$subnode->nodeName][] = $val;
336332
}

src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ public function getTypeProperty(): string
3232

3333
public function getClassForType(string $type): ?string
3434
{
35-
if (isset($this->typesMapping[$type])) {
36-
return $this->typesMapping[$type];
37-
}
38-
39-
return null;
35+
return $this->typesMapping[$type] ?? null;
4036
}
4137

4238
/**

src/Symfony/Component/Translation/Dumper/JsonFileDumper.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ class JsonFileDumper extends FileDumper
2525
*/
2626
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
2727
{
28-
if (isset($options['json_encoding'])) {
29-
$flags = $options['json_encoding'];
30-
} else {
31-
$flags = JSON_PRETTY_PRINT;
32-
}
28+
$flags = $options['json_encoding'] ?? JSON_PRETTY_PRINT;
3329

3430
return json_encode($messages->all($domain), $flags);
3531
}

0 commit comments

Comments
 (0)