minor #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
-------

636a872389 SCA: reverted code style changes
c926b1abd3 SCA: reverted code style changes
300b31fa75 SCA: applied requested code style changes
0180cb936f SCA: simplify some ifs in favour of null coalescing operator
This commit is contained in:
Nicolas Grekas 2018-10-31 10:30:44 +01:00
commit d9b4872454
9 changed files with 9 additions and 42 deletions

View File

@ -283,11 +283,7 @@ class SecurityExtension extends Extension
$contextKey = null;
// Context serializer listener
if (false === $firewall['stateless']) {
$contextKey = $id;
if (isset($firewall['context'])) {
$contextKey = $firewall['context'];
}
$contextKey = $firewall['context'] ?? $id;
$listeners[] = new Reference($this->createContextListener($container, $contextKey));
$sessionStrategyId = 'security.authentication.session_strategy';
} else {

View File

@ -180,11 +180,7 @@ class Table
*/
public function getColumnStyle($columnIndex)
{
if (isset($this->columnStyles[$columnIndex])) {
return $this->columnStyles[$columnIndex];
}
return $this->getStyle();
return $this->columnStyles[$columnIndex] ?? $this->getStyle();
}
/**

View File

@ -557,10 +557,7 @@ class Filesystem
}
}
$copyOnWindows = false;
if (isset($options['copy_on_windows'])) {
$copyOnWindows = $options['copy_on_windows'];
}
$copyOnWindows = $options['copy_on_windows'] ?? false;
if (null === $iterator) {
$flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;

View File

@ -100,11 +100,7 @@ abstract class IntlGlobals
*/
public static function getErrorName($code)
{
if (isset(self::$errorCodes[$code])) {
return self::$errorCodes[$code];
}
return '[BOGUS UErrorCode]';
return self::$errorCodes[$code] ?? '[BOGUS UErrorCode]';
}
/**

View File

@ -57,10 +57,7 @@ class SenderLocator implements SenderLocatorInterface
if ($interfaceMapping = array_intersect_key($mapping, class_implements($message))) {
return current($interfaceMapping);
}
if (isset($mapping['*'])) {
return $mapping['*'];
}
return null;
return $mapping['*'] ?? null;
}
}

View File

@ -254,10 +254,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
});
// extract fragment
$fragment = '';
if (isset($defaults['_fragment'])) {
$fragment = $defaults['_fragment'];
}
$fragment = $defaults['_fragment'] ?? '';
if (isset($extra['_fragment'])) {
$fragment = $extra['_fragment'];

View File

@ -326,11 +326,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
$val = $this->parseXml($subnode, $context);
if ('item' === $subnode->nodeName && isset($val['@key'])) {
if (isset($val['#'])) {
$value[$val['@key']] = $val['#'];
} else {
$value[$val['@key']] = $val;
}
$value[$val['@key']] = $val['#'] ?? $val;
} else {
$value[$subnode->nodeName][] = $val;
}

View File

@ -32,11 +32,7 @@ class ClassDiscriminatorMapping
public function getClassForType(string $type): ?string
{
if (isset($this->typesMapping[$type])) {
return $this->typesMapping[$type];
}
return null;
return $this->typesMapping[$type] ?? null;
}
/**

View File

@ -25,11 +25,7 @@ class JsonFileDumper extends FileDumper
*/
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
if (isset($options['json_encoding'])) {
$flags = $options['json_encoding'];
} else {
$flags = JSON_PRETTY_PRINT;
}
$flags = $options['json_encoding'] ?? JSON_PRETTY_PRINT;
return json_encode($messages->all($domain), $flags);
}