Unverified Commit f436f7c0 authored by larowlan's avatar larowlan
Browse files

Issue #3222251 by bbrala, longwave: [November 8, 2021] Replace all isset...

Issue #3222251 by bbrala, longwave: [November 8, 2021] Replace all isset constructs with the null coalescing operator

(cherry picked from commit 330473e7)
parent 460665f7
......@@ -83,7 +83,7 @@ public function composerLock() {
*/
public function getRequireDev() {
$composerJsonData = $this->rootComposerJson();
return isset($composerJsonData['require-dev']) ? $composerJsonData['require-dev'] : [];
return $composerJsonData['require-dev'] ?? [];
}
/**
......
......@@ -139,7 +139,7 @@ public function getAllCleanupPaths() {
// Merge root config with defaults.
foreach (array_change_key_case(static::$defaultConfig, CASE_LOWER) as $package => $paths) {
$this->configData[$package] = array_merge(
isset($this->configData[$package]) ? $this->configData[$package] : [],
$this->configData[$package] ?? [],
$paths);
}
return $this->configData;
......@@ -157,7 +157,7 @@ public function getAllCleanupPaths() {
public function getPathsForPackage($package) {
$package = strtolower($package);
$paths = $this->getAllCleanupPaths();
return isset($paths[$package]) ? $paths[$package] : [];
return $paths[$package] ?? [];
}
}
......@@ -354,7 +354,7 @@ function _batch_process() {
// completion level of the current operation.
$current = $total - $remaining + $finished;
$percentage = _batch_api_percentage($total, $current);
$elapsed = isset($current_set['elapsed']) ? $current_set['elapsed'] : 0;
$elapsed = $current_set['elapsed'] ?? 0;
$values = [
'@remaining' => $remaining,
'@total' => $total,
......
......@@ -415,8 +415,8 @@ function drupal_valid_test_ua($new_prefix = NULL) {
// A valid Simpletest request will contain a hashed and salted authentication
// code. Check if this code is present in a cookie or custom user agent
// string.
$http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL;
$user_agent = isset($_COOKIE['SIMPLETEST_USER_AGENT']) ? $_COOKIE['SIMPLETEST_USER_AGENT'] : $http_user_agent;
$http_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? NULL;
$user_agent = $_COOKIE['SIMPLETEST_USER_AGENT'] ?? $http_user_agent;
if (isset($user_agent) && preg_match("/^simple(\w+\d+):(.+):(.+):(.+)$/", $user_agent, $matches)) {
list(, $prefix, $time, $salt, $hmac) = $matches;
$check_string = $prefix . ':' . $time . ':' . $salt;
......
......@@ -355,8 +355,8 @@ function drupal_attach_tabledrag(&$element, array $options) {
$tabledrag_id = (!isset($tabledrag_id)) ? 0 : $tabledrag_id + 1;
// If a subgroup or source isn't set, assume it is the same as the group.
$target = isset($options['subgroup']) ? $options['subgroup'] : $group;
$source = isset($options['source']) ? $options['source'] : $target;
$target = $options['subgroup'] ?? $group;
$source = $options['source'] ?? $target;
$element['#attached']['drupalSettings']['tableDrag'][$options['table_id']][$group][$tabledrag_id] = [
'target' => $target,
'source' => $source,
......
......@@ -323,7 +323,7 @@ function _drupal_get_error_level() {
$error_level = \Drupal::config('system.logging')->get('error_level');
}
catch (\Exception $e) {
$error_level = isset($GLOBALS['config']['system.logging']['error_level']) ? $GLOBALS['config']['system.logging']['error_level'] : ERROR_REPORTING_HIDE;
$error_level = $GLOBALS['config']['system.logging']['error_level'] ?? ERROR_REPORTING_HIDE;
}
// If there is no container or if it has no config.factory service, we are
......
......@@ -193,10 +193,10 @@ function template_preprocess_fieldset(&$variables) {
$element = $variables['element'];
Element::setAttributes($element, ['id']);
RenderElement::setAttributes($element);
$variables['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : [];
$variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
$variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
$variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL;
$variables['attributes'] = $element['#attributes'] ?? [];
$variables['prefix'] = $element['#field_prefix'] ?? NULL;
$variables['suffix'] = $element['#field_suffix'] ?? NULL;
$variables['title_display'] = $element['#title_display'] ?? NULL;
$variables['children'] = $element['#children'];
$variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
......@@ -477,8 +477,8 @@ function template_preprocess_form_element(&$variables) {
$variables['title_display'] = $element['#title_display'];
$variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
$variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
$variables['prefix'] = $element['#field_prefix'] ?? NULL;
$variables['suffix'] = $element['#field_suffix'] ?? NULL;
$variables['description'] = NULL;
if (!empty($element['#description'])) {
......@@ -883,7 +883,7 @@ function batch_process($redirect = NULL, Url $url = NULL, $redirect_callback = N
$process_info = [
'current_set' => 0,
'progressive' => TRUE,
'url' => isset($url) ? $url : Url::fromRoute('system.batch_page.html'),
'url' => $url ?? Url::fromRoute('system.batch_page.html'),
'source_url' => Url::fromRouteMatch(\Drupal::routeMatch())->mergeOptions(['query' => \Drupal::request()->query->all()]),
'batch_redirect' => $redirect,
'theme' => \Drupal::theme()->getActiveTheme()->getName(),
......
......@@ -1523,7 +1523,7 @@ function _install_get_version_info($version) {
function install_load_profile(&$install_state) {
$profile = $install_state['parameters']['profile'];
$install_state['profiles'][$profile]->load();
$install_state['profile_info'] = install_profile_info($profile, isset($install_state['parameters']['langcode']) ? $install_state['parameters']['langcode'] : 'en');
$install_state['profile_info'] = install_profile_info($profile, $install_state['parameters']['langcode'] ?? 'en');
$sync_directory = Settings::get('config_sync_directory');
if (!empty($install_state['parameters']['existing_config']) && !empty($sync_directory)) {
......
......@@ -114,7 +114,7 @@ function drupal_install_profile_distribution_name() {
$profile = \Drupal::installProfile();
$info = \Drupal::service('extension.list.profile')->getExtensionInfo($profile);
}
return isset($info['distribution']['name']) ? $info['distribution']['name'] : 'Drupal';
return $info['distribution']['name'] ?? 'Drupal';
}
/**
......@@ -132,7 +132,7 @@ function drupal_install_profile_distribution_version() {
// installation state (it might not be saved anywhere yet).
if (InstallerKernel::installationAttempted()) {
global $install_state;
return isset($install_state['profile_info']['version']) ? $install_state['profile_info']['version'] : \Drupal::VERSION;
return $install_state['profile_info']['version'] ?? \Drupal::VERSION;
}
// At all other times, we load the profile via standard methods.
else {
......
......@@ -151,7 +151,7 @@ function drupal_find_theme_functions($cache, $prefixes) {
// refers to a base hook, not to another suggestion, and all suggestions
// are found using the base hook's pattern, not a pattern from an
// intermediary suggestion.
$pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
$pattern = $info['pattern'] ?? ($hook . '__');
// Grep only the functions which are within the prefix group.
list($first_prefix,) = explode('_', $prefix, 2);
if (!isset($info['base hook']) && !empty($pattern) && isset($grouped_functions[$first_prefix])) {
......@@ -212,7 +212,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
}
}
$theme = \Drupal::theme()->getActiveTheme()->getName();
$subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : [];
$subtheme_paths = $theme_paths[$theme] ?? [];
// Escape the periods in the extension.
$regex = '/' . str_replace('.', '\.', $extension) . '$/';
......@@ -261,7 +261,7 @@ function drupal_find_theme_templates($cache, $extension, $path) {
// the use of 'pattern' and 'base hook'.
$patterns = array_keys($files);
foreach ($cache as $hook => $info) {
$pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
$pattern = $info['pattern'] ?? ($hook . '__');
if (!isset($info['base hook']) && !empty($pattern)) {
// Transform _ in pattern to - to match file naming scheme
// for the purposes of searching.
......@@ -1020,7 +1020,7 @@ function template_preprocess_table(&$variables) {
unset($cell['data']);
}
// Flag the cell as a header or not and remove the flag.
$is_header = isset($cell['header']) ? $cell['header'] : TRUE;
$is_header = $cell['header'] ?? TRUE;
unset($cell['header']);
// Track responsive classes for each column as needed. Only the header
......@@ -1061,7 +1061,7 @@ function template_preprocess_table(&$variables) {
// Check if we're dealing with a simple or complex row
if (isset($row['data'])) {
$cells = $row['data'];
$variables['no_striping'] = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
$variables['no_striping'] = $row['no_striping'] ?? FALSE;
// Set the attributes array and exclude 'data' and 'no_striping'.
$row_attributes = $row;
......@@ -1788,7 +1788,7 @@ function template_preprocess_pager(&$variables) {
$parameters = $variables['pager']['#parameters'];
$quantity = empty($variables['pager']['#quantity']) ? 0 : $variables['pager']['#quantity'];
$route_name = $variables['pager']['#route_name'];
$route_parameters = isset($variables['pager']['#route_parameters']) ? $variables['pager']['#route_parameters'] : [];
$route_parameters = $variables['pager']['#route_parameters'] ?? [];
/** @var \Drupal\Core\Pager\PagerManagerInterface $pager_manager */
$pager_manager = \Drupal::service('pager.manager');
......
......@@ -78,7 +78,7 @@ public function get() {
* {@inheritdoc}
*/
public function getProvider() {
return isset($this->definition['provider']) ? $this->definition['provider'] : FALSE;
return $this->definition['provider'] ?? FALSE;
}
/**
......
......@@ -115,10 +115,10 @@ public function __construct(array $container_definition = []) {
throw new InvalidArgumentException('The non-optimized format is not supported by this class. Use an optimized machine-readable format instead, e.g. as produced by \Drupal\Component\DependencyInjection\Dumper\OptimizedPhpArrayDumper.');
}
$this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : [];
$this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : [];
$this->serviceDefinitions = isset($container_definition['services']) ? $container_definition['services'] : [];
$this->frozen = isset($container_definition['frozen']) ? $container_definition['frozen'] : FALSE;
$this->aliases = $container_definition['aliases'] ?? [];
$this->parameters = $container_definition['parameters'] ?? [];
$this->serviceDefinitions = $container_definition['services'] ?? [];
$this->frozen = $container_definition['frozen'] ?? FALSE;
// Register the service_container with itself.
$this->services['service_container'] = $this;
......@@ -146,7 +146,7 @@ public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_IN
throw new ServiceCircularReferenceException($id, array_keys($this->loading));
}
$definition = isset($this->serviceDefinitions[$id]) ? $this->serviceDefinitions[$id] : NULL;
$definition = $this->serviceDefinitions[$id] ?? NULL;
if (!$definition && $invalid_behavior === ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
if (!$id) {
......
......@@ -34,10 +34,10 @@ public function __construct(array $container_definition = []) {
// Do not call the parent's constructor as it would bail on the
// machine-optimized format.
$this->aliases = isset($container_definition['aliases']) ? $container_definition['aliases'] : [];
$this->parameters = isset($container_definition['parameters']) ? $container_definition['parameters'] : [];
$this->serviceDefinitions = isset($container_definition['services']) ? $container_definition['services'] : [];
$this->frozen = isset($container_definition['frozen']) ? $container_definition['frozen'] : FALSE;
$this->aliases = $container_definition['aliases'] ?? [];
$this->parameters = $container_definition['parameters'] ?? [];
$this->serviceDefinitions = $container_definition['services'] ?? [];
$this->frozen = $container_definition['frozen'] ?? FALSE;
// Register the service_container with itself.
$this->services['service_container'] = $this;
......
......@@ -293,11 +293,11 @@ public function addSubscriber(EventSubscriberInterface $subscriber) {
$this->addListener($event_name, [$subscriber, $params]);
}
elseif (is_string($params[0])) {
$this->addListener($event_name, [$subscriber, $params[0]], isset($params[1]) ? $params[1] : 0);
$this->addListener($event_name, [$subscriber, $params[0]], $params[1] ?? 0);
}
else {
foreach ($params as $listener) {
$this->addListener($event_name, [$subscriber, $listener[0]], isset($listener[1]) ? $listener[1] : 0);
$this->addListener($event_name, [$subscriber, $listener[0]], $listener[1] ?? 0);
}
}
}
......
......@@ -68,7 +68,7 @@ public function __construct($prefix, $collection, $cache_backend_class = NULL, a
public function get($filepath) {
$filepaths = [$filepath];
$cached = $this->getMultiple($filepaths);
return isset($cached[$filepath]) ? $cached[$filepath] : NULL;
return $cached[$filepath] ?? NULL;
}
/**
......
......@@ -526,7 +526,7 @@ public function setItemFromArray($value) {
}
$item = new PoItem();
$item->setContext(isset($value['msgctxt']) ? $value['msgctxt'] : '');
$item->setContext($value['msgctxt'] ?? '');
$item->setSource($value['msgid']);
$item->setTranslation($value['msgstr']);
$item->setPlural($plural);
......
......@@ -37,7 +37,7 @@ abstract class ContextAwarePluginBase extends PluginBase implements ContextAware
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
$context_configuration = isset($configuration['context']) ? $configuration['context'] : [];
$context_configuration = $configuration['context'] ?? [];
unset($configuration['context']);
parent::__construct($configuration, $plugin_id, $plugin_definition);
......
......@@ -260,7 +260,7 @@ protected function lookupReplacement($code, $unknown_character = '?') {
$this->readGenericData($bank);
}
$code = $code & 0xff;
return isset($this->genericMap[$bank][$code]) ? $this->genericMap[$bank][$code] : $unknown_character;
return $this->genericMap[$bank][$code] ?? $unknown_character;
}
/**
......
......@@ -68,7 +68,7 @@ public static function getBestMatchingLangcode($http_accept_language, $langcodes
// to the same langcode for different qvalues. Keep the highest.
$ua_langcodes[$langcode] = max(
(int) ($qvalue * 1000),
(isset($ua_langcodes[$langcode]) ? $ua_langcodes[$langcode] : 0)
($ua_langcodes[$langcode] ?? 0)
);
}
}
......@@ -113,7 +113,7 @@ public static function getBestMatchingLangcode($http_accept_language, $langcodes
// If nothing matches below, the default qvalue is the one of the wildcard
// language, if set, or is 0 (which will never match).
$qvalue = isset($ua_langcodes['*']) ? $ua_langcodes['*'] : 0;
$qvalue = $ua_langcodes['*'] ?? 0;
// Find the longest possible prefix of the user agent supplied language
// ('the language-range') that matches this site language ('the language
......
......@@ -138,9 +138,9 @@ protected function buildAttachmentsCommands(AjaxResponse $response, Request $req
// Resolve the attached libraries into asset collections.
$assets = new AttachedAssets();
$assets->setLibraries(isset($attachments['library']) ? $attachments['library'] : [])
$assets->setLibraries($attachments['library'] ?? [])
->setAlreadyLoadedLibraries(isset($ajax_page_state['libraries']) ? explode(',', $ajax_page_state['libraries']) : [])
->setSettings(isset($attachments['drupalSettings']) ? $attachments['drupalSettings'] : []);
->setSettings($attachments['drupalSettings'] ?? []);
$css_assets = $this->assetResolver->getCssAssets($assets, $optimize_css);
list($js_assets_header, $js_assets_footer) = $this->assetResolver->getJsAssets($assets, $optimize_js);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment