Skip to content

Commit 99b4576

Browse files
committed
Code analysis fixes
1 parent 2b9f85e commit 99b4576

File tree

7 files changed

+85
-16
lines changed

7 files changed

+85
-16
lines changed

composer.json

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,47 @@
1111
],
1212
"minimum-stability": "dev",
1313
"prefer-stable": true,
14+
"repositories": [
15+
{
16+
"type": "composer",
17+
"url": "https://packages.drupal.org/8"
18+
}
19+
],
20+
"require": {
21+
"os2forms/os2forms": "^3.13"
22+
},
1423
"require-dev": {
24+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.2",
1525
"drupal/coder": "^8.3",
16-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
26+
"mglaman/drupal-check": "^1.4"
27+
},
28+
"config": {
29+
"sort-packages": true,
30+
"allow-plugins": {
31+
"dealerdirect/phpcodesniffer-composer-installer": true,
32+
"zaporylie/composer-drupal-optimizations": true,
33+
"cweagans/composer-patches": true,
34+
"simplesamlphp/composer-module-installer": true
35+
}
1736
},
1837
"scripts": {
19-
"coding-standards-check": "phpcs --standard=phpcs.xml.dist",
20-
"coding-standards-apply": "phpcbf --standard=phpcs.xml.dist"
38+
"code-analysis/drupal-check": [
39+
"vendor/bin/drupal-check --deprecations --analysis --exclude-dir=vendor *.* src"
40+
],
41+
"code-analysis": [
42+
"@code-analysis/drupal-check"
43+
],
44+
"coding-standards-check/phpcs": [
45+
"vendor/bin/phpcs --standard=phpcs.xml.dist"
46+
],
47+
"coding-standards-check": [
48+
"@coding-standards-check/phpcs"
49+
],
50+
"coding-standards-apply/phpcs": [
51+
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
52+
],
53+
"coding-standards-apply": [
54+
"@coding-standards-apply/phpcs"
55+
]
2156
}
2257
}

os2forms_user_field_lookup.module

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,33 @@ use Drupal\os2forms_user_field_lookup\WebformElementHelper;
1212
* Implements hook_webform_element_default_properties_alter().
1313
*
1414
* @see WebformElementHelper::alterDefaultProperties()
15+
*
16+
* @phpstan-param array<string, mixed> $properties
17+
* @phpstan-param array<string, mixed> $definition
1518
*/
16-
function os2forms_user_field_lookup_webform_element_default_properties_alter(array &$properties, array &$definition) {
19+
function os2forms_user_field_lookup_webform_element_default_properties_alter(array &$properties, array &$definition): void {
1720
Drupal::service(WebformElementHelper::class)->alterDefaultProperties($properties, $definition);
1821
}
1922

2023
/**
2124
* Implements hook_webform_element_translatable_properties_alter().
2225
*
2326
* @see WebformElementHelper::alterTranslatableProperties()
27+
*
28+
* @phpstan-param array<string, mixed> $properties
29+
* @phpstan-param array<string, mixed> $definition
2430
*/
25-
function os2forms_user_field_lookup_webform_element_translatable_properties_alter(array &$properties, array &$definition) {
31+
function os2forms_user_field_lookup_webform_element_translatable_properties_alter(array &$properties, array &$definition): void {
2632
Drupal::service(WebformElementHelper::class)->alterTranslatableProperties($properties, $definition);
2733
}
2834

2935
/**
3036
* Implements hook_webform_element_configuration_form_alter().
3137
*
3238
* @see WebformElementHelper::alterConfigurationForm()
39+
*
40+
* @phpstan-param array<string, mixed> $form
3341
*/
34-
function os2forms_user_field_lookup_webform_element_configuration_form_alter(&$form, FormStateInterface $form_state) {
42+
function os2forms_user_field_lookup_webform_element_configuration_form_alter(&$form, FormStateInterface $form_state): void {
3543
Drupal::service(WebformElementHelper::class)->alterConfigurationForm($form, $form_state);
3644
}

src/Element/UserFieldElement.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class UserFieldElement extends Textfield {
1313

1414
/**
1515
* {@inheritDoc}
16+
*
17+
* @phpstan-param array<string, mixed> $element
18+
* @phpstan-return array<string, mixed>
1619
*/
17-
public static function preRenderTextfield($element) {
20+
public static function preRenderTextfield($element): array {
1821
$element = parent::preRenderTextfield($element);
1922
static::setAttributes($element, ['os2forms-user-field-lookup']);
2023

src/Element/UserFieldElementCheckbox.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class UserFieldElementCheckbox extends Checkbox {
1313

1414
/**
1515
* {@inheritDoc}
16+
*
17+
* @phpstan-param array<string, mixed> $element
18+
* @phpstan-return array<string, mixed>
1619
*/
17-
public static function preRenderCheckbox($element) {
20+
public static function preRenderCheckbox($element): array {
1821
$element = parent::preRenderCheckbox($element);
1922
// @see https://stackoverflow.com/a/6905050
2023
$element['#attributes']['onclick'] = 'return false';

src/Plugin/WebformElement/UserFieldElement.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
namespace Drupal\os2forms_user_field_lookup\Plugin\WebformElement;
44

55
use Drupal\Component\Utility\NestedArray;
6-
use Drupal\webform\Plugin\WebformElement\TextField;
76
use Drupal\Core\Form\FormStateInterface;
7+
use Drupal\webform\Plugin\WebformElement\TextField;
88

99
/**
1010
* User field element.
@@ -20,6 +20,8 @@ class UserFieldElement extends TextField {
2020

2121
/**
2222
* {@inheritdoc}
23+
*
24+
* @phpstan-return array<string, mixed>
2325
*/
2426
protected function defineDefaultProperties() {
2527
return [
@@ -29,8 +31,11 @@ protected function defineDefaultProperties() {
2931

3032
/**
3133
* {@inheritdoc}
34+
*
35+
* @phpstan-param array<string, mixed> $element
36+
* @phpstan-param array<string, mixed> $form
3237
*/
33-
public function alterForm(array &$element, array &$form, FormStateInterface $form_state) {
38+
public function alterForm(array &$element, array &$form, FormStateInterface $form_state): void {
3439
if ($fieldName = $element['#os2forms_user_field_lookup_field_name'] ?? NULL) {
3540
if ($this->currentUser->isAuthenticated()) {
3641
/** @var \Drupal\user\Entity\User $user */

src/Plugin/WebformElement/UserFieldElementCheckbox.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class UserFieldElementCheckbox extends Checkbox {
2020

2121
/**
2222
* {@inheritdoc}
23+
*
24+
* @phpstan-return array<string, mixed>
2325
*/
2426
protected function defineDefaultProperties() {
2527
return [
@@ -29,8 +31,11 @@ protected function defineDefaultProperties() {
2931

3032
/**
3133
* {@inheritdoc}
34+
*
35+
* @phpstan-param array<string, mixed> $element
36+
* @phpstan-param array<string, mixed> $form
3237
*/
33-
public function alterForm(array &$element, array &$form, FormStateInterface $form_state) {
38+
public function alterForm(array &$element, array &$form, FormStateInterface $form_state): void {
3439
if ($fieldName = $element['#os2forms_user_field_lookup_field_name'] ?? NULL) {
3540
if ($this->currentUser->isAuthenticated()) {
3641
/** @var \Drupal\user\Entity\User $user */

src/WebformElementHelper.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,34 @@ public function __construct(EntityFieldManagerInterface $entityFieldManager) {
3232

3333
/**
3434
* Implements hook_webform_element_default_properties_alter().
35+
*
36+
* @phpstan-param array<string, mixed> $properties
37+
* @phpstan-param array<string, mixed> $definition
3538
*/
36-
public function alterDefaultProperties(array &$properties, array &$definition) {
39+
public function alterDefaultProperties(array &$properties, array &$definition): void {
3740
if ('os2forms_user_field_lookup' === ($definition['provider'] ?? NULL)) {
3841
$properties['os2forms_user_field_lookup_field_name'] = '';
3942
}
4043
}
4144

4245
/**
4346
* Implements hook_webform_element_translatable_properties_alter().
47+
*
48+
* @phpstan-param array<string, mixed> $properties
49+
* @phpstan-param array<string, mixed> $definition
4450
*/
45-
public function alterTranslatableProperties(array &$properties, array &$definition) {
51+
public function alterTranslatableProperties(array &$properties, array &$definition): void {
4652
// Make the custom data property translatable.
4753
$properties[] = 'os2forms_user_field_lookup_field_name';
4854
}
4955

5056
/**
5157
* Implements hook_webform_element_configuration_form_alter().
58+
*
59+
* @phpstan-param array<string, mixed> $form
5260
*/
53-
public function alterConfigurationForm(&$form, FormStateInterface $form_state) {
54-
/** @var Drupal\webform_ui\Form\WebformUiElementEditForm $formObject */
61+
public function alterConfigurationForm(&$form, FormStateInterface $form_state): void {
62+
/** @var \Drupal\webform_ui\Form\WebformUiElementEditForm $formObject */
5563
$formObject = $form_state->getFormObject();
5664
$elementPlugin = $formObject->getWebformElementPlugin();
5765
$pluginDefinition = $elementPlugin->getPluginDefinition();
@@ -77,8 +85,10 @@ public function alterConfigurationForm(&$form, FormStateInterface $form_state) {
7785

7886
/**
7987
* Get filter for user field definitions.
88+
*
89+
* @phpstan-param array<string, mixed> $pluginDefinition
8090
*/
81-
private function getUserFieldDefinitionFilter(array $pluginDefinition) {
91+
private function getUserFieldDefinitionFilter(array $pluginDefinition): mixed {
8292
switch ($pluginDefinition['class']) {
8393
case UserFieldElementCheckbox::class:
8494
// Get all custom boolean fields.

0 commit comments

Comments
 (0)