diff --git a/core/includes/form.inc b/core/includes/form.inc index 17ca32c03f..f605920457 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -1036,17 +1036,13 @@ function _batch_populate_queue(&$batch, $set_id) { function _batch_queue($batch_set) { static $queues; - if (!isset($queues)) { - $queues = []; - } + $queues ??= []; if (isset($batch_set['queue'])) { $name = $batch_set['queue']['name']; $class = $batch_set['queue']['class']; - if (!isset($queues[$class][$name])) { - $queues[$class][$name] = new $class($name, \Drupal::database()); - } + $queues[$class][$name] ??= new $class($name, \Drupal::database()); return $queues[$class][$name]; } } diff --git a/core/includes/module.inc b/core/includes/module.inc index 02a4f5d41f..bf0eae87de 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -41,9 +41,7 @@ */ function module_load_include($type, $module, $name = NULL) { @trigger_error("module_load_include() is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. Instead, you should use \Drupal::moduleHandler()->loadInclude(). Note that including code from uninstalled extensions is no longer supported. See https://www.drupal.org/node/2948698", E_USER_DEPRECATED); - if (!isset($name)) { - $name = $module; - } + $name ??= $module; if (\Drupal::hasService('extension.list.module')) { /** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */ diff --git a/core/includes/theme.inc b/core/includes/theme.inc index ba8f4ee7b7..e2c59851b2 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -267,9 +267,7 @@ function theme_get_setting($setting_name, $theme = NULL) { $cache = &drupal_static(__FUNCTION__, []); // If no key is given, use the current theme if we can determine it. - if (!isset($theme)) { - $theme = \Drupal::theme()->getActiveTheme()->getName(); - } + $theme ??= \Drupal::theme()->getActiveTheme()->getName(); if (empty($cache[$theme])) { // Create a theme settings object. @@ -1163,9 +1161,7 @@ function template_preprocess_container(&$variables) { // Special handling for form elements. if (isset($element['#array_parents'])) { // Assign an html ID. - if (!isset($element['#attributes']['id'])) { - $element['#attributes']['id'] = $element['#id']; - } + $element['#attributes']['id'] ??= $element['#id']; $variables['has_parent'] = TRUE; } @@ -1226,9 +1222,7 @@ function template_preprocess(&$variables, $hook, $info) { $drupal_static_fast['default_variables'] = &drupal_static(__FUNCTION__); } $default_variables = &$drupal_static_fast['default_variables']; - if (!isset($default_variables)) { - $default_variables = _template_preprocess_default_variables(); - } + $default_variables ??= _template_preprocess_default_variables(); $variables += $default_variables; // When theming a render element, merge its #attributes into @@ -1369,9 +1363,7 @@ function template_preprocess_page(&$variables) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); foreach (\Drupal::theme()->getActiveTheme()->getRegions() as $region) { - if (!isset($variables['page'][$region])) { - $variables['page'][$region] = []; - } + $variables['page'][$region] ??= []; } $variables['base_path'] = base_path(); @@ -1568,9 +1560,7 @@ function template_preprocess_field(&$variables, $hook) { $variables['multiple'] = $element['#is_multiple']; static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute(); - } + $default_attributes ??= new Attribute(); // Merge attributes when a single-value field has a hidden label. if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && !empty($element['#items'][0]->_attributes)) { diff --git a/core/includes/update.inc b/core/includes/update.inc index ae13309396..1cbfb2477d 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -189,12 +189,8 @@ function update_do_one($module, $number, $dependency_map, &$context) { unset($context['sandbox']['#finished']); } - if (!isset($context['results'][$module])) { - $context['results'][$module] = []; - } - if (!isset($context['results'][$module][$number])) { - $context['results'][$module][$number] = []; - } + $context['results'][$module] ??= []; + $context['results'][$module][$number] ??= []; $context['results'][$module][$number] = array_merge($context['results'][$module][$number], $ret); if (!empty($ret['#abort'])) { @@ -259,9 +255,7 @@ function update_invoke_post_update($function, &$context) { $context['finished'] = $context['sandbox']['#finished']; unset($context['sandbox']['#finished']); } - if (!isset($context['results'][$extension][$name])) { - $context['results'][$extension][$name] = []; - } + $context['results'][$extension][$name] ??= []; $context['results'][$extension][$name] = array_merge($context['results'][$extension][$name], $ret); if (!empty($ret['#abort'])) { @@ -357,9 +351,7 @@ function update_get_update_list() { $replacements = ['', '$2', '', '']; $description = preg_replace($patterns, $replacements, $func->getDocComment()); $ret[$module]['pending'][$update] = "$update - $description"; - if (!isset($ret[$module]['start'])) { - $ret[$module]['start'] = $update; - } + $ret[$module]['start'] ??= $update; } } if (!isset($ret[$module]['start']) && isset($ret[$module]['pending'])) { diff --git a/core/lib/Drupal/Component/Graph/Graph.php b/core/lib/Drupal/Component/Graph/Graph.php index 6fe9cf21b0..cbd0511d5f 100644 --- a/core/lib/Drupal/Component/Graph/Graph.php +++ b/core/lib/Drupal/Component/Graph/Graph.php @@ -75,9 +75,7 @@ public function searchAndSort() { foreach ($state['last_visit_order'] as $vertex) { $component = $this->graph[$vertex]['component']; - if (!isset($component_weights[$component])) { - $component_weights[$component] = 0; - } + $component_weights[$component] ??= 0; $this->graph[$vertex]['weight'] = $component_weights[$component]--; } @@ -100,9 +98,7 @@ public function searchAndSort() { */ protected function depthFirstSearch(&$state, $start, &$component = NULL) { // Assign new component for each new vertex, i.e. when not called recursively. - if (!isset($component)) { - $component = $start; - } + $component ??= $start; // Nothing to do, if we already visited this vertex. if (isset($this->graph[$start]['paths'])) { return; diff --git a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php index 6574c5b3da..db985a16d8 100644 --- a/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php +++ b/core/lib/Drupal/Component/Plugin/LazyPluginCollection.php @@ -116,9 +116,7 @@ public function remove($instance_id) { * (optional) The configuration used by this instance. Defaults to NULL. */ public function addInstanceId($id, $configuration = NULL) { - if (!isset($this->instanceIds[$id])) { - $this->instanceIds[$id] = $id; - } + $this->instanceIds[$id] ??= $id; } /** diff --git a/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php b/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php index 8a0e9c9d9f..71427174f2 100644 --- a/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php +++ b/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php @@ -198,9 +198,7 @@ public static function counter() { // once with the same parameters. static $count; - if (!isset($count)) { - $count = 0; - } + $count ??= 0; $count++; diff --git a/core/modules/block/src/Entity/Block.php b/core/modules/block/src/Entity/Block.php index ece8de38ab..01b7428bb9 100644 --- a/core/modules/block/src/Entity/Block.php +++ b/core/modules/block/src/Entity/Block.php @@ -281,9 +281,7 @@ public function setVisibilityConfig($instance_id, array $configuration) { * {@inheritdoc} */ public function getVisibilityConditions() { - if (!isset($this->visibilityCollection)) { - $this->visibilityCollection = new ConditionPluginCollection($this->conditionPluginManager(), $this->get('visibility')); - } + $this->visibilityCollection ??= new ConditionPluginCollection($this->conditionPluginManager(), $this->get('visibility')); return $this->visibilityCollection; } @@ -301,9 +299,7 @@ public function getVisibilityCondition($instance_id) { * The condition plugin manager. */ protected function conditionPluginManager() { - if (!isset($this->conditionPluginManager)) { - $this->conditionPluginManager = \Drupal::service('plugin.manager.condition'); - } + $this->conditionPluginManager ??= \Drupal::service('plugin.manager.condition'); return $this->conditionPluginManager; } diff --git a/core/modules/book/src/Form/BookOutlineForm.php b/core/modules/book/src/Form/BookOutlineForm.php index 0bf60353ce..444c1d92bf 100644 --- a/core/modules/book/src/Form/BookOutlineForm.php +++ b/core/modules/book/src/Form/BookOutlineForm.php @@ -83,9 +83,7 @@ public function form(array $form, FormStateInterface $form_state) { } // Find the depth limit for the parent select. - if (!isset($this->entity->book['parent_depth_limit'])) { - $this->entity->book['parent_depth_limit'] = $this->bookManager->getParentDepthLimit($this->entity->book); - } + $this->entity->book['parent_depth_limit'] ??= $this->bookManager->getParentDepthLimit($this->entity->book); $form = $this->bookManager->addFormElements($form, $form_state, $this->entity, $this->currentUser(), FALSE); return $form; diff --git a/core/modules/book/src/ProxyClass/BookManager.php b/core/modules/book/src/ProxyClass/BookManager.php index 8ee2568989..dd297a45ca 100644 --- a/core/modules/book/src/ProxyClass/BookManager.php +++ b/core/modules/book/src/ProxyClass/BookManager.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/book/src/ProxyClass/BookUninstallValidator.php b/core/modules/book/src/ProxyClass/BookUninstallValidator.php index 2ba59bf055..79a987309c 100644 --- a/core/modules/book/src/ProxyClass/BookUninstallValidator.php +++ b/core/modules/book/src/ProxyClass/BookUninstallValidator.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/breakpoint/src/BreakpointManager.php b/core/modules/breakpoint/src/BreakpointManager.php index 070b0bf043..f339e3b5d5 100644 --- a/core/modules/breakpoint/src/BreakpointManager.php +++ b/core/modules/breakpoint/src/BreakpointManager.php @@ -167,9 +167,7 @@ public function getBreakpointsByGroup($group) { $instances = []; foreach ($this->breakpointsByGroup[$group] as $plugin_id => $definition) { - if (!isset($this->instances[$plugin_id])) { - $this->instances[$plugin_id] = $this->createInstance($plugin_id); - } + $this->instances[$plugin_id] ??= $this->createInstance($plugin_id); $instances[$plugin_id] = $this->instances[$plugin_id]; } return $instances; @@ -186,9 +184,7 @@ public function getGroups() { else { $groups = []; foreach ($this->getDefinitions() as $plugin_definition) { - if (!isset($groups[$plugin_definition['group']])) { - $groups[$plugin_definition['group']] = $plugin_definition['group']; - } + $groups[$plugin_definition['group']] ??= $plugin_definition['group']; } $this->cacheBackend->set($this->cacheKey . '::groups', $groups, Cache::PERMANENT, ['breakpoints']); } diff --git a/core/modules/ckeditor5/ckeditor5.module b/core/modules/ckeditor5/ckeditor5.module index 561795fa95..d319dd5d7e 100644 --- a/core/modules/ckeditor5/ckeditor5.module +++ b/core/modules/ckeditor5/ckeditor5.module @@ -600,9 +600,7 @@ function ckeditor5_config_schema_info_alter(&$definitions) { */ function _ckeditor5_theme_css($theme = NULL): array { $css = []; - if (!isset($theme)) { - $theme = \Drupal::config('system.theme')->get('default'); - } + $theme ??= \Drupal::config('system.theme')->get('default'); if (isset($theme) && $theme_path = \Drupal::service('extension.list.theme')->getPath($theme)) { $info = \Drupal::service('extension.list.theme')->getExtensionInfo($theme); if (isset($info['ckeditor5-stylesheets']) && $info['ckeditor5-stylesheets'] !== FALSE) { diff --git a/core/modules/comment/src/CommentManager.php b/core/modules/comment/src/CommentManager.php index ba26943fe4..084cf84cd5 100644 --- a/core/modules/comment/src/CommentManager.php +++ b/core/modules/comment/src/CommentManager.php @@ -151,14 +151,12 @@ public function addBodyField($comment_type_id) { * {@inheritdoc} */ public function forbiddenMessage(EntityInterface $entity, $field_name) { - if (!isset($this->authenticatedCanPostComments)) { - // We only output a link if we are certain that users will get the - // permission to post comments by logging in. - $this->authenticatedCanPostComments = $this->entityTypeManager - ->getStorage('user_role') - ->load(RoleInterface::AUTHENTICATED_ID) - ->hasPermission('post comments'); - } + // We only output a link if we are certain that users will get the + // permission to post comments by logging in. + $this->authenticatedCanPostComments ??= $this->entityTypeManager + ->getStorage('user_role') + ->load(RoleInterface::AUTHENTICATED_ID) + ->hasPermission('post comments'); if ($this->authenticatedCanPostComments) { // We cannot use the redirect.destination service here because these links diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index 5b38f4549e..16a5fd508d 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -124,11 +124,9 @@ public function create(FieldableEntityInterface $entity, $fields) { if ($entity instanceof EntityOwnerInterface) { $last_comment_uid = $entity->getOwnerId(); } - if (!isset($last_comment_uid)) { - // Default to current user when entity does not implement - // EntityOwnerInterface or author is not set. - $last_comment_uid = $this->currentUser->id(); - } + // Default to current user when entity does not implement + // EntityOwnerInterface or author is not set. + $last_comment_uid ??= $this->currentUser->id(); // Default to REQUEST_TIME when entity does not have a changed property. $last_comment_timestamp = REQUEST_TIME; // @todo Make comment statistics language aware and add some tests. See @@ -241,11 +239,9 @@ public function update(CommentInterface $comment) { if ($entity instanceof EntityOwnerInterface) { $last_comment_uid = $entity->getOwnerId(); } - if (!isset($last_comment_uid)) { - // Default to current user when entity does not implement - // EntityOwnerInterface or author is not set. - $last_comment_uid = $this->currentUser->id(); - } + // Default to current user when entity does not implement + // EntityOwnerInterface or author is not set. + $last_comment_uid ??= $this->currentUser->id(); $this->database->update('comment_entity_statistics') ->fields([ 'cid' => 0, diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php index 0e4e024dd5..235456a1ee 100644 --- a/core/modules/comment/src/CommentViewBuilder.php +++ b/core/modules/comment/src/CommentViewBuilder.php @@ -164,9 +164,7 @@ public function buildComponents(array &$build, array $entities, array $displays, ]; } - if (!isset($build[$id]['#attached'])) { - $build[$id]['#attached'] = []; - } + $build[$id]['#attached'] ??= []; $build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer'; if ($attach_history && $is_node) { $build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator'; diff --git a/core/modules/config/src/Controller/ConfigController.php b/core/modules/config/src/Controller/ConfigController.php index 0c0f486865..f2375d05dc 100644 --- a/core/modules/config/src/Controller/ConfigController.php +++ b/core/modules/config/src/Controller/ConfigController.php @@ -171,9 +171,7 @@ public function downloadExport() { * Table showing a two-way diff between the active and staged configuration. */ public function diff($source_name, $target_name = NULL, $collection = NULL) { - if (!isset($collection)) { - $collection = StorageInterface::DEFAULT_COLLECTION; - } + $collection ??= StorageInterface::DEFAULT_COLLECTION; $syncStorage = $this->importTransformer->transform($this->syncStorage); $diff = $this->configManager->diff($this->targetStorage, $syncStorage, $source_name, $target_name, $collection); $this->diffFormatter->show_header = FALSE; diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php index a4894b99f1..6b9ea93f9c 100644 --- a/core/modules/content_translation/src/ContentTranslationHandler.php +++ b/core/modules/content_translation/src/ContentTranslationHandler.php @@ -596,9 +596,7 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat // @todo Find a more reliable way to determine if a form element concerns a // multilingual value. - if (!isset($ignored_types)) { - $ignored_types = array_flip(['actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details', 'link']); - } + $ignored_types ??= array_flip(['actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details', 'link']); /** @var \Drupal\Core\Entity\ContentEntityForm $form_object */ $form_object = $form_state->getFormObject(); diff --git a/core/modules/dblog/src/Plugin/views/filter/DblogTypes.php b/core/modules/dblog/src/Plugin/views/filter/DblogTypes.php index ed8f547166..4e4d200c55 100644 --- a/core/modules/dblog/src/Plugin/views/filter/DblogTypes.php +++ b/core/modules/dblog/src/Plugin/views/filter/DblogTypes.php @@ -16,9 +16,7 @@ class DblogTypes extends InOperator { * {@inheritdoc} */ public function getValueOptions() { - if (!isset($this->valueOptions)) { - $this->valueOptions = _dblog_get_message_types(); - } + $this->valueOptions ??= _dblog_get_message_types(); return $this->valueOptions; } diff --git a/core/modules/field/src/ProxyClass/FieldUninstallValidator.php b/core/modules/field/src/ProxyClass/FieldUninstallValidator.php index 0861eea532..f45037d55f 100644 --- a/core/modules/field/src/ProxyClass/FieldUninstallValidator.php +++ b/core/modules/field/src/ProxyClass/FieldUninstallValidator.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/file/src/Plugin/views/filter/Status.php b/core/modules/file/src/Plugin/views/filter/Status.php index 181c3d85a6..e44bcd023f 100644 --- a/core/modules/file/src/Plugin/views/filter/Status.php +++ b/core/modules/file/src/Plugin/views/filter/Status.php @@ -15,12 +15,10 @@ class Status extends InOperator { public function getValueOptions() { - if (!isset($this->valueOptions)) { - $this->valueOptions = [ - 0 => $this->t('Temporary'), - FileInterface::STATUS_PERMANENT => $this->t('Permanent'), - ]; - } + $this->valueOptions ??= [ + 0 => $this->t('Temporary'), + FileInterface::STATUS_PERMANENT => $this->t('Permanent'), + ]; return $this->valueOptions; } diff --git a/core/modules/file/src/Validation/UploadedFileValidator.php b/core/modules/file/src/Validation/UploadedFileValidator.php index 984b06f987..c9fce8021d 100644 --- a/core/modules/file/src/Validation/UploadedFileValidator.php +++ b/core/modules/file/src/Validation/UploadedFileValidator.php @@ -47,9 +47,7 @@ public function validate(UploadedFile $uploadedFile, array $options = []): Const * The Symfony validator. */ protected function getValidator(): ValidatorInterface { - if (!isset($this->validator)) { - $this->validator = $this->validatorFactory->createValidator(); - } + $this->validator ??= $this->validatorFactory->createValidator(); return $this->validator; } diff --git a/core/modules/file/tests/src/Functional/FileManagedTestBase.php b/core/modules/file/tests/src/Functional/FileManagedTestBase.php index aa34b29827..aad51e4782 100644 --- a/core/modules/file/tests/src/Functional/FileManagedTestBase.php +++ b/core/modules/file/tests/src/Functional/FileManagedTestBase.php @@ -181,20 +181,16 @@ public function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { * File URI. */ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { - if (!isset($filepath)) { - // Prefix with non-latin characters to ensure that all file-related - // tests work with international filenames. - // cSpell:disable-next-line - $filepath = 'Файл для тестирования ' . $this->randomMachineName(); - } + // Prefix with non-latin characters to ensure that all file-related + // tests work with international filenames. + // cSpell:disable-next-line + $filepath ??= 'Файл для тестирования ' . $this->randomMachineName(); if (!isset($scheme)) { $scheme = 'public'; } $filepath = $scheme . '://' . $filepath; - if (!isset($contents)) { - $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; - } + $contents ??= "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; file_put_contents($filepath, $contents); $this->assertFileExists($filepath); diff --git a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php index 19ca6f584a..5456116846 100644 --- a/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php +++ b/core/modules/file/tests/src/Kernel/FileManagedUnitTestBase.php @@ -194,20 +194,16 @@ public function createFile($filepath = NULL, $contents = NULL, $scheme = NULL) { * File URI. */ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { - if (!isset($filepath)) { - // Prefix with non-latin characters to ensure that all file-related - // tests work with international filenames. - // cSpell:disable-next-line - $filepath = 'Файл для тестирования ' . $this->randomMachineName(); - } + // Prefix with non-latin characters to ensure that all file-related + // tests work with international filenames. + // cSpell:disable-next-line + $filepath ??= 'Файл для тестирования ' . $this->randomMachineName(); if (!isset($scheme)) { $scheme = 'public'; } $filepath = $scheme . '://' . $filepath; - if (!isset($contents)) { - $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; - } + $contents ??= "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; file_put_contents($filepath, $contents); $this->assertFileExists($filepath); diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index c6cae99e5a..a5059506db 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -210,9 +210,7 @@ function filter_get_formats_by_role($rid) { * @see filter_fallback_format() */ function filter_default_format(AccountInterface $account = NULL) { - if (!isset($account)) { - $account = \Drupal::currentUser(); - } + $account ??= \Drupal::currentUser(); // Get a list of formats for this user, ordered by weight. The first one // available is the user's default format. $formats = filter_formats($account); diff --git a/core/modules/filter/src/ProxyClass/FilterUninstallValidator.php b/core/modules/filter/src/ProxyClass/FilterUninstallValidator.php index 2e7ccc184c..fbc2b4583b 100644 --- a/core/modules/filter/src/ProxyClass/FilterUninstallValidator.php +++ b/core/modules/filter/src/ProxyClass/FilterUninstallValidator.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/forum/src/ProxyClass/ForumUninstallValidator.php b/core/modules/forum/src/ProxyClass/ForumUninstallValidator.php index 7d9469e19f..e832b190a0 100644 --- a/core/modules/forum/src/ProxyClass/ForumUninstallValidator.php +++ b/core/modules/forum/src/ProxyClass/ForumUninstallValidator.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/help/src/Plugin/Search/HelpSearch.php b/core/modules/help/src/Plugin/Search/HelpSearch.php index e59d67549d..58b49ccced 100644 --- a/core/modules/help/src/Plugin/Search/HelpSearch.php +++ b/core/modules/help/src/Plugin/Search/HelpSearch.php @@ -277,14 +277,10 @@ protected function prepareResults(StatementInterface $found) { $keys = $this->getKeywords(); foreach ($found as $item) { $section_plugin_id = $item->section_plugin_id; - if (!isset($plugins[$section_plugin_id])) { - $plugins[$section_plugin_id] = $this->getSectionPlugin($section_plugin_id); - } + $plugins[$section_plugin_id] ??= $this->getSectionPlugin($section_plugin_id); if ($plugins[$section_plugin_id]) { $langcode = $item->langcode; - if (!isset($languages[$langcode])) { - $languages[$langcode] = $this->languageManager->getLanguage($item->langcode); - } + $languages[$langcode] ??= $this->languageManager->getLanguage($item->langcode); $topic = $plugins[$section_plugin_id]->renderTopicForSearch($item->topic_id, $languages[$langcode]); if ($topic) { if (isset($topic['cacheable_metadata'])) { @@ -346,9 +342,7 @@ public function updateIndex() { try { foreach ($items as $item) { $section_plugin_id = $item->section_plugin_id; - if (!isset($section_plugins[$section_plugin_id])) { - $section_plugins[$section_plugin_id] = $this->getSectionPlugin($section_plugin_id); - } + $section_plugins[$section_plugin_id] ??= $this->getSectionPlugin($section_plugin_id); if (!$section_plugins[$section_plugin_id]) { $this->removeItemsFromIndex($item->sid); diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 2870e37b88..5811234b9e 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -105,9 +105,7 @@ function history_read_multiple($nids) { */ function history_write($nid, $account = NULL) { - if (!isset($account)) { - $account = \Drupal::currentUser(); - } + $account ??= \Drupal::currentUser(); if ($account->isAuthenticated()) { $request_time = \Drupal::time()->getRequestTime(); diff --git a/core/modules/image/src/Form/ImageStyleDeleteForm.php b/core/modules/image/src/Form/ImageStyleDeleteForm.php index a0aea333b5..0fa96cc0db 100644 --- a/core/modules/image/src/Form/ImageStyleDeleteForm.php +++ b/core/modules/image/src/Form/ImageStyleDeleteForm.php @@ -77,9 +77,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { * An option list suitable for the form select '#options'. */ protected function getReplacementOptions() { - if (!isset($this->replacementOptions)) { - $this->replacementOptions = array_diff_key(image_style_options(), [$this->getEntity()->id() => '']); - } + $this->replacementOptions ??= array_diff_key(image_style_options(), [$this->getEntity()->id() => '']); return $this->replacementOptions; } diff --git a/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifierTrait.php b/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifierTrait.php index b7b65586e5..cec970247d 100644 --- a/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifierTrait.php +++ b/core/modules/jsonapi/src/JsonApiResource/ResourceIdentifierTrait.php @@ -47,9 +47,7 @@ public function getTypeName() { * {@inheritdoc} */ public function getResourceType() { - if (!isset($this->resourceType)) { - $this->resourceType = $this->resourceIdentifier->getResourceType(); - } + $this->resourceType ??= $this->resourceIdentifier->getResourceType(); return $this->resourceType; } diff --git a/core/modules/jsonapi/src/Query/Filter.php b/core/modules/jsonapi/src/Query/Filter.php index ab134317c4..a2ada166b1 100644 --- a/core/modules/jsonapi/src/Query/Filter.php +++ b/core/modules/jsonapi/src/Query/Filter.php @@ -232,9 +232,7 @@ protected static function expand(array $original) { */ protected static function expandItem($filter_index, array $filter_item) { if (isset($filter_item[EntityCondition::VALUE_KEY])) { - if (!isset($filter_item[EntityCondition::PATH_KEY])) { - $filter_item[EntityCondition::PATH_KEY] = $filter_index; - } + $filter_item[EntityCondition::PATH_KEY] ??= $filter_index; $filter_item = [ static::CONDITION_KEY => $filter_item, @@ -242,9 +240,7 @@ protected static function expandItem($filter_index, array $filter_item) { ]; } - if (!isset($filter_item[static::CONDITION_KEY][EntityCondition::OPERATOR_KEY])) { - $filter_item[static::CONDITION_KEY][EntityCondition::OPERATOR_KEY] = '='; - } + $filter_item[static::CONDITION_KEY][EntityCondition::OPERATOR_KEY] ??= '='; return $filter_item; } diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php index 993ff5b57b..49d6a7321b 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php @@ -90,9 +90,7 @@ protected static function toCollectionResourceResponse(array $responses, $self_l unset($merged_document['links']); } else { - if (!isset($merged_document['data'])) { - $merged_document['data'] = $is_multiple ? [] : NULL; - } + $merged_document['data'] ??= $is_multiple ? [] : NULL; $merged_document['links'] = [ 'self' => [ 'href' => $self_link, diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php index be0c633adc..184df68b4e 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php @@ -1257,9 +1257,7 @@ protected function getExpectedCollectionResponse(array $collection, $self_link, $merged_response = static::toCollectionResourceResponse($individual_responses, $self_link, TRUE); $merged_document = $merged_response->getResponseData(); - if (!isset($merged_document['data'])) { - $merged_document['data'] = []; - } + $merged_document['data'] ??= []; $cacheability = static::getExpectedCollectionCacheability($this->account, $collection, NULL, $filtered); $cacheability->setCacheMaxAge($merged_response->getCacheableMetadata()->getCacheMaxAge()); diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 4ac86e6802..0180e5c1e0 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -122,12 +122,8 @@ function language_element_info_alter(&$type) { // Alter the language_select element so that it will be rendered like a select // field. if (isset($type['language_select'])) { - if (!isset($type['language_select']['#process'])) { - $type['language_select']['#process'] = []; - } - if (!isset($type['language_select']['#theme_wrappers'])) { - $type['language_select']['#theme_wrappers'] = []; - } + $type['language_select']['#process'] ??= []; + $type['language_select']['#theme_wrappers'] ??= []; $type['language_select']['#process'] = array_merge($type['language_select']['#process'], [ 'language_process_language_select', ['Drupal\Core\Render\Element\Select', 'processSelect'], diff --git a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php index 67ae7dfa99..eb4f6e627b 100644 --- a/core/modules/language/src/Config/LanguageConfigFactoryOverride.php +++ b/core/modules/language/src/Config/LanguageConfigFactoryOverride.php @@ -115,9 +115,7 @@ public function getOverride($langcode, $name) { * {@inheritdoc} */ public function getStorage($langcode) { - if (!isset($this->storages[$langcode])) { - $this->storages[$langcode] = $this->baseStorage->createCollection($this->createConfigCollectionName($langcode)); - } + $this->storages[$langcode] ??= $this->baseStorage->createCollection($this->createConfigCollectionName($langcode)); return $this->storages[$langcode]; } diff --git a/core/modules/language/src/Form/NegotiationConfigureForm.php b/core/modules/language/src/Form/NegotiationConfigureForm.php index d25305f030..75ce4781fa 100644 --- a/core/modules/language/src/Form/NegotiationConfigureForm.php +++ b/core/modules/language/src/Form/NegotiationConfigureForm.php @@ -251,9 +251,7 @@ protected function configureFormTable(array &$form, $type) { // Add missing data to the methods lists. foreach ($negotiation_info as $method_id => $method) { - if (!isset($methods_weight[$method_id])) { - $methods_weight[$method_id] = $method['weight'] ?? 0; - } + $methods_weight[$method_id] ??= $method['weight'] ?? 0; } // Order methods list by weight. diff --git a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php index 3aed7ecc2a..550b0c71f7 100644 --- a/core/modules/language/src/HttpKernel/PathProcessorLanguage.php +++ b/core/modules/language/src/HttpKernel/PathProcessorLanguage.php @@ -102,9 +102,7 @@ public function processInbound($path, Request $request) { * {@inheritdoc} */ public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) { - if (!isset($this->multilingual)) { - $this->multilingual = $this->languageManager->isMultilingual(); - } + $this->multilingual ??= $this->languageManager->isMultilingual(); if ($this->multilingual) { $this->negotiator->reset(); $scope = 'outbound'; diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php index 12f349a461..b3d833b53e 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationContentEntity.php @@ -121,9 +121,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL, unset($options['language']); } - if (!isset($options['query'][static::QUERY_PARAMETER])) { - $options['query'][static::QUERY_PARAMETER] = $langcode; - } + $options['query'][static::QUERY_PARAMETER] ??= $langcode; if ($bubbleable_metadata) { // Cached URLs that have been processed by this outbound path diff --git a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php index daa8cf8acd..ee6ee69ffa 100644 --- a/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php +++ b/core/modules/language/src/Plugin/LanguageNegotiation/LanguageNegotiationSession.php @@ -136,9 +136,7 @@ public function processOutbound($path, &$options = [], Request $request = NULL, // enabled, and the corresponding option has been set, we must preserve // any explicit user language preference even with cookies disabled. if ($this->queryRewrite) { - if (!isset($options['query'][$this->queryParam])) { - $options['query'][$this->queryParam] = $this->queryValue; - } + $options['query'][$this->queryParam] ??= $this->queryValue; if ($bubbleable_metadata) { // Cached URLs that have been processed by this outbound path // processor must be: diff --git a/core/modules/language/src/ProxyClass/LanguageConverter.php b/core/modules/language/src/ProxyClass/LanguageConverter.php index 5511c6859e..dfa7867771 100644 --- a/core/modules/language/src/ProxyClass/LanguageConverter.php +++ b/core/modules/language/src/ProxyClass/LanguageConverter.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/language/tests/language_events_test/src/EventSubscriber.php b/core/modules/language/tests/language_events_test/src/EventSubscriber.php index e805b9fc62..81c39ce616 100644 --- a/core/modules/language/tests/language_events_test/src/EventSubscriber.php +++ b/core/modules/language/tests/language_events_test/src/EventSubscriber.php @@ -37,9 +37,7 @@ public function configEventRecorder(LanguageConfigOverrideCrudEvent $event, stri // Record all events that occur. $all_events = $this->state->get('language_events_test.all_events', []); $override_name = $override->getName(); - if (!isset($all_events[$event_name][$override_name])) { - $all_events[$event_name][$override_name] = []; - } + $all_events[$event_name][$override_name] ??= []; $all_events[$event_name][$override_name][] = $event_info; $this->state->set('language_events_test.all_events', $all_events); } diff --git a/core/modules/layout_builder/src/Form/MoveBlockForm.php b/core/modules/layout_builder/src/Form/MoveBlockForm.php index beb3aa9757..ed8f21b1a5 100644 --- a/core/modules/layout_builder/src/Form/MoveBlockForm.php +++ b/core/modules/layout_builder/src/Form/MoveBlockForm.php @@ -187,9 +187,7 @@ public function buildForm(array $form, FormStateInterface $form_state, SectionSt $components = $current_section->getComponentsByRegion($selected_region); // If the component is not in this region, add it to the listed components. - if (!isset($components[$uuid])) { - $components[$uuid] = $sections[$delta]->getComponent($uuid); - } + $components[$uuid] ??= $sections[$delta]->getComponent($uuid); $state_weight_delta = round(count($components) / 2); foreach ($components as $component_uuid => $component) { /** @var \Drupal\Core\Block\BlockPluginInterface $plugin */ diff --git a/core/modules/layout_discovery/layout_discovery.module b/core/modules/layout_discovery/layout_discovery.module index 02bedc5353..262d918909 100644 --- a/core/modules/layout_discovery/layout_discovery.module +++ b/core/modules/layout_discovery/layout_discovery.module @@ -43,9 +43,7 @@ function template_preprocess_layout(&$variables) { // Create an attributes variable for each region. foreach (Element::children($variables['content']) as $name) { - if (!isset($variables['content'][$name]['#attributes'])) { - $variables['content'][$name]['#attributes'] = []; - } + $variables['content'][$name]['#attributes'] ??= []; $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']); } } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index b5e3270cea..f6f71109b0 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -246,9 +246,7 @@ function locale_translate_batch_import($file, array $options, &$context) { } foreach ($report as $key => $value) { if (is_numeric($report[$key])) { - if (!isset($context['results']['stats'][$file->uri][$key])) { - $context['results']['stats'][$file->uri][$key] = 0; - } + $context['results']['stats'][$file->uri][$key] ??= 0; $context['results']['stats'][$file->uri][$key] += $report[$key]; } elseif (is_array($value)) { @@ -638,9 +636,7 @@ function locale_config_batch_set_config_langcodes(&$context) { * @see locale_config_batch_build() */ function locale_config_batch_refresh_name(array $names, array $langcodes, &$context) { - if (!isset($context['results']['stats']['config'])) { - $context['results']['stats']['config'] = 0; - } + $context['results']['stats']['config'] ??= 0; $context['results']['stats']['config'] += Locale::config()->updateConfigTranslations($names, $langcodes); foreach ($names as $name) { $context['results']['names'][] = $name; diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 093823a29e..254fab0823 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -515,9 +515,7 @@ function locale_js_alter(&$javascript, AttachedAssetsInterface $assets, Language * applicable. */ function locale_js_translate(array $files = [], $language_interface = NULL) { - if (!isset($language_interface)) { - $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - } + $language_interface ??= \Drupal::languageManager()->getCurrentLanguage(); $dir = 'public://' . \Drupal::config('locale.settings')->get('javascript.directory'); $parsed = \Drupal::state()->get('system.javascript_parsed', []); diff --git a/core/modules/locale/src/LocaleTranslation.php b/core/modules/locale/src/LocaleTranslation.php index a9ccc93626..ba7cd8882a 100644 --- a/core/modules/locale/src/LocaleTranslation.php +++ b/core/modules/locale/src/LocaleTranslation.php @@ -115,9 +115,7 @@ public function getStringTranslation($langcode, $string, $context) { } // Strings are cached by langcode, context and roles, using instances of the // LocaleLookup class to handle string lookup and caching. - if (!isset($this->translations[$langcode][$context])) { - $this->translations[$langcode][$context] = new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack); - } + $this->translations[$langcode][$context] ??= new LocaleLookup($langcode, $context, $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack); $translation = $this->translations[$langcode][$context]->get($string); // If the translation is TRUE, no translation exists, but that string needs // to be stored in the persistent cache for performance reasons (so for @@ -134,9 +132,7 @@ public function getStringTranslation($langcode, $string, $context) { * TRUE if english should be translated, FALSE if not. */ protected function canTranslateEnglish() { - if (!isset($this->translateEnglish)) { - $this->translateEnglish = $this->configFactory->get('locale.settings')->get('translate_english'); - } + $this->translateEnglish ??= $this->configFactory->get('locale.settings')->get('translate_english'); return $this->translateEnglish; } diff --git a/core/modules/locale/src/PoDatabaseReader.php b/core/modules/locale/src/PoDatabaseReader.php index 4ed7663467..4e946b34d3 100644 --- a/core/modules/locale/src/PoDatabaseReader.php +++ b/core/modules/locale/src/PoDatabaseReader.php @@ -150,9 +150,7 @@ private function loadStrings() { * Get the database result resource for the given language and options. */ private function readString() { - if (!isset($this->result)) { - $this->result = $this->loadStrings(); - } + $this->result ??= $this->loadStrings(); return array_shift($this->result); } diff --git a/core/modules/locale/src/PoDatabaseWriter.php b/core/modules/locale/src/PoDatabaseWriter.php index 7e7340cf10..7720039fb6 100644 --- a/core/modules/locale/src/PoDatabaseWriter.php +++ b/core/modules/locale/src/PoDatabaseWriter.php @@ -121,9 +121,7 @@ public function getOptions() { * One of LOCALE_CUSTOMIZED or LOCALE_NOT_CUSTOMIZED. */ public function setOptions(array $options) { - if (!isset($options['overwrite_options'])) { - $options['overwrite_options'] = []; - } + $options['overwrite_options'] ??= []; $options['overwrite_options'] += [ 'not_customized' => FALSE, 'customized' => FALSE, diff --git a/core/modules/locale/src/TranslationString.php b/core/modules/locale/src/TranslationString.php index ac8ef1440b..2644596ed8 100644 --- a/core/modules/locale/src/TranslationString.php +++ b/core/modules/locale/src/TranslationString.php @@ -44,12 +44,10 @@ class TranslationString extends StringBase { */ public function __construct($values = []) { parent::__construct($values); - if (!isset($this->isNew)) { - // We mark the string as not new if it is a complete translation. - // This will work when loading from database, otherwise the storage - // controller that creates the string object must handle it. - $this->isNew = !$this->isTranslation(); - } + // We mark the string as not new if it is a complete translation. + // This will work when loading from database, otherwise the storage + // controller that creates the string object must handle it. + $this->isNew ??= !$this->isTranslation(); } /** diff --git a/core/modules/menu_ui/src/MenuForm.php b/core/modules/menu_ui/src/MenuForm.php index 9d90ac5a60..d847989c60 100644 --- a/core/modules/menu_ui/src/MenuForm.php +++ b/core/modules/menu_ui/src/MenuForm.php @@ -451,10 +451,8 @@ protected function buildOverviewTreeForm($tree, $delta) { uasort($operations, [SortArray::class, 'sortByWeightElement']); } foreach ($operations as $key => $operation) { - if (!isset($operations[$key]['query'])) { - // Bring the user back to the menu overview. - $operations[$key]['query'] = $this->getDestinationArray(); - } + // Bring the user back to the menu overview. + $operations[$key]['query'] ??= $this->getDestinationArray(); } $form[$id]['operations'] = [ '#type' => 'operations', diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index 47b887f376..1d6578ff60 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -125,9 +125,7 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa * The source. */ protected function getSource() { - if (!isset($this->source)) { - $this->source = $this->migration->getSourcePlugin(); - } + $this->source ??= $this->migration->getSourcePlugin(); return $this->source; } diff --git a/core/modules/migrate/src/Plugin/Migration.php b/core/modules/migrate/src/Plugin/Migration.php index f19a35e3e5..1f49e07930 100644 --- a/core/modules/migrate/src/Plugin/Migration.php +++ b/core/modules/migrate/src/Plugin/Migration.php @@ -388,9 +388,7 @@ public function getIdMapPlugin() { * {@inheritdoc} */ public function getSourcePlugin() { - if (!isset($this->sourcePlugin)) { - $this->sourcePlugin = $this->sourcePluginManager->createInstance($this->source['plugin'], $this->source, $this); - } + $this->sourcePlugin ??= $this->sourcePluginManager->createInstance($this->source['plugin'], $this->source, $this); return $this->sourcePlugin; } @@ -398,9 +396,7 @@ public function getSourcePlugin() { * {@inheritdoc} */ public function getProcessPlugins(array $process = NULL) { - if (!isset($process)) { - $process = $this->getProcess(); - } + $process ??= $this->getProcess(); $index = serialize($process); if (!isset($this->processPlugins[$index])) { $this->processPlugins[$index] = []; @@ -460,9 +456,7 @@ public function getDestinationPlugin($stub_being_requested = FALSE) { if ($stub_being_requested && !empty($this->destination['no_stub'])) { throw new MigrateSkipRowException('Stub requested but not made because no_stub configuration is set.'); } - if (!isset($this->destinationPlugin)) { - $this->destinationPlugin = $this->destinationPluginManager->createInstance($this->destination['plugin'], $this->destination, $this); - } + $this->destinationPlugin ??= $this->destinationPluginManager->createInstance($this->destination['plugin'], $this->destination, $this); return $this->destinationPlugin; } diff --git a/core/modules/migrate/src/Plugin/MigrationPluginManager.php b/core/modules/migrate/src/Plugin/MigrationPluginManager.php index 8725ac4756..65c4588e61 100644 --- a/core/modules/migrate/src/Plugin/MigrationPluginManager.php +++ b/core/modules/migrate/src/Plugin/MigrationPluginManager.php @@ -227,9 +227,7 @@ public function buildDependencyMigration(array $migrations, array $dynamic_ids) */ protected function addDependency(array &$graph, $id, $dependency, $dynamic_ids) { $dependencies = $dynamic_ids[$dependency] ?? [$dependency]; - if (!isset($graph[$id]['edges'])) { - $graph[$id]['edges'] = []; - } + $graph[$id]['edges'] ??= []; $graph[$id]['edges'] += array_combine($dependencies, $dependencies); } diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index 52b89c9999..f9319469c1 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -176,9 +176,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition $this->eventDispatcher = $event_dispatcher; $this->message = new MigrateMessage(); - if (!isset($this->database)) { - $this->database = \Drupal::database(); - } + $this->database ??= \Drupal::database(); // Default generated table names, limited to 63 characters. $machine_name = str_replace(':', '__', $this->migration->id()); diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index 3191c7256d..aede29e1e2 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -280,9 +280,7 @@ abstract protected function initializeIterator(); * The module handler. */ protected function getModuleHandler() { - if (!isset($this->moduleHandler)) { - $this->moduleHandler = \Drupal::moduleHandler(); - } + $this->moduleHandler ??= \Drupal::moduleHandler(); return $this->moduleHandler; } @@ -334,9 +332,7 @@ public function prepareRow(Row $row) { * The iterator that will yield the row arrays to be processed. */ protected function getIterator() { - if (!isset($this->iterator)) { - $this->iterator = $this->initializeIterator(); - } + $this->iterator ??= $this->initializeIterator(); return $this->iterator; } @@ -521,9 +517,7 @@ public function count($refresh = FALSE) { * The cache object. */ protected function getCache() { - if (!isset($this->cache)) { - $this->cache = \Drupal::cache('migrate'); - } + $this->cache ??= \Drupal::cache('migrate'); return $this->cache; } @@ -546,9 +540,7 @@ protected function doCount() { * The storage object. */ protected function getHighWaterStorage() { - if (!isset($this->highWaterStorage)) { - $this->highWaterStorage = \Drupal::keyValue('migrate:high_water'); - } + $this->highWaterStorage ??= \Drupal::keyValue('migrate:high_water'); return $this->highWaterStorage; } diff --git a/core/modules/mysql/src/Driver/Database/mysql/Schema.php b/core/modules/mysql/src/Driver/Database/mysql/Schema.php index 6fdcad7047..7f6d999960 100644 --- a/core/modules/mysql/src/Driver/Database/mysql/Schema.php +++ b/core/modules/mysql/src/Driver/Database/mysql/Schema.php @@ -204,9 +204,7 @@ protected function createFieldSql($name, $spec) { */ protected function processField($field) { - if (!isset($field['size'])) { - $field['size'] = 'normal'; - } + $field['size'] ??= 'normal'; // Set the correct database-engine specific datatype. // In case one is already provided, force it to uppercase. diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index a58487c1da..533f25baa9 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -758,9 +758,7 @@ protected function parseAdvancedDefaults($f, $keys) { // Split out the advanced search parameters. foreach ($f as $advanced) { [$key, $value] = explode(':', $advanced, 2); - if (!isset($defaults[$key])) { - $defaults[$key] = []; - } + $defaults[$key] ??= []; $defaults[$key][] = $value; } diff --git a/core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php b/core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php index 7dcd43e7ca..193143bb51 100644 --- a/core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php +++ b/core/modules/node/src/ProxyClass/ParamConverter/NodePreviewConverter.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php index 22cd0d9ac6..68de94839d 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php @@ -121,9 +121,7 @@ public static function processAllowedValuesKey(array &$element): array { // Override the default description which is not applicable to this use of // the machine name element given that it allows users to manually enter // characters usually not allowed in machine names. - if (!isset($element['#description'])) { - $element['#description'] = ''; - } + $element['#description'] ??= ''; return $element; } diff --git a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php index 2ff57aebee..c0f4127bb0 100644 --- a/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php +++ b/core/modules/pgsql/src/Driver/Database/pgsql/Schema.php @@ -206,9 +206,7 @@ public function queryTableInformation($table) { * PostgreSQL's temporary namespace name. */ protected function getTempNamespaceName() { - if (!isset($this->tempNamespaceName)) { - $this->tempNamespaceName = $this->connection->query('SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema()')->fetchField(); - } + $this->tempNamespaceName ??= $this->connection->query('SELECT nspname FROM pg_namespace WHERE oid = pg_my_temp_schema()')->fetchField(); return $this->tempNamespaceName; } @@ -384,9 +382,7 @@ protected function createFieldSql($name, $spec) { * A field description array, as specified in the schema documentation. */ protected function processField($field) { - if (!isset($field['size'])) { - $field['size'] = 'normal'; - } + $field['size'] ??= 'normal'; // Set the correct database-engine specific datatype. // In case one is already provided, force it to lowercase. @@ -405,9 +401,7 @@ protected function processField($field) { // The PostgreSQL schema in Drupal creates a check constraint // to ensure that a value inserted is >= 0. To provide the extra // integer capacity, here, we bump up the column field size. - if (!isset($map)) { - $map = $this->getFieldTypeMap(); - } + $map ??= $this->getFieldTypeMap(); switch ($field['pgsql_type']) { case 'smallint': $field['pgsql_type'] = $map['int:medium']; diff --git a/core/modules/rest/src/Entity/RestResourceConfig.php b/core/modules/rest/src/Entity/RestResourceConfig.php index 027eb5e6c5..515a3b5fb3 100644 --- a/core/modules/rest/src/Entity/RestResourceConfig.php +++ b/core/modules/rest/src/Entity/RestResourceConfig.php @@ -93,9 +93,7 @@ public function __construct(array $values, $entity_type) { * @return \Drupal\Component\Plugin\PluginManagerInterface */ protected function getResourcePluginManager() { - if (!isset($this->pluginManager)) { - $this->pluginManager = \Drupal::service('plugin.manager.rest'); - } + $this->pluginManager ??= \Drupal::service('plugin.manager.rest'); return $this->pluginManager; } diff --git a/core/modules/sdc/src/Twig/TwigExtension.php b/core/modules/sdc/src/Twig/TwigExtension.php index 8205080cb0..7fa2d511c3 100644 --- a/core/modules/sdc/src/Twig/TwigExtension.php +++ b/core/modules/sdc/src/Twig/TwigExtension.php @@ -87,9 +87,7 @@ public function addAdditionalContext(array &$context, string $component_id): voi protected function mergeAdditionalRenderContext(Component $component, array $context): array { $context['componentMetadata'] = $component->metadata->normalize(); $component_attributes = ['data-component-id' => $component->getPluginId()]; - if (!isset($context['attributes'])) { - $context['attributes'] = new Attribute($component_attributes); - } + $context['attributes'] ??= new Attribute($component_attributes); // If there is an "attributes" property, merge the additional attributes // into it if possible. elseif ($context['attributes'] instanceof Attribute) { diff --git a/core/modules/search/search.api.php b/core/modules/search/search.api.php index 47744998e3..1d4a295eaf 100644 --- a/core/modules/search/search.api.php +++ b/core/modules/search/search.api.php @@ -48,9 +48,7 @@ */ function hook_search_preprocess($text, $langcode = NULL) { // If the language is not set, get it from the language manager. - if (!isset($langcode)) { - $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); - } + $langcode ??= \Drupal::languageManager()->getCurrentLanguage()->getId(); // If the langcode is set to 'en' then add variations of the word "testing" // which can also be found during English language searches. diff --git a/core/modules/search/search.module b/core/modules/search/search.module index 84feabfed8..06ffe21cc0 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -178,9 +178,7 @@ function search_excerpt($keys, $text, $langcode = NULL) { // Remember where we last found $key, in case we are coming through a // second time. - if (!isset($look_start[$key])) { - $look_start[$key] = 0; - } + $look_start[$key] ??= 0; // See if we can find $key after where we found it the last time. Since // we are requiring a match on a word boundary, make sure $text starts diff --git a/core/modules/search/src/Entity/SearchPage.php b/core/modules/search/src/Entity/SearchPage.php index d5eef74a9c..883e7eb2ee 100644 --- a/core/modules/search/src/Entity/SearchPage.php +++ b/core/modules/search/src/Entity/SearchPage.php @@ -182,9 +182,7 @@ public function postCreate(EntityStorageInterface $storage) { // @todo Use self::applyDefaultValue() once // https://www.drupal.org/node/2004756 is in. - if (!isset($this->weight)) { - $this->weight = $this->isDefaultSearch() ? -10 : 0; - } + $this->weight ??= $this->isDefaultSearch() ? -10 : 0; } /** diff --git a/core/modules/search/src/SearchIndex.php b/core/modules/search/src/SearchIndex.php index 97f57abe12..999060429b 100644 --- a/core/modules/search/src/SearchIndex.php +++ b/core/modules/search/src/SearchIndex.php @@ -155,9 +155,7 @@ public function index($type, $sid, $langcode, $text, $update_weights = TRUE) { $accumulator .= $word . ' '; // Check word length. if (is_numeric($word) || mb_strlen($word) >= $minimum_word_size) { - if (!isset($scored_words[$word])) { - $scored_words[$word] = 0; - } + $scored_words[$word] ??= 0; $scored_words[$word] += $score * $focus; // Focus is a decaying value in terms of the amount of unique // words up to this point. From 100 words and more, it decays, to diff --git a/core/modules/settings_tray/settings_tray.module b/core/modules/settings_tray/settings_tray.module index 35a4466575..934c5d4bdb 100644 --- a/core/modules/settings_tray/settings_tray.module +++ b/core/modules/settings_tray/settings_tray.module @@ -169,9 +169,7 @@ function settings_tray_block_alter(&$definitions) { foreach ($definitions as &$definition) { // If a block plugin does not define its own 'settings_tray' form, use the // plugin class itself. - if (!isset($definition['forms']['settings_tray'])) { - $definition['forms']['settings_tray'] = $definition['class']; - } + $definition['forms']['settings_tray'] ??= $definition['class']; } } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index df1b9969c3..00a6701605 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -131,9 +131,7 @@ function shortcut_set_switch_access($account = NULL) { function shortcut_current_displayed_set($account = NULL) { $shortcut_sets = &drupal_static(__FUNCTION__, []); $user = \Drupal::currentUser(); - if (!isset($account)) { - $account = $user; - } + $account ??= $user; // Try to return a shortcut set from the static cache. if (isset($shortcut_sets[$account->id()])) { return $shortcut_sets[$account->id()]; @@ -168,9 +166,7 @@ function shortcut_current_displayed_set($account = NULL) { */ function shortcut_default_set($account = NULL) { $user = \Drupal::currentUser(); - if (!isset($account)) { - $account = $user; - } + $account ??= $user; // Allow modules to return a default shortcut set name. Since we can only // have one, we allow the last module which returns a valid result to take @@ -200,9 +196,7 @@ function shortcut_default_set($account = NULL) { function shortcut_renderable_links($shortcut_set = NULL) { $shortcut_links = []; - if (!isset($shortcut_set)) { - $shortcut_set = shortcut_current_displayed_set(); - } + $shortcut_set ??= shortcut_current_displayed_set(); $cache_tags = []; foreach ($shortcut_set->getShortcuts() as $shortcut) { diff --git a/core/modules/sqlite/src/Driver/Database/sqlite/Schema.php b/core/modules/sqlite/src/Driver/Database/sqlite/Schema.php index 64bdffa8c8..e3a6cca480 100644 --- a/core/modules/sqlite/src/Driver/Database/sqlite/Schema.php +++ b/core/modules/sqlite/src/Driver/Database/sqlite/Schema.php @@ -122,9 +122,7 @@ protected function createKeySql($fields) { * A field description array, as specified in the schema documentation. */ protected function processField($field) { - if (!isset($field['size'])) { - $field['size'] = 'normal'; - } + $field['size'] ??= 'normal'; // Set the correct database-engine specific datatype. // In case one is already provided, force it to uppercase. diff --git a/core/modules/system/src/PathBasedBreadcrumbBuilder.php b/core/modules/system/src/PathBasedBreadcrumbBuilder.php index 64985ed1ed..2c0606b1ce 100644 --- a/core/modules/system/src/PathBasedBreadcrumbBuilder.php +++ b/core/modules/system/src/PathBasedBreadcrumbBuilder.php @@ -178,11 +178,9 @@ public function build(RouteMatchInterface $route_match) { $breadcrumb = $breadcrumb->addCacheableDependency($access); if ($access->isAllowed()) { $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject()); - if (!isset($title)) { - // Fallback to using the raw path component as the title if the - // route is missing a _title or _title_callback attribute. - $title = str_replace(['-', '_'], ' ', Unicode::ucfirst(end($path_elements))); - } + // Fallback to using the raw path component as the title if the + // route is missing a _title or _title_callback attribute. + $title ??= str_replace(['-', '_'], ' ', Unicode::ucfirst(end($path_elements))); $url = Url::fromRouteMatch($route_match); $links[] = new Link($title, $url); } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 2de1283198..6441d1d919 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -743,13 +743,9 @@ function system_js_settings_alter(&$settings, AttachedAssetsInterface $assets) { // Only set core/drupalSettings values that haven't been set already. foreach ($path_settings as $key => $value) { - if (!isset($settings['path'][$key])) { - $settings['path'][$key] = $value; - } - } - if (!isset($settings['pluralDelimiter'])) { - $settings['pluralDelimiter'] = PoItem::DELIMITER; + $settings['path'][$key] ??= $value; } + $settings['pluralDelimiter'] ??= PoItem::DELIMITER; // Add the theme token to ajaxPageState, ensuring the database is available // before doing so. Also add the loaded libraries to ajaxPageState. /** @var \Drupal\Core\Asset\LibraryDependencyResolver $library_dependency_resolver */ diff --git a/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php b/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php index afa6f8df54..846203694a 100644 --- a/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php +++ b/core/modules/system/tests/src/Functional/Ajax/FrameworkTest.php @@ -148,9 +148,7 @@ protected function assertCommand(array $haystack, array $needle): void { */ protected function drupalGetAjax($path, array $options = [], array $headers = []) { $headers[] = 'X-Requested-With: XMLHttpRequest'; - if (!isset($options['query'][MainContentViewSubscriber::WRAPPER_FORMAT])) { - $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] = 'drupal_ajax'; - } + $options['query'][MainContentViewSubscriber::WRAPPER_FORMAT] ??= 'drupal_ajax'; return Json::decode($this->drupalGet($path, $options, $headers)); } diff --git a/core/modules/system/tests/src/Functional/Pager/PagerTest.php b/core/modules/system/tests/src/Functional/Pager/PagerTest.php index 9686d44dbb..b3551c4dc0 100644 --- a/core/modules/system/tests/src/Functional/Pager/PagerTest.php +++ b/core/modules/system/tests/src/Functional/Pager/PagerTest.php @@ -327,9 +327,7 @@ protected function assertPagerItems(int $current_page): void { * @internal */ protected function assertClass(NodeElement $element, string $class, string $message = NULL): void { - if (!isset($message)) { - $message = "Class .$class found."; - } + $message ??= "Class .$class found."; $this->assertTrue($element->hasClass($class), $message); } @@ -346,9 +344,7 @@ protected function assertClass(NodeElement $element, string $class, string $mess * @internal */ protected function assertNoClass(NodeElement $element, string $class, string $message = NULL): void { - if (!isset($message)) { - $message = "Class .$class not found."; - } + $message ??= "Class .$class not found."; $this->assertFalse($element->hasClass($class), $message); } diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php index b0b4d4f5dc..06beb124ee 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php @@ -119,9 +119,7 @@ public function testTaxonomyVocabularyTree() { // Count elements in every tree depth. foreach ($tree as $element) { - if (!isset($depth_count[$element->depth])) { - $depth_count[$element->depth] = 0; - } + $depth_count[$element->depth] ??= 0; $depth_count[$element->depth]++; } $this->assertEquals(3, $depth_count[0], 'Three elements in taxonomy tree depth 0.'); diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 5a6b85235d..e5a487e7bb 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -63,9 +63,7 @@ function text_help($route_name, RouteMatchInterface $route_match) { */ function text_summary($text, $format = NULL, $size = NULL) { - if (!isset($size)) { - $size = \Drupal::config('text.settings')->get('default_summary_length'); - } + $size ??= \Drupal::config('text.settings')->get('default_summary_length'); // Find where the delimiter is in the body. $delimiter = strpos($text, ''); diff --git a/core/modules/toolbar/src/Element/ToolbarItem.php b/core/modules/toolbar/src/Element/ToolbarItem.php index 2568b824b9..67b82e8b63 100644 --- a/core/modules/toolbar/src/Element/ToolbarItem.php +++ b/core/modules/toolbar/src/Element/ToolbarItem.php @@ -71,9 +71,7 @@ public static function preRenderToolbarItem($element) { 'data-toolbar-tray' => $id . '-tray', ]; // Merge in module-provided attributes. - if (!isset($element['tray']['#wrapper_attributes'])) { - $element['tray']['#wrapper_attributes'] = []; - } + $element['tray']['#wrapper_attributes'] ??= []; $element['tray']['#wrapper_attributes'] += $attributes; $element['tray']['#wrapper_attributes']['class'][] = 'toolbar-tray'; } diff --git a/core/modules/update/tests/src/Functional/UpdateSemverTestBase.php b/core/modules/update/tests/src/Functional/UpdateSemverTestBase.php index 666c7d8977..f59fa2268b 100644 --- a/core/modules/update/tests/src/Functional/UpdateSemverTestBase.php +++ b/core/modules/update/tests/src/Functional/UpdateSemverTestBase.php @@ -53,9 +53,7 @@ protected function setUp(): void { * {@inheritdoc} */ protected function refreshUpdateStatus($xml_map, $url = 'update-test') { - if (!isset($xml_map['drupal'])) { - $xml_map['drupal'] = '0.0'; - } + $xml_map['drupal'] ??= '0.0'; parent::refreshUpdateStatus($xml_map, $url); } diff --git a/core/modules/update/update.authorize.inc b/core/modules/update/update.authorize.inc index 742a3f159e..c4d0139ff4 100644 --- a/core/modules/update/update.authorize.inc +++ b/core/modules/update/update.authorize.inc @@ -131,16 +131,10 @@ function update_authorize_run_install($filetransfer, $project, $updater_name, $l function update_authorize_batch_copy_project($project, $updater_name, $local_url, $filetransfer, &$context) { // Initialize some variables in the Batch API $context array. - if (!isset($context['results']['log'])) { - $context['results']['log'] = []; - } - if (!isset($context['results']['log'][$project])) { - $context['results']['log'][$project] = []; - } + $context['results']['log'] ??= []; + $context['results']['log'][$project] ??= []; - if (!isset($context['results']['tasks'])) { - $context['results']['tasks'] = []; - } + $context['results']['tasks'] ??= []; // The batch API uses a session, and since all the arguments are serialized // and unserialized between requests, although the FileTransfer object itself diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc index 466ca09f68..c028ae620f 100644 --- a/core/modules/update/update.compare.inc +++ b/core/modules/update/update.compare.inc @@ -316,10 +316,8 @@ function update_calculate_project_update_status(&$project_data, $available) { continue; } } - if (!isset($target_major)) { - // If there are no valid support branches, use the current major. - $target_major = $existing_major; - } + // If there are no valid support branches, use the current major. + $target_major ??= $existing_major; } else { @@ -421,9 +419,7 @@ function update_calculate_project_update_status(&$project_data, $available) { // See if this is a higher major version than our target and yet still // supported. If so, record it as an "Also available" release. if ($release_major_version > $target_major) { - if (!isset($project_data['also'])) { - $project_data['also'] = []; - } + $project_data['also'] ??= []; if (!isset($project_data['also'][$release_major_version])) { $project_data['also'][$release_major_version] = $version; $project_data['releases'][$version] = $release_info; diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 4d3337beaa..5bf3e85f38 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -604,9 +604,7 @@ function update_storage_clear() { */ function _update_manager_unique_identifier() { static $id; - if (!isset($id)) { - $id = substr(hash('sha256', Settings::getHashSalt()), 0, 8); - } + $id ??= substr(hash('sha256', Settings::getHashSalt()), 0, 8); return $id; } diff --git a/core/modules/update/update.report.inc b/core/modules/update/update.report.inc index 8dbb17e094..893d17f5e0 100644 --- a/core/modules/update/update.report.inc +++ b/core/modules/update/update.report.inc @@ -50,12 +50,10 @@ function template_preprocess_update_report(&$variables) { ]; // Build project rows. - if (!isset($rows[$project['project_type']])) { - $rows[$project['project_type']] = [ - '#type' => 'table', - '#attributes' => ['class' => ['update']], - ]; - } + $rows[$project['project_type']] ??= [ + '#type' => 'table', + '#attributes' => ['class' => ['update']], + ]; $row_key = !empty($project['title']) ? mb_strtolower($project['title']) : mb_strtolower($project['name']); // Add the project status row and details. diff --git a/core/modules/user/src/PermissionHandler.php b/core/modules/user/src/PermissionHandler.php index 50670b0381..4ffd698c08 100644 --- a/core/modules/user/src/PermissionHandler.php +++ b/core/modules/user/src/PermissionHandler.php @@ -105,9 +105,7 @@ public function __construct(ModuleHandlerInterface $module_handler, TranslationI * The YAML discovery. */ protected function getYamlDiscovery() { - if (!isset($this->yamlDiscovery)) { - $this->yamlDiscovery = new YamlDiscovery('permissions', $this->moduleHandler->getModuleDirectories()); - } + $this->yamlDiscovery ??= new YamlDiscovery('permissions', $this->moduleHandler->getModuleDirectories()); return $this->yamlDiscovery; } diff --git a/core/modules/user/src/Plugin/migrate/process/UserLangcode.php b/core/modules/user/src/Plugin/migrate/process/UserLangcode.php index 174c8a557c..0f02a49bf8 100644 --- a/core/modules/user/src/Plugin/migrate/process/UserLangcode.php +++ b/core/modules/user/src/Plugin/migrate/process/UserLangcode.php @@ -58,9 +58,7 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if (!isset($this->configuration['fallback_to_site_default'])) { - $this->configuration['fallback_to_site_default'] = TRUE; - } + $this->configuration['fallback_to_site_default'] ??= TRUE; // If the user's language is empty, it means the locale module was not // installed, so the user's langcode should be English and the user's diff --git a/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php b/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php index 84f6dfecc2..2ee9545801 100644 --- a/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php +++ b/core/modules/user/src/Plugin/migrate/process/d6/UserUpdate7002.php @@ -39,9 +39,7 @@ class UserUpdate7002 extends ProcessPluginBase implements ContainerFactoryPlugin public function __construct(array $configuration, $plugin_id, array $plugin_definition, Config $date_config) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->dateConfig = $date_config; - if (!isset(static::$timezones)) { - static::$timezones = TimeZoneFormHelper::getOptionsList(); - } + static::$timezones ??= TimeZoneFormHelper::getOptionsList(); } /** diff --git a/core/modules/user/tests/src/Traits/UserCreationTrait.php b/core/modules/user/tests/src/Traits/UserCreationTrait.php index 510d722ebd..35ec3e0aba 100644 --- a/core/modules/user/tests/src/Traits/UserCreationTrait.php +++ b/core/modules/user/tests/src/Traits/UserCreationTrait.php @@ -239,15 +239,11 @@ protected function createAdminRole($rid = NULL, $name = NULL, $weight = NULL) { */ protected function createRole(array $permissions, $rid = NULL, $name = NULL, $weight = NULL) { // Generate a random, lowercase machine name if none was passed. - if (!isset($rid)) { - $rid = $this->randomMachineName(8); - } + $rid ??= $this->randomMachineName(8); // Generate a random label. - if (!isset($name)) { - // In the role UI role names are trimmed and random string can start or - // end with a space. - $name = trim($this->randomString(8)); - } + // In the role UI role names are trimmed and random string can start or + // end with a space. + $name ??= trim($this->randomString(8)); // Check the all the permissions strings are valid. if (!$this->checkPermissions($permissions)) { diff --git a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php index 5074969ab7..fb994be8da 100644 --- a/core/modules/views/src/Entity/Render/EntityFieldRenderer.php +++ b/core/modules/views/src/Entity/Render/EntityFieldRenderer.php @@ -139,9 +139,7 @@ public function render(ResultRow $row, EntityField $field = NULL) { // The method is called for each field in each result row. In order to // leverage multiple-entity building of formatter output, we build the // render arrays for all fields in all rows on the first call. - if (!isset($this->build)) { - $this->build = $this->buildFields($this->view->result); - } + $this->build ??= $this->buildFields($this->view->result); if (isset($field)) { $field_id = $field->options['id']; diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 8fb42eadf4..2c30035b65 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -119,9 +119,7 @@ class View extends ConfigEntityBase implements ViewEntityInterface { */ public function getExecutable() { // Ensure that an executable View is available. - if (!isset($this->executable)) { - $this->executable = Views::executableFactory()->get($this); - } + $this->executable ??= Views::executableFactory()->get($this); return $this->executable; } diff --git a/core/modules/views/src/EntityViewsData.php b/core/modules/views/src/EntityViewsData.php index eb964521af..027f82c4a8 100644 --- a/core/modules/views/src/EntityViewsData.php +++ b/core/modules/views/src/EntityViewsData.php @@ -118,9 +118,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[] */ protected function getFieldStorageDefinitions() { - if (!isset($this->fieldStorageDefinitions)) { - $this->fieldStorageDefinitions = $this->entityFieldManager->getFieldStorageDefinitions($this->entityType->id()); - } + $this->fieldStorageDefinitions ??= $this->entityFieldManager->getFieldStorageDefinitions($this->entityType->id()); return $this->fieldStorageDefinitions; } diff --git a/core/modules/views/src/FieldAPIHandlerTrait.php b/core/modules/views/src/FieldAPIHandlerTrait.php index b3ec833a52..a1f51e51a6 100644 --- a/core/modules/views/src/FieldAPIHandlerTrait.php +++ b/core/modules/views/src/FieldAPIHandlerTrait.php @@ -72,9 +72,7 @@ protected function getFieldStorageDefinition() { * The entity field manager. */ protected function getEntityFieldManager() { - if (!isset($this->entityFieldManager)) { - $this->entityFieldManager = \Drupal::service('entity_field.manager'); - } + $this->entityFieldManager ??= \Drupal::service('entity_field.manager'); return $this->entityFieldManager; } diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index ad7ee244e3..ec782f2a8c 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -134,9 +134,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o if (isset($options['field'])) { $this->field = $options['field']; - if (!isset($this->realField)) { - $this->realField = $options['field']; - } + $this->realField ??= $options['field']; } $this->query = &$view->query; @@ -547,9 +545,7 @@ public function setRelationship() { * {@inheritdoc} */ public function ensureMyTable() { - if (!isset($this->tableAlias)) { - $this->tableAlias = $this->query->ensureTable($this->table, $this->relationship); - } + $this->tableAlias ??= $this->query->ensureTable($this->table, $this->relationship); return $this->tableAlias; } diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index e478e91301..cca876d938 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -226,9 +226,7 @@ public function unpackOptions(&$storage, $options, $definition = NULL, $all = TR return; } - if (!isset($definition)) { - $definition = $this->defineOptions(); - } + $definition ??= $this->defineOptions(); foreach ($options as $key => $value) { if (is_array($value)) { @@ -394,9 +392,7 @@ protected function viewsTokenReplace($text, $tokens) { assert(is_numeric($key) || preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $key) === 1, 'Tokens need to be valid Twig variables.'); $token_array = [$key => $token_array]; } - if (!isset($twig_tokens[$top])) { - $twig_tokens[$top] = []; - } + $twig_tokens[$top] ??= []; $twig_tokens[$top] += $token_array; } } @@ -660,9 +656,7 @@ public static function queryLanguageSubstitutions() { * @return \Drupal\Core\Render\RendererInterface */ protected function getRenderer() { - if (!isset($this->renderer)) { - $this->renderer = \Drupal::service('renderer'); - } + $this->renderer ??= \Drupal::service('renderer'); return $this->renderer; } diff --git a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php index bbc33b438b..7f6009f1b8 100644 --- a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php @@ -137,9 +137,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o } public function isException($arg = NULL) { - if (!isset($arg)) { - $arg = $this->argument ?? NULL; - } + $arg ??= $this->argument ?? NULL; return !empty($this->options['exception']['value']) && $this->options['exception']['value'] === $arg; } @@ -751,9 +749,7 @@ public function defaultSummaryForm(&$form, FormStateInterface $form_state) { * building the view will be aborted here. */ public function defaultAction($info = NULL) { - if (!isset($info)) { - $info = $this->defaultActions($this->options['default_action']); - } + $info ??= $this->defaultActions($this->options['default_action']); if (!$info) { return FALSE; diff --git a/core/modules/views/src/Plugin/views/display/Attachment.php b/core/modules/views/src/Plugin/views/display/Attachment.php index e6e73fbd8a..44d261f34a 100644 --- a/core/modules/views/src/Plugin/views/display/Attachment.php +++ b/core/modules/views/src/Plugin/views/display/Attachment.php @@ -90,9 +90,7 @@ public function optionsSummary(&$categories, &$options) { } } - if (!isset($attach_to)) { - $attach_to = $this->t('Not defined'); - } + $attach_to ??= $this->t('Not defined'); $options['displays'] = [ 'category' => 'attachment', diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index 81c37a2c37..03346f9a48 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2061,9 +2061,7 @@ public function setOverride($section, $new_state = NULL) { return; } - if (!isset($new_state)) { - $new_state = empty($this->options['defaults'][$section]); - } + $new_state ??= empty($this->options['defaults'][$section]); // For each option that is part of this group, fix our settings. foreach ($options as $option) { @@ -2299,9 +2297,7 @@ public function renderArea($area, $empty = FALSE) { * {@inheritdoc} */ public function access(AccountInterface $account = NULL) { - if (!isset($account)) { - $account = \Drupal::currentUser(); - } + $account ??= \Drupal::currentUser(); $plugin = $this->getPlugin('access'); /** @var \Drupal\views\Plugin\views\access\AccessPluginBase $plugin */ diff --git a/core/modules/views/src/Plugin/views/display/Feed.php b/core/modules/views/src/Plugin/views/display/Feed.php index caf6f8cbc9..300416be4e 100644 --- a/core/modules/views/src/Plugin/views/display/Feed.php +++ b/core/modules/views/src/Plugin/views/display/Feed.php @@ -284,9 +284,7 @@ public function optionsSummary(&$categories, &$options) { } } - if (!isset($attach_to)) { - $attach_to = $this->t('None'); - } + $attach_to ??= $this->t('None'); $options['displays'] = [ 'category' => 'page', diff --git a/core/modules/views/src/Plugin/views/display/PathPluginBase.php b/core/modules/views/src/Plugin/views/display/PathPluginBase.php index 984d740e57..f53cfae4d1 100644 --- a/core/modules/views/src/Plugin/views/display/PathPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/PathPluginBase.php @@ -195,10 +195,8 @@ protected function getRoute($view_id, $display_id) { // Add access check parameters to the route. $access_plugin = $this->getPlugin('access'); - if (!isset($access_plugin)) { - // @todo Do we want to support a default plugin in getPlugin itself? - $access_plugin = Views::pluginManager('access')->createInstance('none'); - } + // @todo Do we want to support a default plugin in getPlugin itself? + $access_plugin ??= Views::pluginManager('access')->createInstance('none'); $access_plugin->alterRouteDefinition($route); // Set the argument map, in order to support named parameters. diff --git a/core/modules/views/src/Plugin/views/field/EntityField.php b/core/modules/views/src/Plugin/views/field/EntityField.php index 6ef6b011b8..71a2fa0f78 100644 --- a/core/modules/views/src/Plugin/views/field/EntityField.php +++ b/core/modules/views/src/Plugin/views/field/EntityField.php @@ -547,9 +547,7 @@ public function submitFormCalculateOptions(array $options, array $form_state_opt // conflict. unset($options['settings']); $options = $form_state_options + $options; - if (!isset($options['settings'])) { - $options['settings'] = []; - } + $options['settings'] ??= []; return $options; } @@ -1017,9 +1015,7 @@ protected function addSelfTokens(&$tokens, $item) { * The field formatter instance. */ protected function getFormatterInstance($format = NULL) { - if (!isset($format)) { - $format = $this->options['type']; - } + $format ??= $this->options['type']; $settings = $this->options['settings'] + $this->formatterPluginManager->getDefaultSettings($format); $options = [ diff --git a/core/modules/views/src/Plugin/views/field/EntityOperations.php b/core/modules/views/src/Plugin/views/field/EntityOperations.php index f8e36f9f0f..28afdba973 100644 --- a/core/modules/views/src/Plugin/views/field/EntityOperations.php +++ b/core/modules/views/src/Plugin/views/field/EntityOperations.php @@ -138,9 +138,7 @@ public function render(ResultRow $values) { $operations = $this->entityTypeManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); if ($this->options['destination']) { foreach ($operations as &$operation) { - if (!isset($operation['query'])) { - $operation['query'] = []; - } + $operation['query'] ??= []; $operation['query'] += $this->getDestinationArray(); } } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 412da1b2d4..ac0a24b807 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -140,9 +140,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->additional_fields = $this->definition['additional fields']; } - if (!isset($this->options['exclude'])) { - $this->options['exclude'] = ''; - } + $this->options['exclude'] ??= ''; } /** @@ -1369,9 +1367,7 @@ public function renderText($alter) { $this->last_render_text = $value; if (!empty($alter['make_link']) && (!empty($alter['path']) || !empty($alter['url']))) { - if (!isset($tokens)) { - $tokens = $this->getRenderTokens($alter); - } + $tokens ??= $this->getRenderTokens($alter); $value = $this->renderAsLink($alter, $value, $tokens); } @@ -1569,9 +1565,7 @@ protected function renderAsLink($alter, $text, $tokens) { // currently can only be altered in preprocessors and not within the UI. if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) { foreach ($alter['link_attributes'] as $key => $attribute) { - if (!isset($options['attributes'][$key])) { - $options['attributes'][$key] = $this->viewsTokenReplace($attribute, $tokens); - } + $options['attributes'][$key] ??= $this->viewsTokenReplace($attribute, $tokens); } } @@ -1638,9 +1632,7 @@ public function getRenderTokens($item) { $count = 0; foreach ($this->displayHandler->getHandlers('argument') as $arg => $handler) { $token = "{{ arguments.$arg }}"; - if (!isset($tokens[$token])) { - $tokens[$token] = ''; - } + $tokens[$token] ??= ''; // Use strip tags as there should never be HTML in the path. // However, we need to preserve special characters like " that @@ -1878,9 +1870,7 @@ public static function trimText($alter, $value) { * @return \Drupal\Core\Utility\LinkGeneratorInterface */ protected function linkGenerator() { - if (!isset($this->linkGenerator)) { - $this->linkGenerator = \Drupal::linkGenerator(); - } + $this->linkGenerator ??= \Drupal::linkGenerator(); return $this->linkGenerator; } @@ -1890,9 +1880,7 @@ protected function linkGenerator() { * @return \Drupal\Core\Render\RendererInterface */ protected function getRenderer() { - if (!isset($this->renderer)) { - $this->renderer = \Drupal::service('renderer'); - } + $this->renderer ??= \Drupal::service('renderer'); return $this->renderer; } diff --git a/core/modules/views/src/Plugin/views/filter/BooleanOperator.php b/core/modules/views/src/Plugin/views/filter/BooleanOperator.php index 81c2f47aa8..f63b395797 100644 --- a/core/modules/views/src/Plugin/views/filter/BooleanOperator.php +++ b/core/modules/views/src/Plugin/views/filter/BooleanOperator.php @@ -150,9 +150,7 @@ public function getValueOptions() { } // Provide a fallback if the above didn't set anything. - if (!isset($this->valueOptions)) { - $this->valueOptions = [1 => $this->t('True'), 0 => $this->t('False')]; - } + $this->valueOptions ??= [1 => $this->t('True'), 0 => $this->t('False')]; } protected function defineOptions() { diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 1d24826b75..7ee1a8565e 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -1461,9 +1461,7 @@ public function storeGroupInput($input, $status) { } if ($status !== FALSE) { - if (!isset($views_session[$this->view->storage->id()][$display_id])) { - $views_session[$this->view->storage->id()][$display_id] = []; - } + $views_session[$this->view->storage->id()][$display_id] ??= []; $views_session[$this->view->storage->id()][$display_id][$this->options['group_info']['identifier']] = $input[$this->options['group_info']['identifier']]; } if (!empty($views_session)) { @@ -1574,9 +1572,7 @@ public function storeExposedInput($input, $status) { } if ($status) { - if (!isset($views_session[$this->view->storage->id()][$display_id])) { - $views_session[$this->view->storage->id()][$display_id] = []; - } + $views_session[$this->view->storage->id()][$display_id] ??= []; $session_ref = &$views_session[$this->view->storage->id()][$display_id]; diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 52c198ce05..1bb28cdcce 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -263,9 +263,7 @@ protected function valueForm(&$form, FormStateInterface $form_state) { * When using exposed filters, we may be required to reduce the set. */ public function reduceValueOptions($input = NULL) { - if (!isset($input)) { - $input = $this->valueOptions; - } + $input ??= $this->valueOptions; // Because options may be an array of strings, or an array of mixed arrays // and strings (optgroups), or an array of objects, or a form of Markup, we diff --git a/core/modules/views/src/Plugin/views/filter/NumericFilter.php b/core/modules/views/src/Plugin/views/filter/NumericFilter.php index 2e34e069cf..6948b87f14 100644 --- a/core/modules/views/src/Plugin/views/filter/NumericFilter.php +++ b/core/modules/views/src/Plugin/views/filter/NumericFilter.php @@ -317,13 +317,11 @@ protected function valueForm(&$form, FormStateInterface $form_state) { $user_input[$identifier]['max'] = $this->value['max']; } - if (!isset($form['value'])) { - // Ensure there is something in the 'value'. - $form['value'] = [ - '#type' => 'value', - '#value' => NULL, - ]; - } + // Ensure there is something in the 'value'. + $form['value'] ??= [ + '#type' => 'value', + '#value' => NULL, + ]; } } diff --git a/core/modules/views/src/Plugin/views/filter/StringFilter.php b/core/modules/views/src/Plugin/views/filter/StringFilter.php index ba8fe2cf99..3bd8c316cd 100644 --- a/core/modules/views/src/Plugin/views/filter/StringFilter.php +++ b/core/modules/views/src/Plugin/views/filter/StringFilter.php @@ -303,13 +303,11 @@ protected function valueForm(&$form, FormStateInterface $form_state) { } } - if (!isset($form['value'])) { - // Ensure there is something in the 'value'. - $form['value'] = [ - '#type' => 'value', - '#value' => NULL, - ]; - } + // Ensure there is something in the 'value'. + $form['value'] ??= [ + '#type' => 'value', + '#value' => NULL, + ]; } /** diff --git a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php index 446b636f37..fd38fee12f 100644 --- a/core/modules/views/src/Plugin/views/query/QueryPluginBase.php +++ b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php @@ -177,9 +177,7 @@ public function setWhereGroup($type = 'AND', $group = NULL, $where = 'where') { // Set an alias. $groups = &$this->$where; - if (!isset($group)) { - $group = empty($groups) ? 1 : max(array_keys($groups)) + 1; - } + $group ??= empty($groups) ? 1 : max(array_keys($groups)) + 1; // Create an empty group if (empty($groups[$group])) { diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php index af57e33ec4..f7f5717b8a 100644 --- a/core/modules/views/src/Plugin/views/query/Sql.php +++ b/core/modules/views/src/Plugin/views/query/Sql.php @@ -518,9 +518,7 @@ public function queueTable($table, $relationship = NULL, JoinPluginBase $join = $alias = $this->markTable($table, $relationship, $alias); // If no alias is specified, give it the default. - if (!isset($alias)) { - $alias = $this->tables[$relationship][$table]['alias'] . $this->tables[$relationship][$table]['count']; - } + $alias ??= $this->tables[$relationship][$table]['alias'] . $this->tables[$relationship][$table]['count']; // If this is a relationship based table, add a marker with // the relationship as a primary table for the alias. @@ -616,9 +614,7 @@ public function ensureTable($table, $relationship = NULL, JoinPluginBase $join = } // If we do not have join info, fetch it. - if (!isset($join)) { - $join = $this->getJoinData($table, $this->relationships[$relationship]['base']); - } + $join ??= $this->getJoinData($table, $this->relationships[$relationship]['base']); // If it can't be fetched, this won't work. if (empty($join)) { @@ -673,18 +669,14 @@ public function ensureTable($table, $relationship = NULL, JoinPluginBase $join = * additional copies will NOT be added if the table is already there. */ protected function ensurePath($table, $relationship = NULL, $join = NULL, $traced = [], $add = []) { - if (!isset($relationship)) { - $relationship = $this->view->storage->get('base_table'); - } + $relationship ??= $this->view->storage->get('base_table'); if (!array_key_exists($relationship, $this->relationships)) { return FALSE; } // If we do not have join info, fetch it. - if (!isset($join)) { - $join = $this->getJoinData($table, $this->relationships[$relationship]['base']); - } + $join ??= $this->getJoinData($table, $this->relationships[$relationship]['base']); // If it can't be fetched, this won't work. if (empty($join)) { @@ -1321,9 +1313,7 @@ public function query($get_count = FALSE) { else { $this->getCountOptimized = FALSE; } - if (!isset($this->getCountOptimized)) { - $this->getCountOptimized = TRUE; - } + $this->getCountOptimized ??= TRUE; // Go ahead and build the query. $query = $this->getConnection() @@ -1592,9 +1582,7 @@ public function loadEntities(&$results) { $entity_types = []; foreach ($entity_information as $info) { $entity_type = $info['entity_type']; - if (!isset($entity_types[$entity_type])) { - $entity_types[$entity_type] = $this->entityTypeManager->getDefinition($entity_type); - } + $entity_types[$entity_type] ??= $this->entityTypeManager->getDefinition($entity_type); } // Assemble a list of entities to load. diff --git a/core/modules/views/src/Plugin/views/row/RssFields.php b/core/modules/views/src/Plugin/views/row/RssFields.php index 924cd7b6e2..a954cce1a7 100644 --- a/core/modules/views/src/Plugin/views/row/RssFields.php +++ b/core/modules/views/src/Plugin/views/row/RssFields.php @@ -123,9 +123,7 @@ public function validate() { public function render($row) { static $row_index; - if (!isset($row_index)) { - $row_index = 0; - } + $row_index ??= 0; // Create the RSS item object. $item = new \stdClass(); diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 7b04186dbe..1f55e12da7 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -1505,10 +1505,8 @@ public function render($display_id = NULL) { // Initialize the style plugin. $this->initStyle(); - if (!isset($this->response)) { - // Set the response so other parts can alter it. - $this->response = new Response('', 200); - } + // Set the response so other parts can alter it. + $this->response ??= new Response('', 200); // Give field handlers the opportunity to perform additional queries // using the entire resultset prior to rendering. @@ -1804,9 +1802,7 @@ public function setResponse(Response $response) { * The response object of the view. */ public function getResponse() { - if (!isset($this->response)) { - $this->response = new Response(); - } + $this->response ??= new Response(); return $this->response; } @@ -2267,9 +2263,7 @@ public function getHandlers($type, $display_id = NULL) { $this->setDisplay($display_id); - if (!isset($display_id)) { - $display_id = $this->current_display; - } + $display_id ??= $this->current_display; // Get info about the types so we can get the right data. $types = static::getHandlerTypes(); diff --git a/core/modules/views/src/Views.php b/core/modules/views/src/Views.php index 2373ebbc21..494accf29e 100644 --- a/core/modules/views/src/Views.php +++ b/core/modules/views/src/Views.php @@ -394,14 +394,12 @@ public static function pluginList() { // Key first by the plugin type, then the name. $key = $type . ':' . $name; // Add info for this plugin. - if (!isset($plugins[$key])) { - $plugins[$key] = [ - 'type' => $type, - 'title' => $info[$name]['title'], - 'provider' => $info[$name]['provider'], - 'views' => [], - ]; - } + $plugins[$key] ??= [ + 'type' => $type, + 'title' => $info[$name]['title'], + 'provider' => $info[$name]['provider'], + 'views' => [], + ]; // Add this view to the list for this plugin. $plugins[$key]['views'][$view->id()] = $view->id(); @@ -429,73 +427,71 @@ public static function pluginList() { public static function getHandlerTypes() { // Statically cache this so translation only occurs once per request for all // of these values. - if (!isset(static::$handlerTypes)) { - static::$handlerTypes = [ - 'field' => [ - // title - 'title' => static::t('Fields'), - // Lowercase title for mid-sentence. - 'ltitle' => static::t('fields'), - // Singular title. - 'stitle' => static::t('Field'), - // Singular lowercase title for mid sentence - 'lstitle' => static::t('field'), - 'plural' => 'fields', - ], - 'argument' => [ - 'title' => static::t('Contextual filters'), - 'ltitle' => static::t('contextual filters'), - 'stitle' => static::t('Contextual filter'), - 'lstitle' => static::t('contextual filter'), - 'plural' => 'arguments', - ], - 'sort' => [ - 'title' => static::t('Sort criteria'), - 'ltitle' => static::t('sort criteria'), - 'stitle' => static::t('Sort criterion'), - 'lstitle' => static::t('sort criterion'), - 'plural' => 'sorts', - ], - 'filter' => [ - 'title' => static::t('Filter criteria'), - 'ltitle' => static::t('filter criteria'), - 'stitle' => static::t('Filter criterion'), - 'lstitle' => static::t('filter criterion'), - 'plural' => 'filters', - ], - 'relationship' => [ - 'title' => static::t('Relationships'), - 'ltitle' => static::t('relationships'), - 'stitle' => static::t('Relationship'), - 'lstitle' => static::t('Relationship'), - 'plural' => 'relationships', - ], - 'header' => [ - 'title' => static::t('Header'), - 'ltitle' => static::t('header'), - 'stitle' => static::t('Header'), - 'lstitle' => static::t('Header'), - 'plural' => 'header', - 'type' => 'area', - ], - 'footer' => [ - 'title' => static::t('Footer'), - 'ltitle' => static::t('footer'), - 'stitle' => static::t('Footer'), - 'lstitle' => static::t('Footer'), - 'plural' => 'footer', - 'type' => 'area', - ], - 'empty' => [ - 'title' => static::t('No results behavior'), - 'ltitle' => static::t('no results behavior'), - 'stitle' => static::t('No results behavior'), - 'lstitle' => static::t('No results behavior'), - 'plural' => 'empty', - 'type' => 'area', - ], - ]; - } + static::$handlerTypes ??= [ + 'field' => [ + // title + 'title' => static::t('Fields'), + // Lowercase title for mid-sentence. + 'ltitle' => static::t('fields'), + // Singular title. + 'stitle' => static::t('Field'), + // Singular lowercase title for mid sentence + 'lstitle' => static::t('field'), + 'plural' => 'fields', + ], + 'argument' => [ + 'title' => static::t('Contextual filters'), + 'ltitle' => static::t('contextual filters'), + 'stitle' => static::t('Contextual filter'), + 'lstitle' => static::t('contextual filter'), + 'plural' => 'arguments', + ], + 'sort' => [ + 'title' => static::t('Sort criteria'), + 'ltitle' => static::t('sort criteria'), + 'stitle' => static::t('Sort criterion'), + 'lstitle' => static::t('sort criterion'), + 'plural' => 'sorts', + ], + 'filter' => [ + 'title' => static::t('Filter criteria'), + 'ltitle' => static::t('filter criteria'), + 'stitle' => static::t('Filter criterion'), + 'lstitle' => static::t('filter criterion'), + 'plural' => 'filters', + ], + 'relationship' => [ + 'title' => static::t('Relationships'), + 'ltitle' => static::t('relationships'), + 'stitle' => static::t('Relationship'), + 'lstitle' => static::t('Relationship'), + 'plural' => 'relationships', + ], + 'header' => [ + 'title' => static::t('Header'), + 'ltitle' => static::t('header'), + 'stitle' => static::t('Header'), + 'lstitle' => static::t('Header'), + 'plural' => 'header', + 'type' => 'area', + ], + 'footer' => [ + 'title' => static::t('Footer'), + 'ltitle' => static::t('footer'), + 'stitle' => static::t('Footer'), + 'lstitle' => static::t('Footer'), + 'plural' => 'footer', + 'type' => 'area', + ], + 'empty' => [ + 'title' => static::t('No results behavior'), + 'ltitle' => static::t('no results behavior'), + 'stitle' => static::t('No results behavior'), + 'lstitle' => static::t('No results behavior'), + 'plural' => 'empty', + 'type' => 'area', + ], + ]; return static::$handlerTypes; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 0735b1de87..c728f91bb9 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -184,9 +184,7 @@ function views_theme($existing, $type, $theme, $path) { // For the views module we ensure views.theme.inc is included. if ($def['provider'] == 'views') { - if (!isset($hooks[$def['theme']]['includes'])) { - $hooks[$def['theme']]['includes'] = []; - } + $hooks[$def['theme']]['includes'] ??= []; if (!in_array('views.theme.inc', $hooks[$def['theme']]['includes'])) { $hooks[$def['theme']]['includes'][] = $module_dir . '/views.theme.inc'; } @@ -364,9 +362,7 @@ function views_theme_suggestions_container_alter(array &$suggestions, array $var * @see template_preprocess_views_view() */ function views_add_contextual_links(&$render_element, $location, $display_id, array $view_element = NULL) { - if (!isset($view_element)) { - $view_element = $render_element; - } + $view_element ??= $render_element; $view_element['#cache_properties'] = ['view_id', 'view_display_show_admin_links', 'view_display_plugin_id']; $view_id = $view_element['#view_id']; $show_admin_links = $view_element['#view_display_show_admin_links']; diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 58d34f16ae..5617efb5ce 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -585,9 +585,7 @@ function template_preprocess_views_view_table(&$variables) { if (!empty($fields[$field])) { $field_output = $handler->getField($num, $field); $column_reference['wrapper_element'] = $fields[$field]->elementType(TRUE, TRUE); - if (!isset($column_reference['content'])) { - $column_reference['content'] = []; - } + $column_reference['content'] ??= []; // Only bother with separators and stuff if the field shows up. // Place the field into the column, along with an optional separator. diff --git a/core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php b/core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php index 9ef21bfa96..644a01dd22 100644 --- a/core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php +++ b/core/modules/views_ui/src/ProxyClass/ParamConverter/ViewUIConverter.php @@ -60,9 +60,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php index b9afc6146f..32c1533164 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php @@ -306,9 +306,7 @@ protected function assertPreviewAJAX(int $row_count): void { * @internal */ protected function assertClass(NodeElement $element, string $class, string $message = ''): void { - if (!isset($message)) { - $message = "Class .$class found."; - } + $message ??= "Class .$class found."; $this->assertStringContainsString($class, $element->getAttribute('class'), $message); } diff --git a/core/modules/workspaces/src/WorkspaceManager.php b/core/modules/workspaces/src/WorkspaceManager.php index e6663f7ea7..ef34e17659 100644 --- a/core/modules/workspaces/src/WorkspaceManager.php +++ b/core/modules/workspaces/src/WorkspaceManager.php @@ -139,11 +139,9 @@ public function __construct(RequestStack $request_stack, EntityTypeManagerInterf */ public function isEntityTypeSupported(EntityTypeInterface $entity_type) { $entity_type_id = $entity_type->id(); - if (!isset($this->supported[$entity_type_id])) { - // Only entity types which are revisionable and publishable can belong - // to a workspace. - $this->supported[$entity_type_id] = $entity_type->entityClassImplements(EntityPublishedInterface::class) && $entity_type->isRevisionable(); - } + // Only entity types which are revisionable and publishable can belong + // to a workspace. + $this->supported[$entity_type_id] ??= $entity_type->entityClassImplements(EntityPublishedInterface::class) && $entity_type->isRevisionable(); return $this->supported[$entity_type_id]; } diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php index 986a02c92b..2a65e12399 100644 --- a/core/tests/Drupal/KernelTests/AssertContentTrait.php +++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php @@ -662,9 +662,7 @@ protected function assertNoPattern($pattern, $message = '') { * TRUE on pass. */ protected function assertTextPattern($pattern, $message = NULL) { - if (!isset($message)) { - $message = new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]); - } + $message ??= new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]); $this->assertMatchesRegularExpression($pattern, $this->getTextContent(), $message); return TRUE; } diff --git a/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php b/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php index 2466a93259..4b4a6bdf71 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/LibraryDiscoveryIntegrationTest.php @@ -302,9 +302,7 @@ protected function activateTheme($theme_name) { * @internal */ protected function assertAssetInLibrary(string $asset, string $extension, string $library_name, string $sub_key, string $message = NULL): void { - if (!isset($message)) { - $message = sprintf('Asset %s found in library "%s/%s"', $asset, $extension, $library_name); - } + $message ??= sprintf('Asset %s found in library "%s/%s"', $asset, $extension, $library_name); $library = $this->libraryDiscovery->getLibraryByName($extension, $library_name); foreach ($library[$sub_key] as $definition) { if ($asset == $definition['data']) { @@ -331,9 +329,7 @@ protected function assertAssetInLibrary(string $asset, string $extension, string * @internal */ protected function assertNoAssetInLibrary(string $asset, string $extension, string $library_name, string $sub_key, string $message = NULL): void { - if (!isset($message)) { - $message = sprintf('Asset %s not found in library "%s/%s"', $asset, $extension, $library_name); - } + $message ??= sprintf('Asset %s not found in library "%s/%s"', $asset, $extension, $library_name); $library = $this->libraryDiscovery->getLibraryByName($extension, $library_name); foreach ($library[$sub_key] as $definition) { if ($asset == $definition['data']) { diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php index 0655ba469b..b07e362e78 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php @@ -49,9 +49,7 @@ abstract class GenericCacheBackendUnitTestBase extends KernelTestBase { * Bin name. */ protected function getTestBin() { - if (!isset($this->testBin)) { - $this->testBin = 'page'; - } + $this->testBin ??= 'page'; return $this->testBin; } @@ -90,9 +88,7 @@ public function tearDownCacheBackend() { * Cache backend to test. */ protected function getCacheBackend($bin = NULL) { - if (!isset($bin)) { - $bin = $this->getTestBin(); - } + $bin ??= $this->getTestBin(); if (!isset($this->cachebackends[$bin])) { $this->cachebackends[$bin] = $this->createCacheBackend($bin); // Ensure the backend is empty. diff --git a/core/tests/Drupal/KernelTests/Core/File/FileTestBase.php b/core/tests/Drupal/KernelTests/Core/File/FileTestBase.php index b41787f452..4601b92e7b 100644 --- a/core/tests/Drupal/KernelTests/Core/File/FileTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/File/FileTestBase.php @@ -105,9 +105,7 @@ public function assertFilePermissions($filepath, $expected_mode, $message = NULL $expected_mode = $expected_mode | $expected_mode >> 3 | $expected_mode >> 6; } - if (!isset($message)) { - $message = t('Expected file permission to be %expected, actually were %actual.', ['%actual' => decoct($actual_mode), '%expected' => decoct($expected_mode)]); - } + $message ??= t('Expected file permission to be %expected, actually were %actual.', ['%actual' => decoct($actual_mode), '%expected' => decoct($expected_mode)]); $this->assertEquals($expected_mode, $actual_mode, $message); } @@ -141,9 +139,7 @@ public function assertDirectoryPermissions($directory, $expected_mode, $message $expected_mode = $expected_mode | $expected_mode >> 3 | $expected_mode >> 6; } - if (!isset($message)) { - $message = t('Expected directory permission to be %expected, actually were %actual.', ['%actual' => decoct($actual_mode), '%expected' => decoct($expected_mode)]); - } + $message ??= t('Expected directory permission to be %expected, actually were %actual.', ['%actual' => decoct($actual_mode), '%expected' => decoct($expected_mode)]); $this->assertEquals($expected_mode, $actual_mode, $message); } @@ -159,9 +155,7 @@ public function assertDirectoryPermissions($directory, $expected_mode, $message */ public function createDirectory($path = NULL) { // A directory to operate on. - if (!isset($path)) { - $path = 'public://' . $this->randomMachineName(); - } + $path ??= 'public://' . $this->randomMachineName(); $this->assertTrue(\Drupal::service('file_system')->mkdir($path)); $this->assertDirectoryExists($path); return $path; @@ -184,20 +178,16 @@ public function createDirectory($path = NULL) { * File URI. */ public function createUri($filepath = NULL, $contents = NULL, $scheme = NULL) { - if (!isset($filepath)) { - // Prefix with non-latin characters to ensure that all file-related - // tests work with international filenames. - // cSpell:disable-next-line - $filepath = 'Файл для тестирования ' . $this->randomMachineName(); - } + // Prefix with non-latin characters to ensure that all file-related + // tests work with international filenames. + // cSpell:disable-next-line + $filepath ??= 'Файл для тестирования ' . $this->randomMachineName(); if (!isset($scheme)) { $scheme = 'public'; } $filepath = $scheme . '://' . $filepath; - if (!isset($contents)) { - $contents = "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; - } + $contents ??= "file_put_contents() doesn't seem to appreciate empty strings so let's put in some data."; file_put_contents($filepath, $contents); $this->assertFileExists($filepath); diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index d89d738e38..c20657b180 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -572,9 +572,7 @@ public function register(ContainerBuilder $container) { // Use memory for key value storages to avoid database queries. Store the // key value factory on the test object so that key value storages persist // container rebuilds, otherwise all state data would vanish. - if (!isset($this->keyValue)) { - $this->keyValue = new KeyValueMemoryFactory(); - } + $this->keyValue ??= new KeyValueMemoryFactory(); $container->set('keyvalue', $this->keyValue); // Set the default language on the minimal container. diff --git a/core/tests/Drupal/TestTools/Random.php b/core/tests/Drupal/TestTools/Random.php index e68bc09bb4..9ab875931c 100644 --- a/core/tests/Drupal/TestTools/Random.php +++ b/core/tests/Drupal/TestTools/Random.php @@ -23,9 +23,7 @@ abstract class Random { * The random generator. */ public static function getGenerator(): RandomUtility { - if (!isset(static::$randomGenerator)) { - static::$randomGenerator = new RandomUtility(); - } + static::$randomGenerator ??= new RandomUtility(); return static::$randomGenerator; } diff --git a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php index 1105b3f193..a9ce34e3bb 100644 --- a/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php +++ b/core/tests/Drupal/Tests/Component/ProxyBuilder/ProxyBuilderTest.php @@ -379,9 +379,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php index 74de788258..0c87caca71 100644 --- a/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Access/AccessManagerTest.php @@ -531,9 +531,7 @@ protected function setupAccessChecker() { * Add default expectations to the access arguments resolver factory. */ protected function setupAccessArgumentsResolverFactory($constraint = NULL) { - if (!isset($constraint)) { - $constraint = $this->any(); - } + $constraint ??= $this->any(); return $this->argumentsResolverFactory->expects($constraint) ->method('getArgumentsResolver') ->willReturnCallback(function ($route_match, $account) { diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 613bbddb43..93d8e25385 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -638,12 +638,8 @@ public function testDeleteNothing() { public function getMockEntity($class = EntityBaseTest::class, array $arguments = [], $methods = []) { // Ensure the entity is passed at least an array of values and an entity // type ID - if (!isset($arguments[0])) { - $arguments[0] = []; - } - if (!isset($arguments[1])) { - $arguments[1] = 'test_entity_type'; - } + $arguments[0] ??= []; + $arguments[1] ??= 'test_entity_type'; return $this->getMockForAbstractClass($class, $arguments, '', TRUE, TRUE, TRUE, $methods); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php index 5657fa656a..997b5cb972 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php @@ -292,9 +292,7 @@ public function providerTestSetLinkActiveClass() { } else { $active_attributes = $situation['attributes']; - if (!isset($active_attributes['class'])) { - $active_attributes['class'] = []; - } + $active_attributes['class'] ??= []; $active_attributes['class'][] = 'is-active'; $target_markup = $create_markup(new Attribute($active_attributes)); } diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index 9de2c5e1ac..b161d36eb2 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -314,9 +314,7 @@ public function getInfo($type) { '#name' => 'op', '#is_button' => TRUE, ]; - if (!isset($types[$type])) { - $types[$type] = []; - } + $types[$type] ??= []; return $types[$type]; } diff --git a/core/tests/Drupal/Tests/Core/ProxyBuilder/ProxyBuilderTest.php b/core/tests/Drupal/Tests/Core/ProxyBuilder/ProxyBuilderTest.php index 969c70a345..49f1482db1 100644 --- a/core/tests/Drupal/Tests/Core/ProxyBuilder/ProxyBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/ProxyBuilder/ProxyBuilderTest.php @@ -130,9 +130,7 @@ public function __construct(\Symfony\Component\DependencyInjection\ContainerInte */ protected function lazyLoadItself() { - if (!isset($this->service)) { - $this->service = $this->container->get($this->drupalProxyOriginalServiceId); - } + $this->service ??= $this->container->get($this->drupalProxyOriginalServiceId); return $this->service; } diff --git a/core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php b/core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php index 1eb14c8dab..d7df3b6d39 100644 --- a/core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php @@ -402,13 +402,9 @@ protected function setUpAccessPolicyProcessor( $cache_static = $cache_static->reveal(); } - if (!isset($current_user)) { - $current_user = $this->prophesize(AccountProxyInterface::class)->reveal(); - } + $current_user ??= $this->prophesize(AccountProxyInterface::class)->reveal(); - if (!isset($account_switcher)) { - $account_switcher = $this->prophesize(AccountSwitcherInterface::class)->reveal(); - } + $account_switcher ??= $this->prophesize(AccountSwitcherInterface::class)->reveal(); return new AccessPolicyProcessor( $variation_cache,