Skip to content

Commit 996ff27

Browse files
cablemanrimi-itk
andcommitted
ITKDev: Code review changes
Co-authored-by: Mikkel Ricky <[email protected]>
1 parent babbaf1 commit 996ff27

26 files changed

+403
-172
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)
4747
// CVR lookup
4848
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
4949
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
50-
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCompany $cvrPlugin */
50+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCompanyInterface $cvrPlugin */
5151
$cvrPlugin = $pluginManager->createDefaultInstanceByGroup('cvr_lookup');
5252

5353
if ($cvrPlugin->isReady()) {
@@ -57,7 +57,7 @@ if ($cvrPlugin->isReady()) {
5757
// CPR lookup.
5858
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
5959
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
60-
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr $cprPlugin */
60+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCprInterface $cprPlugin */
6161
$cprPlugin = $pluginManager->createDefaultInstanceByGroup('cpr_lookup');
6262

6363
if ($cprPlugin->isReady()) {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"require-dev": {
22-
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
22+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
2323
"drupal/coder": "^8.3",
2424
"mglaman/phpstan-drupal": "^1.1",
2525
"phpstan/extension-installer": "^1.3",

os2web_datalookup.install

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
22

3+
/**
4+
* @file
5+
* Install, uninstall and update hooks for the module.
6+
*/
7+
38
use Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm;
49

510
/**
611
* Setting "serviceplatformen_cpr_extended" as default CPR lookup plugin.
712
*/
8-
function os2web_datalookup_update_9001() {
13+
function os2web_datalookup_update_9001(): void {
914
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
1015
$config->set("cpr_lookup.default_plugin", 'serviceplatformen_cpr_extended');
1116
$config->save();
@@ -14,7 +19,7 @@ function os2web_datalookup_update_9001() {
1419
/**
1520
* Setting "datafordeler_cvr" as default CVR lookup plugin.
1621
*/
17-
function os2web_datalookup_update_9002() {
22+
function os2web_datalookup_update_9002(): void {
1823
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
1924
$config->set("cvr_lookup.default_plugin", 'datafordeler_cvr');
2025
$config->save();
@@ -23,7 +28,7 @@ function os2web_datalookup_update_9002() {
2328
/**
2429
* Setting "datafordeler_pnumber" as default P-Number lookup plugin.
2530
*/
26-
function os2web_datalookup_update_9003() {
31+
function os2web_datalookup_update_9003(): void {
2732
$config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName);
2833
$config->set("pnumber_lookup.default_plugin", 'datafordeler_pnumber');
2934
$config->save();

phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ruleset name="PHP_CodeSniffer">
3-
<description>OS2web Audit PHP Code Sniffer configuration</description>
3+
<description>OS2web Datalookup PHP Code Sniffer configuration</description>
44

55
<file>.</file>
66
<exclude-pattern>vendor/</exclude-pattern>

phpstan.neon

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,6 @@ parameters:
88
- '*/node_modules/*'
99
ignoreErrors:
1010
# This is how drupal works....
11-
- '#Unsafe usage of new static\(\).#'
12-
- '#getEditableConfigNames\(\) return type has no value type specified in iterable type array#'
13-
- '#buildForm\(\) has parameter \$form with no value type specified in iterable type array.#'
14-
- '#buildForm\(\) return type has no value type specified in iterable type array.#'
15-
- '#validateForm\(\) has parameter \$form with no value type specified in iterable type array.#'
16-
- '#submitForm\(\) has parameter \$form with no value type specified in iterable type array.#'
17-
- '#getDerivativeDefinitions\(\) has parameter \$base_plugin_definition with no value type specified in iterable type array.#'
18-
- '#getDerivativeDefinitions\(\) return type has no value type specified in iterable type array.#'
19-
- '#LoggerManager::__construct\(\) has parameter \$namespaces with no value type specified in iterable type Traversable.#'
20-
- '#__construct\(\) has parameter \$configuration with no value type specified in iterable type array.#'
21-
- '#getConfiguration\(\) return type has no value type specified in iterable type array.#'
22-
- '#setConfiguration\(\) has parameter \$configuration with no value type specified in iterable type array.#'
23-
- '#defaultConfiguration\(\) return type has no value type specified in iterable type array.#'
24-
- '#buildConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
25-
- '#buildConfigurationForm\(\) return type has no value type specified in iterable type array.#'
26-
- '#validateConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
27-
- '#submitConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#'
28-
- '#getForm\(\) invoked with 2 parameters, 1 required.#'
11+
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
12+
- '#The text '@deprecated use lookup\(\) instead.' does not match the standard format: @deprecated in %deprecation-version% and is#'
13+
- '#Each @deprecated tag must have a @see tag immediately following it#'

src/Annotation/DataLookup.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\os2web_datalookup\Annotation;
44

55
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Core\Annotation\Translation;
67

78
/**
89
* Defines a AuthProvider annotation object.
@@ -22,7 +23,7 @@ class DataLookup extends Plugin {
2223
*
2324
* @var string
2425
*/
25-
public $id;
26+
public string $id;
2627

2728
/**
2829
* The human-readable name of the consent storage.
@@ -31,24 +32,24 @@ class DataLookup extends Plugin {
3132
*
3233
* @ingroup plugin_translatable
3334
*/
34-
public $label;
35+
public Translation $label;
3536

3637
/**
3738
* A brief description of the consent storage.
3839
*
3940
* This will be shown when adding or configuring this consent storage.
4041
*
41-
* @var \Drupal\Core\Annotation\Translation
42+
* @var \Drupal\Core\Annotation\Translation|string
4243
*
4344
* @ingroup plugin_translatable
4445
*/
45-
public $description = '';
46+
public Translation|string $description = '';
4647

4748
/**
48-
* Group of the plugin lookup plugin.
49+
* Group of the plugin lookup plugins.
4950
*
5051
* @var string
5152
*/
52-
public $group = '';
53+
public string $group = '';
5354

5455
}

src/Controller/DatalookupController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
use Drupal\Component\Plugin\PluginManagerInterface;
66
use Drupal\Core\Controller\ControllerBase;
77
use Drupal\Core\Link;
8-
use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface;
98
use Symfony\Component\DependencyInjection\ContainerInterface;
109

1110
/**
12-
* Class DatalookupController.
11+
* Data lookup controller.
1312
*
1413
* @package Drupal\os2web_datalookup\Controller
1514
*/
@@ -20,10 +19,13 @@ class DatalookupController extends ControllerBase {
2019
*
2120
* @var \Drupal\Component\Plugin\PluginManagerInterface
2221
*/
23-
protected $manager;
22+
protected PluginManagerInterface $manager;
2423

2524
/**
26-
* {@inheritdoc}
25+
* Default constructor.
26+
*
27+
* @param \Drupal\Component\Plugin\PluginManagerInterface $manager
28+
* The plugin manger.
2729
*/
2830
public function __construct(PluginManagerInterface $manager) {
2931
$this->manager = $manager;
@@ -40,8 +42,13 @@ public static function create(ContainerInterface $container) {
4042

4143
/**
4244
* Status list callback.
45+
*
46+
* @return array<string, mixed>
47+
* An render array.
48+
*
49+
* @throws \Drupal\Component\Plugin\Exception\PluginException
4350
*/
44-
public function statusList() {
51+
public function statusList(): array {
4552
$headers = [
4653
'title' => $this
4754
->t('Title'),
@@ -55,7 +62,7 @@ public function statusList() {
5562

5663
$rows = [];
5764
foreach ($this->manager->getDefinitions() as $id => $plugin_definition) {
58-
/** @var DataLookupInterface $plugin */
65+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $plugin */
5966
$plugin = $this->manager->createInstance($id);
6067
$status = $plugin->getStatus();
6168
$rows[$id] = [

src/Form/DataLookupPluginGroupSettingsForm.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\Core\Form\ConfigFormBase;
77
use Drupal\Core\Form\FormStateInterface;
88
use Drupal\Core\Link;
9+
use Drupal\os2web_datalookup\Plugin\DataLookupManager;
910
use Symfony\Component\DependencyInjection\ContainerInterface;
1011

1112
/**
@@ -18,16 +19,20 @@ class DataLookupPluginGroupSettingsForm extends ConfigFormBase {
1819
*
1920
* @var string
2021
*/
21-
public static $configName = 'os2web_datalookup.groups.settings';
22+
public static string $configName = 'os2web_datalookup.groups.settings';
2223

23-
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager */
24-
protected $dataLookupManager;
24+
/**
25+
* Data lookup manager.
26+
*
27+
* @var \Drupal\os2web_datalookup\Plugin\DataLookupManager
28+
*/
29+
protected DataLookupManager $dataLookupManager;
2530

2631
/**
2732
* Constructs a new DataLookupPluginGroupSettingsForm object.
2833
*
29-
* @param \Drupal\os2web_datalookup\Plugin\DataLookupManager
30-
* Datalookup manager.
34+
* @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookupManager
35+
* Data lookup manager.
3136
*/
3237
public function __construct(PluginManagerInterface $dataLookupManager) {
3338
$this->dataLookupManager = $dataLookupManager;
@@ -36,7 +41,7 @@ public function __construct(PluginManagerInterface $dataLookupManager) {
3641
/**
3742
* {@inheritdoc}
3843
*/
39-
public static function create(ContainerInterface $container) {
44+
public static function create(ContainerInterface $container): static {
4045
return new static(
4146
$container->get('plugin.manager.os2web_datalookup')
4247
);
@@ -52,7 +57,7 @@ public function getFormId() {
5257
/**
5358
* {@inheritdoc}
5459
*/
55-
protected function getEditableConfigNames() {
60+
protected function getEditableConfigNames(): array {
5661
return [DataLookupPluginGroupSettingsForm::$configName];
5762
}
5863

@@ -69,7 +74,7 @@ protected function getGroupIdFromRequest() {
6974
/**
7075
* {@inheritdoc}
7176
*/
72-
public function buildForm(array $form, FormStateInterface $form_state) {
77+
public function buildForm(array $form, FormStateInterface $form_state): array {
7378
$group_id = $this->getGroupIdFromRequest();
7479

7580
$plugin_definitions = $this->dataLookupManager->getDefinitionsByGroup($group_id);
@@ -114,7 +119,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
114119
/**
115120
* {@inheritdoc}
116121
*/
117-
public function submitForm(array &$form, FormStateInterface $form_state) {
122+
public function submitForm(array &$form, FormStateInterface $form_state): void {
118123
$group_id = $this->getGroupIdFromRequest();
119124

120125
$config = $this->config(DataLookupPluginGroupSettingsForm::$configName);

src/Form/DataLookupPluginSettingsForm.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(ConfigFactoryInterface $config_factory, PluginManage
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public static function create(ContainerInterface $container) {
25+
public static function create(ContainerInterface $container): static {
2626
return new static(
2727
$container->get('config.factory'),
2828
$container->get('plugin.manager.os2web_datalookup')
@@ -32,7 +32,7 @@ public static function create(ContainerInterface $container) {
3232
/**
3333
* {@inheritdoc}
3434
*/
35-
public static function getConfigName() {
35+
public static function getConfigName(): string {
3636
return 'os2web_datalookup';
3737
}
3838

src/Form/PluginSettingsFormBase.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Abstract class for PluginSettingsForm implementation.
88
*/
99

10+
use Drupal\Component\Plugin\PluginManagerInterface;
1011
use Drupal\Core\Form\ConfigFormBase;
1112
use Drupal\Core\Form\FormStateInterface;
1213

@@ -20,36 +21,37 @@ abstract class PluginSettingsFormBase extends ConfigFormBase implements PluginSe
2021
*
2122
* @var \Drupal\Component\Plugin\PluginManagerInterface
2223
*/
23-
protected $manager;
24+
protected PluginManagerInterface $manager;
2425

2526
/**
2627
* {@inheritdoc}
2728
*/
28-
protected function getEditableConfigNames() {
29+
protected function getEditableConfigNames(): array {
2930
return [$this->getConfigId()];
3031
}
3132

3233
/**
3334
* {@inheritdoc}
3435
*/
35-
public function getFormId() {
36+
public function getFormId(): string {
3637
return $this->getConfigName() . '_settings_form_' . $this->getPluginIdFromRequest();
3738
}
3839

3940
/**
4041
* {@inheritdoc}
4142
*/
42-
public function buildForm(array $form, FormStateInterface $form_state) {
43+
public function buildForm(array $form, FormStateInterface $form_state): array {
4344
$plugin_id = $this->getPluginIdFromRequest();
4445
$instance = $this->getPluginInstance($plugin_id);
4546
$form = $instance->buildConfigurationForm($form, $form_state);
47+
4648
return parent::buildForm($form, $form_state);
4749
}
4850

4951
/**
5052
* {@inheritdoc}
5153
*/
52-
public function validateForm(array &$form, FormStateInterface $form_state) {
54+
public function validateForm(array &$form, FormStateInterface $form_state): void {
5355
$plugin_id = $this->getPluginIdFromRequest();
5456
$instance = $this->getPluginInstance($plugin_id);
5557
$instance->validateConfigurationForm($form, $form_state);
@@ -58,7 +60,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
5860
/**
5961
* {@inheritdoc}
6062
*/
61-
public function submitForm(array &$form, FormStateInterface $form_state) {
63+
public function submitForm(array &$form, FormStateInterface $form_state): void {
6264
$plugin_id = $this->getPluginIdFromRequest();
6365
$instance = $this->getPluginInstance($plugin_id);
6466
$instance->submitConfigurationForm($form, $form_state);
@@ -77,6 +79,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
7779
*/
7880
protected function getPluginIdFromRequest() {
7981
$request = $this->getRequest();
82+
8083
return $request->get('_plugin_id');
8184
}
8285

@@ -89,11 +92,12 @@ protected function getPluginIdFromRequest() {
8992
* @return object
9093
* Plugin instance.
9194
*
92-
* @throws PluginException
95+
* @throws \Drupal\Component\Plugin\Exception\PluginException
9396
*/
94-
public function getPluginInstance($plugin_id) {
97+
public function getPluginInstance($plugin_id): object {
9598
$configuration = $this->config($this->getConfigId())->get();
9699
$instance = $this->manager->createInstance($plugin_id, $configuration);
100+
97101
return $instance;
98102
}
99103

@@ -103,7 +107,7 @@ public function getPluginInstance($plugin_id) {
103107
* @return string
104108
* Configuration object name.
105109
*/
106-
protected function getConfigId() {
110+
protected function getConfigId(): string {
107111
return $this->getConfigName() . '.' . $this->getPluginIdFromRequest();
108112
}
109113

0 commit comments

Comments
 (0)