From 17abcea7c0f6c0d84ed752d19f206bb7051dd2ac Mon Sep 17 00:00:00 2001 From: Paul Weidner Date: Tue, 7 Jan 2025 15:40:07 -0800 Subject: [PATCH] Fix level 1 phpstan errors --- farm_rothamsted.module | 2 +- .../farm_rothamsted_experiment_research.module | 7 +++++-- .../src/Form/DuplicateProposalForm.php | 2 ++ .../src/ResearchNotificationHandler.php | 2 +- .../farm_rothamsted_notification.module | 6 ++++-- .../src/Plugin/QuickForm/QuickExperimentFormBase.php | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/farm_rothamsted.module b/farm_rothamsted.module index 1d5d2776..8651062a 100644 --- a/farm_rothamsted.module +++ b/farm_rothamsted.module @@ -198,7 +198,7 @@ function farm_rothamsted_form_alter(&$form, FormStateInterface $form_state, $for function farm_rothamsted_asset_form_move_submit(array &$form, FormStateInterface $form_state) { // Get the asset. - /** @var \Drupal\asset\Entity\AssetInterface $asset */ + /** @var \Drupal\asset\Entity\AssetInterface | NULL $asset */ $asset = $form_state->getFormObject()->getEntity(); if (empty($asset)) { return; diff --git a/modules/farm_rothamsted_experiment_research/farm_rothamsted_experiment_research.module b/modules/farm_rothamsted_experiment_research/farm_rothamsted_experiment_research.module index bf6e5e14..4021b839 100644 --- a/modules/farm_rothamsted_experiment_research/farm_rothamsted_experiment_research.module +++ b/modules/farm_rothamsted_experiment_research/farm_rothamsted_experiment_research.module @@ -739,7 +739,10 @@ function farm_rothamsted_experiment_research_preprocess_rothamsted_research_enti // Make sure this is a research entity. if (isset($variables['theme_hook_original']) && isset($variables['elements']["#{$variables['theme_hook_original']}"])) { - $entity_id = $variables['theme_hook_original']; + $entity_type_id = $variables['theme_hook_original']; + } + if (empty($entity_type_id)) { + return; } // Helpful $content variable for templates. @@ -747,7 +750,7 @@ function farm_rothamsted_experiment_research_preprocess_rothamsted_research_enti $variables['content'][$key] = $variables['elements'][$key]; } $variables['#attached']['library'][] = 'farm_ui_theme/layout'; - farm_ui_theme_build_stacked_twocol_layout($variables, $entity_id); + farm_ui_theme_build_stacked_twocol_layout($variables, $entity_type_id); } /** diff --git a/modules/farm_rothamsted_experiment_research/src/Form/DuplicateProposalForm.php b/modules/farm_rothamsted_experiment_research/src/Form/DuplicateProposalForm.php index 297196ad..83d4d34a 100644 --- a/modules/farm_rothamsted_experiment_research/src/Form/DuplicateProposalForm.php +++ b/modules/farm_rothamsted_experiment_research/src/Form/DuplicateProposalForm.php @@ -25,6 +25,7 @@ public function setEntity(EntityInterface $entity) { $this->entity->set($field_name, NULL); } $this->entity->set('status', 'draft'); + return $this; } /** @@ -37,6 +38,7 @@ public function setSourceEntity(EntityInterface $entity) { $status_notes = "This proposal was created by duplicating \"$source_name\". Please refer to that proposal for previous versions and a revision history. $source_link"; $this->entity->set('status_notes', $status_notes); $this->entity->setRevisionLogMessage($status_notes); + return $this; } /** diff --git a/modules/farm_rothamsted_experiment_research/src/ResearchNotificationHandler.php b/modules/farm_rothamsted_experiment_research/src/ResearchNotificationHandler.php index 4bf5b566..e2dd67a7 100644 --- a/modules/farm_rothamsted_experiment_research/src/ResearchNotificationHandler.php +++ b/modules/farm_rothamsted_experiment_research/src/ResearchNotificationHandler.php @@ -801,7 +801,7 @@ protected function getEntityFieldDifferences(EntityInterface $entity, array $exc $changed_field_message = "No field changes."; if (!empty($changed_fields)) { $field_labels = []; - foreach ($changed_fields ?? [] as $field) { + foreach ($changed_fields as $field) { $field_labels[] = $entity->get($field)->getFieldDefinition()->getLabel(); } $field_label_text = implode(', ', $field_labels); diff --git a/modules/farm_rothamsted_notification/farm_rothamsted_notification.module b/modules/farm_rothamsted_notification/farm_rothamsted_notification.module index 9f2fbd57..1747fdfd 100644 --- a/modules/farm_rothamsted_notification/farm_rothamsted_notification.module +++ b/modules/farm_rothamsted_notification/farm_rothamsted_notification.module @@ -124,6 +124,8 @@ function farm_rothamsted_notification_entity_base_field_info(EntityTypeInterface function farm_rothamsted_notification_mail($key, &$message, $params) { // Get entity type information. + $entity_type_id = NULL; + $entity_type_label = NULL; if (isset($params['entity_type_id']) && $entity_type_id = $params['entity_type_id']) { $entity_type_manager = \Drupal::entityTypeManager(); $entity_type_label = $entity_type_manager->getDefinition($entity_type_id)->getLabel(); @@ -150,8 +152,8 @@ function farm_rothamsted_notification_mail($key, &$message, $params) { $variables[$entity_type_id] = $entity; // Set subject and body template. - $subject_template ??= $params['subject_template']; - $body_templates ??= $params['body_template']; + $subject_template = $params['subject_template']; + $body_templates = $params['body_template']; break; // Do not send the message. diff --git a/modules/farm_rothamsted_quick/src/Plugin/QuickForm/QuickExperimentFormBase.php b/modules/farm_rothamsted_quick/src/Plugin/QuickForm/QuickExperimentFormBase.php index 7877eeca..c2765edb 100644 --- a/modules/farm_rothamsted_quick/src/Plugin/QuickForm/QuickExperimentFormBase.php +++ b/modules/farm_rothamsted_quick/src/Plugin/QuickForm/QuickExperimentFormBase.php @@ -970,7 +970,7 @@ protected function getGroupMemberOptions(array $group_names, array $asset_types $group_members = $this->groupMembership->getGroupMembers($groups); // If specified, filter group members to a single asset type. - if (!empty($asset_type)) { + if (!empty($asset_types)) { $group_members = array_filter($group_members, function (AssetInterface $asset) use ($asset_types) { return in_array($asset->getEntityTypeId(), $asset_types); });