Skip to content

Commit 9052497

Browse files
Merge pull request #105 from localgovdrupal/fix/1.x/static-analysis-errors
fix: add return types
2 parents 6fa7ce7 + 123c350 commit 9052497

27 files changed

+57
-52
lines changed

localgov_forms.install

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
*/
77

88
use Drupal\Component\Serialization\Yaml;
9+
use Drupal\Core\StringTranslation\TranslatableMarkup;
910
use Drupal\webform\Entity\WebformOptions;
1011

1112
/**
1213
* Implements hook_install().
1314
*/
14-
function localgov_forms_install() {
15+
function localgov_forms_install(): void {
1516

1617
// Override Webforms default configuration.
1718
$config = \Drupal::configFactory()->getEditable('localgov_forms.webform.settings');
@@ -24,7 +25,7 @@ function localgov_forms_install() {
2425
*
2526
* Creates a Webform option for Local custodian codes.
2627
*/
27-
function localgov_forms_update_8001() {
28+
function localgov_forms_update_8001(): ?TranslatableMarkup {
2829

2930
$has_local_custodian_codes_option = Drupal::service('entity_type.manager')->getStorage('webform_options')->load('local_custodian_codes_gb');
3031
if ($has_local_custodian_codes_option) {
@@ -39,4 +40,6 @@ function localgov_forms_update_8001() {
3940
$local_custodian_codes_option = Yaml::decode(file_get_contents(__DIR__ . '/config/install/webform.webform_options.local_custodian_codes_gb.yml'));
4041
$new_local_custodian_codes_option = WebformOptions::create($local_custodian_codes_option);
4142
$new_local_custodian_codes_option->save();
43+
44+
return NULL;
4245
}

localgov_forms.module

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Drupal\Core\Render\Element;
1010
/**
1111
* Implements hook_theme().
1212
*/
13-
function localgov_forms_theme() {
13+
function localgov_forms_theme(): array {
1414
return [
1515
// Form element: localgov_webform_uk_address.
1616
'localgov_forms_uk_address_lookup' => [
@@ -29,7 +29,7 @@ function localgov_forms_theme() {
2929
* Makes sub-elements available within the `content` variable. Mostly lifted
3030
* from _template_preprocess_webform_composite().
3131
*/
32-
function template_preprocess_localgov_forms_uk_address_lookup(array &$variables) {
32+
function template_preprocess_localgov_forms_uk_address_lookup(array &$variables): void {
3333

3434
$element = $variables['element'];
3535
foreach (Element::children($element) as $key) {
@@ -44,14 +44,14 @@ function template_preprocess_localgov_forms_uk_address_lookup(array &$variables)
4444
/**
4545
* Prepares variables for the UK address element template.
4646
*/
47-
function template_preprocess_localgov_forms_uk_address(array &$variables) {
47+
function template_preprocess_localgov_forms_uk_address(array &$variables): void {
4848

4949
template_preprocess_localgov_forms_uk_address_lookup($variables);
5050
}
5151

5252
/**
5353
* Implements hook_preprocess_hook() for hook_preprocess_webform().
5454
*/
55-
function localgov_forms_preprocess_webform(array &$variables) {
55+
function localgov_forms_preprocess_webform(array &$variables): void {
5656
$variables['#attached']['library'][] = 'localgov_forms/localgov_forms.form_errors';
5757
}

localgov_forms.tokens.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use Drupal\webform\Utility\WebformDateHelper;
1616
*
1717
* Token declarations.
1818
*/
19-
function localgov_forms_token_info() {
19+
function localgov_forms_token_info(): array {
2020

2121
return [
2222
'tokens' => [
@@ -42,7 +42,7 @@ function localgov_forms_token_info() {
4242
*
4343
* @see system_tokens()
4444
*/
45-
function localgov_forms_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
45+
function localgov_forms_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata): array {
4646

4747
$replacements = [];
4848

modules/localgov_forms_date/localgov_forms_date.install

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use Drupal\Component\Serialization\Yaml;
1010
/**
1111
* Adds a UK short date style e.g dd-mm-yyyy.
1212
*/
13-
function localgov_forms_date_update_8001() {
13+
function localgov_forms_date_update_8001(): void {
1414
$config_id = 'core.date_format.localgov_forms_date_short_date';
1515
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
1616
$uk_short_html_date_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
@@ -20,7 +20,7 @@ function localgov_forms_date_update_8001() {
2020
/**
2121
* Adds a UK short date style e.g dd-mm-yyyy HH:mm:ss.
2222
*/
23-
function localgov_forms_date_update_8002() {
23+
function localgov_forms_date_update_8002(): void {
2424
$config_id = 'core.date_format.localgov_forms_date_datetime';
2525
$config_path = \Drupal::service('extension.list.module')->getPath('localgov_forms_date');
2626
$uk_html_datetime_config = Yaml::decode(file_get_contents($config_path . '/config/install/' . $config_id . '.yml'));
@@ -30,7 +30,7 @@ function localgov_forms_date_update_8002() {
3030
/**
3131
* Adds a UUID to LocalGov Forms Date formats.
3232
*/
33-
function localgov_forms_date_update_8003() {
33+
function localgov_forms_date_update_8003(): void {
3434
$localgov_date_formats = [
3535
'core.date_format.localgov_forms_date_short_date',
3636
'core.date_format.localgov_forms_date_datetime',

modules/localgov_forms_date/localgov_forms_date.module

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Datetime Form preprocess function.
1010
*/
11-
function localgov_forms_date_preprocess_datetime_form(array &$variables) {
11+
function localgov_forms_date_preprocess_datetime_form(array &$variables): void {
1212
// Check that this is a localgov_forms_date form element.
1313
if ($variables['element']['#type'] === 'localgov_forms_date') {
1414
$variables['attributes']['class'][] = 'localgov-forms-date';

modules/localgov_forms_date/src/Element/LocalgovFormsDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private static function restoreUnprocessedDate(array &$element) :void {
132132
* be set in the UI which should take precedence over
133133
* the default error message.
134134
*/
135-
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form) {
135+
public static function validateDatelist(&$element, FormStateInterface $form_state, &$complete_form): void {
136136
$input_exists = FALSE;
137137
$input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists);
138138

modules/localgov_forms_date/src/Plugin/WebformElement/LocalgovFormsDate.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function form(array $form, FormStateInterface $form_state) {
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
68+
public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {
6969
parent::validateConfigurationForm($form, $form_state);
7070
$values = $form_state->getValues();
7171
$values['date_part_order'] = ['day', 'month', 'year'];
@@ -77,7 +77,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
7777
/**
7878
* After build handler for Datelist element.
7979
*/
80-
public static function afterBuild(array $element, FormStateInterface $form_state) {
80+
public static function afterBuild(array $element, FormStateInterface $form_state): array {
8181
$element = parent::afterBuild($element, $form_state);
8282

8383
// Set the property of the date of birth elements.
@@ -112,7 +112,7 @@ public static function afterBuild(array $element, FormStateInterface $form_state
112112
*
113113
* @see Drupal\Webform\Plugin\WebformElement\DateBase::setDefaultValue()
114114
*/
115-
public function setDefaultValue(array &$element) {
115+
public function setDefaultValue(array &$element): void {
116116

117117
$orig_type = $element['#type'];
118118
$element['#type'] = 'datelist';
@@ -127,7 +127,7 @@ public function setDefaultValue(array &$element) {
127127
* date validation error messages display in
128128
* a UK Style format e.g dd-mm-yyyy.
129129
*/
130-
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form) {
130+
public static function validateDate(&$element, FormStateInterface $form_state, &$complete_form): void {
131131

132132
// Adds a short date and short date time format.
133133
$localgov_forms_short_date_format = DateFormat::load('localgov_forms_date_short_date')->getPattern();

modules/localgov_forms_date/tests/src/Kernel/DateWebformElementTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DateWebformElementTest extends KernelTestBase {
1717
/**
1818
* Tests a webform with our date field.
1919
*/
20-
public function testFormSubmission() {
20+
public function testFormSubmission(): void {
2121

2222
$this->passCase();
2323
$this->failCaseWithInvalidDay();
@@ -28,7 +28,7 @@ public function testFormSubmission() {
2828
/**
2929
* Tests valid date.
3030
*/
31-
protected function passCase() {
31+
protected function passCase(): void {
3232

3333
$form_state = new FormState();
3434
$form_state->setValue('date',
@@ -42,7 +42,7 @@ protected function passCase() {
4242
/**
4343
* Tests date with invalid day.
4444
*/
45-
protected function failCaseWithInvalidDay() {
45+
protected function failCaseWithInvalidDay(): void {
4646

4747
$form_state = new FormState();
4848
$form_state->setValue('date', ['day' => '1D']);
@@ -55,7 +55,7 @@ protected function failCaseWithInvalidDay() {
5555
/**
5656
* Tests date with nonnumeric day.
5757
*/
58-
protected function failCaseWithNonNumericDay() {
58+
protected function failCaseWithNonNumericDay(): void {
5959

6060
$form_state = new FormState();
6161
$form_state->setValue('date',
@@ -69,7 +69,7 @@ protected function failCaseWithNonNumericDay() {
6969
/**
7070
* Tests date with invalid year.
7171
*/
72-
protected function failCaseWithInvalidYear() {
72+
protected function failCaseWithInvalidYear(): void {
7373

7474
$form_state = new FormState();
7575
$form_state->setValue('date',
@@ -83,7 +83,7 @@ protected function failCaseWithInvalidYear() {
8383
/**
8484
* {@inheritdoc}
8585
*/
86-
protected function setUp() :void {
86+
protected function setUp(): void {
8787

8888
parent::setUp();
8989

modules/localgov_forms_example_liberty_create_integration/localgov_forms_example_liberty_create_integration.module

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use Drupal\webform\WebformSubmissionInterface;
2020
* - DRUPAL_LIBERTY_CREATE_API_USERNAME
2121
* - DRUPAL_LIBERTY_CREATE_API_USER_KEY.
2222
*/
23-
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing) {
23+
function localgov_forms_example_liberty_create_integration_modules_installed($modules, $is_syncing): void {
2424

2525
if (!$is_syncing && in_array('token_environment', $modules, TRUE)) {
2626
$token_env_config = Drupal::service('config.factory')->getEditable('token_environment.settings');
@@ -48,7 +48,7 @@ function localgov_forms_example_liberty_create_integration_modules_installed($mo
4848
* `[webform_submission:values:name:extracted_lastname:clear]` will resolve to
4949
* "Bar".
5050
*/
51-
function localgov_forms_example_liberty_create_integration_tokens_alter(array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata) {
51+
function localgov_forms_example_liberty_create_integration_tokens_alter(array &$replacements, array $context, BubbleableMetadata $bubbleable_metadata): void {
5252

5353
if ($context['type'] === 'webform_submission' && !empty($context['data']['webform_submission'])) {
5454
$firstname_extraction_tokens = array_filter($context['tokens'], fn($token) => strpos($token, ':extracted_firstname'));
@@ -76,7 +76,7 @@ function localgov_forms_example_liberty_create_integration_tokens_alter(array &$
7676
* @see localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter()
7777
* @see localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter()
7878
*/
79-
function localgov_forms_example_liberty_create_integration_token_info_alter(&$token_info) {
79+
function localgov_forms_example_liberty_create_integration_token_info_alter(&$token_info): void {
8080

8181
$token_info['tokens']['webform_submission']['values:?:file_details_for_liberty_create_api'] = [
8282
'name' => t('File detail for Liberty Create API'),
@@ -87,7 +87,7 @@ function localgov_forms_example_liberty_create_integration_token_info_alter(&$to
8787
/**
8888
* Implements hook_webform_handler_invoke_METHOD_NAME_alter() for hook_webform_handler_invoke_post_save_alter().
8989
*/
90-
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter(WebformHandlerInterface $handler, array &$args) {
90+
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter(WebformHandlerInterface $handler, array &$args): void {
9191

9292
$handler_id = $handler->getHandlerId();
9393
if ($handler_id === 'remote_post' || $handler_id === 'async_remote_post') {
@@ -100,7 +100,7 @@ function localgov_forms_example_liberty_create_integration_webform_handler_invok
100100
*
101101
* Relevant during Queue processing.
102102
*/
103-
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter(WebformHandlerInterface $handler, array &$args) {
103+
function localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_load_alter(WebformHandlerInterface $handler, array &$args): void {
104104

105105
localgov_forms_example_liberty_create_integration_webform_handler_invoke_post_save_alter($handler, $args);
106106
}
@@ -121,7 +121,7 @@ function localgov_forms_example_liberty_create_integration_webform_handler_invok
121121
*
122122
* @see Drupal\webform\Plugin\WebformHandler\RemotePostWebformHandler::getRequestData()
123123
*/
124-
function _localgov_forms_example_liberty_create_integration_manage_remote_post_custom_data(WebformHandlerInterface $handler) {
124+
function _localgov_forms_example_liberty_create_integration_manage_remote_post_custom_data(WebformHandlerInterface $handler): void {
125125

126126
$webform_submission = $handler->getWebformSubmission();
127127
if (!$webform_submission instanceof WebformSubmissionInterface) {

modules/localgov_forms_feedback_form/localgov_forms_feedback_form.install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
/**
99
* Implements hook_install().
1010
*/
11-
function localgov_forms_feedback_form_install() {
11+
function localgov_forms_feedback_form_install(): void {
1212
\Drupal::messenger()->addStatus(t('You have installed the LocalGov Forms Feedback Form. This form stores the form submissions in the database. Make sure you have checked this is okay with your data protection officer, or else change the form settings to store the data somewhere else.'));
1313
}

0 commit comments

Comments
 (0)