Skip to content

Commit 4ccf6e4

Browse files
committed
ITKDev: Code style fixes in plugins
1 parent f0a3948 commit 4ccf6e4

14 files changed

+119
-99
lines changed

README.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
# OS2Web Data lookup [![Build Status](https://travis-ci.org/OS2web/os2web_datalookup.svg?branch=8.x)](https://travis-ci.org/OS2web/os2web_datalookup)
2+
23
## Install
34

4-
OS2Web Data lookup provides integration with Danish data lookup services such as Service platformen or Datafordeler.
5-
Module is available to download via composer.
6-
```
5+
OS2Web Data lookup provides integration with Danish data lookup services such as
6+
Service platformen or Datafordeler. Module is available to download via
7+
composer.
8+
9+
```shell
710
composer require os2web/os2web_datalookup
811
drush en os2web_datalookup
912
```
1013

1114
## Update
12-
Updating process for OS2Web Data lookup module is similar to usual Drupal 8 module.
13-
Use Composer's built-in command for listing packages that have updates available:
15+
Updating process for OS2Web Data lookup module is similar to the usual Drupal 8
16+
module. Use Composer's built-in command for listing packages that have updates
17+
available:
1418

15-
```
19+
```shell
1620
composer outdated os2web/os2web_datalookup
1721
```
1822

1923
## Automated testing and code quality
24+
2025
See [OS2Web testing and CI information](https://github.com/OS2Web/docs#testing-and-ci)
2126

2227
## Contribution
2328

2429
Project is opened for new features and os course bugfixes.
25-
If you have any suggestion or you found a bug in project, you are very welcome
26-
to create an issue in github repository issue tracker.
27-
For issue description there is expected that you will provide clear and
28-
sufficient information about your feature request or bug report.
30+
If you have any suggestion, or you found a bug in project, you are very welcome
31+
to create an issue in GitHub repository issue tracker. For issue description,
32+
there is expected that you will provide clear and sufficient information about
33+
your feature request or bug report.
2934

3035
### Code review policy
36+
3137
See [OS2Web code review policy](https://github.com/OS2Web/docs#code-review)
3238

3339
### Git name convention
40+
3441
See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)
3542

3643
### Using services in other modules
3744

38-
```
45+
```php
3946
// CVR lookup
4047
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
4148
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
@@ -68,22 +75,25 @@ if ($cprPlugin->isReady()) {
6875

6976
### Datafordeler integration (https://datafordeler.dk)
7077

71-
In scope of os2forms project already implemented light integration
72-
with Danmarks Adresseregister (DAR) via fetching data for form elements
73-
autocomplete. See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms)
78+
In the scope of os2forms project already implemented light integration with
79+
Danmarks Adresseregister (DAR) via fetching data for form elements autocomplete.
80+
81+
See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms)
7482

7583
As soon as it is clear how the integration is going to be used, then
76-
os2forms_dawa will be refactored to OS2Web Data lookup plugin plugin.
84+
os2forms_dawa will be refactored to OS2Web Data lookup plugin.
7785

7886
## Important notes
87+
7988
### Serviceplatformen plugins
80-
Settings for CPR and CVR serviceplantormen plugins are storing as configuration
81-
in db and will(could) be exported as `yml` file via Drupal configuration
82-
management system. And afterwards could be tracked by `git`.
8389

84-
If case you have public access to your git repository all setting from plugins
90+
Settings for CPR and CVR serviceplatformen plugins are storing as configuration
91+
in db and will(could) be exported as `yml` file via Drupal's configuration
92+
management system. And afterward could be tracked by `git`.
93+
94+
If case you have public access to your git repository, all settings from plugins
8595
will be exposed for third persons.
8696

87-
To avoid/prevent this behavior we recommend use `Config ignore` module, where
88-
you can add all settings you do not want to export/import via configuration
97+
To avoid/prevent this behavior, we recommend use `Config ignore` module, where
98+
you can add all settings you do not want to export/import via the configuration
8999
management system.

src/Plugin/DataLookupManager.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class DataLookupManager extends DefaultPluginManager {
2323
*
2424
* @var \Drupal\Core\Config\ConfigFactoryInterface
2525
*/
26-
protected $configFactory;
26+
protected ConfigFactoryInterface $configFactory;
2727

2828
/**
29-
* Constructs an DataLookupManager object.
29+
* Constructs a DataLookupManager object.
3030
*
3131
* @param \Traversable $namespaces
3232
* An object that implements \Traversable which contains the root paths
@@ -54,7 +54,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
5454
/**
5555
* {@inheritdoc}
5656
*/
57-
public function createInstance($plugin_id, array $configuration = []) {
57+
public function createInstance($plugin_id, array $configuration = []): object {
5858
// Hard switch to another plugin fallback - see
5959
// https://os2web.atlassian.net/browse/OS2FORMS-359.
6060
if ($plugin_id == 'serviceplatformen_cpr') {
@@ -81,7 +81,7 @@ public function createInstance($plugin_id, array $configuration = []) {
8181
* @throws \Drupal\Component\Plugin\Exception\PluginException
8282
* If the instance cannot be created, such as if the ID is invalid.
8383
*/
84-
public function createDefaultInstanceByGroup($group_id) {
84+
public function createDefaultInstanceByGroup(string $group_id): object {
8585
$plugin_id = $this->getGroupDefaultPlugin($group_id);
8686
return $this->createInstance($plugin_id);
8787
}
@@ -92,11 +92,11 @@ public function createDefaultInstanceByGroup($group_id) {
9292
* @param $group_id
9393
* Group id.
9494
*
95-
* @return mixed[]
95+
* @return array
9696
* An array of plugin definitions (empty array if no definitions were
9797
* found). Keys are plugin IDs.
9898
*/
99-
public function getDefinitionsByGroup($group_id) {
99+
public function getDefinitionsByGroup($group_id): array {
100100
$definitions = [];
101101
foreach ($this->getDefinitions() as $id => $plugin_definition) {
102102
if ($plugin_definition['group'] == $group_id) {
@@ -113,11 +113,11 @@ public function getDefinitionsByGroup($group_id) {
113113
* @return array
114114
* Array of groups, keyed by group_id.
115115
*/
116-
public function getDatalookupGroups() {
116+
public function getDatalookupGroups(): array {
117117
$definitions = $this->getDefinitions();
118118
$groups = [];
119119
foreach ($definitions as $definition) {
120-
if (isset($definition['group']) && !empty($definition['group'])) {
120+
if (!empty($definition['group'])) {
121121
$groups[$definition['group']] = $definition['group'];
122122
}
123123
}
@@ -134,8 +134,9 @@ public function getDatalookupGroups() {
134134
* @return string|null
135135
* Plugin ID or NULL is not set.
136136
*/
137-
public function getGroupDefaultPlugin($group_id) {
137+
public function getGroupDefaultPlugin($group_id): ?string {
138138
$config = \Drupal::config(DataLookupPluginGroupSettingsForm::$configName);
139+
139140
return $config->get("$group_id.default_plugin");
140141
}
141142

src/Plugin/os2web/DataLookup/DataLookupBase.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,23 @@ public function label() {
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function getConfiguration() {
45+
public function getConfiguration(): array {
4646
return $this->configuration;
4747
}
4848

4949
/**
5050
* {@inheritdoc}
5151
*/
52-
public function setConfiguration(array $configuration) {
52+
public function setConfiguration(array $configuration): static {
5353
$this->configuration = $configuration + $this->defaultConfiguration();
54+
5455
return $this;
5556
}
5657

5758
/**
5859
* {@inheritdoc}
5960
*/
60-
public function defaultConfiguration() {
61+
public function defaultConfiguration(): array {
6162
return [];
6263
}
6364

@@ -71,7 +72,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
7172
/**
7273
* {@inheritdoc}
7374
*/
74-
public function getStatus() {
75+
public function getStatus(): string {
7576
return 'N/A';
7677
}
7778

@@ -85,7 +86,7 @@ public function getGroup() {
8586
/**
8687
* {@inheritdoc}
8788
*/
88-
public function isReady() {
89+
public function isReady(): bool {
8990
return $this->isReady;
9091
}
9192

src/Plugin/os2web/DataLookup/DataLookupInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface DataLookupInterface extends PluginInspectionInterface, PluginFormInter
2222
public function getStatus();
2323

2424
/**
25-
* Get plugin group.
25+
* Get a plugin group.
2626
*/
2727
public function getGroup();
2828

src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup;
44

5+
use Drupal\os2web_datalookup\LookupResult\CompanyLookupResult;
6+
57
interface DataLookupInterfaceCompany extends DataLookupInterface {
68

79
/**
@@ -13,6 +15,6 @@ interface DataLookupInterfaceCompany extends DataLookupInterface {
1315
* @return \Drupal\os2web_datalookup\LookupResult\CompanyLookupResult
1416
* The company lookup Result.
1517
*/
16-
public function lookup($param);
18+
public function lookup(string $param): CompanyLookupResult;
1719

1820
}

src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup;
44

5+
use Drupal\os2web_datalookup\LookupResult\CprLookupResult;
6+
57
interface DataLookupInterfaceCpr extends DataLookupInterface {
68

79
/**
@@ -13,6 +15,6 @@ interface DataLookupInterfaceCpr extends DataLookupInterface {
1315
* @return \Drupal\os2web_datalookup\LookupResult\CprLookupResult
1416
* The CPR lookup Result.
1517
*/
16-
public function lookup($cpr);
18+
public function lookup(string $cpr): CprLookupResult;
1719

1820
}

src/Plugin/os2web/DataLookup/DatafordelerBase.php

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

55
use Drupal\Core\Form\FormStateInterface;
6+
use Drupal\Core\StringTranslation\TranslatableMarkup;
67
use GuzzleHttp\Client;
78

89
/**
@@ -13,9 +14,9 @@ abstract class DatafordelerBase extends DataLookupBase {
1314
/**
1415
* Plugin readiness flag.
1516
*
16-
* @var bool
17+
* @var Client
1718
*/
18-
protected $httpClient;
19+
protected Client $httpClient;
1920

2021
/**
2122
* {@inheritdoc}
@@ -28,7 +29,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
2829
/**
2930
* Plugin init method.
3031
*/
31-
private function init() {
32+
private function init(): void {
3233
$this->isReady = FALSE;
3334

3435
$configuration = $this->getConfiguration();
@@ -51,8 +52,8 @@ private function init() {
5152
/**
5253
* {@inheritdoc}
5354
*/
54-
public function getStatus() {
55-
if ($this->httpClient) {
55+
public function getStatus(): string|TranslatableMarkup {
56+
if (isset($this->httpClient)) {
5657
return $this->t('Plugin is ready to work');
5758
}
5859
else {
@@ -63,7 +64,7 @@ public function getStatus() {
6364
/**
6465
* {@inheritdoc}
6566
*/
66-
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
67+
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
6768
$form['webserviceurl_live'] = [
6869
'#type' => 'textfield',
6970
'#title' => $this->t('Webservice URL (LIVE)'),
@@ -91,7 +92,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
9192
/**
9293
* {@inheritdoc}
9394
*/
94-
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
95+
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
9596
if ($form_state->getValue('cert_passphrase_live') == '') {
9697
$form_state->unsetValue('cert_passphrase_live');
9798
}

src/Plugin/os2web/DataLookup/DatafordelerCVR.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DatafordelerCVR extends DatafordelerBase implements DataLookupInterfaceCom
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function defaultConfiguration() {
25+
public function defaultConfiguration(): array {
2626
return [
2727
'webserviceurl_live' => 'https://s5-certservices.datafordeler.dk/CVR/HentCVRData/1/REST/',
2828
'cert_path_live' => '',
@@ -33,7 +33,7 @@ public function defaultConfiguration() {
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
36+
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
3737
$form = parent::buildConfigurationForm($form, $form_state);
3838

3939
$form['test_cvr'] = [
@@ -47,7 +47,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
50+
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
5151
parent::submitConfigurationForm($form, $form_state);
5252

5353
if (!empty($form_state->getValue('test_cvr'))) {
@@ -64,9 +64,9 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function lookup($cvr) {
67+
public function lookup(string $param): CompanyLookupResult {
6868
try {
69-
$response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $cvr]]);
69+
$response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $param]]);
7070
$result = json_decode((string) $response->getBody());
7171
}
7272
catch (ClientException $e) {
@@ -76,7 +76,7 @@ public function lookup($cvr) {
7676
$cvrResult = new CompanyLookupResult();
7777
if ($result && isset($result->virksomhed) && !empty((array) $result->virksomhed)) {
7878
$cvrResult->setSuccessful();
79-
$cvrResult->setCvr($cvr);
79+
$cvrResult->setCvr($param);
8080

8181
if ($result->virksomhedsnavn) {
8282
$cvrResult->setName($result->virksomhedsnavn->vaerdi);

src/Plugin/os2web/DataLookup/DatafordelerPNumber.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class DatafordelerPNumber extends DatafordelerBase implements DataLookupInterfac
2222
/**
2323
* {@inheritdoc}
2424
*/
25-
public function defaultConfiguration() {
25+
public function defaultConfiguration(): array {
2626
return [
2727
'webserviceurl_live' => 'https://s5-certservices.datafordeler.dk/CVR/HentCVRData/1/REST/',
2828
'cert_path_live' => '',
@@ -33,7 +33,7 @@ public function defaultConfiguration() {
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
36+
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
3737
$form = parent::buildConfigurationForm($form, $form_state);
3838

3939
$form['test_pnumber'] = [
@@ -47,7 +47,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
4747
/**
4848
* {@inheritdoc}
4949
*/
50-
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
50+
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
5151
parent::submitConfigurationForm($form, $form_state);
5252

5353
if (!empty($form_state->getValue('test_pnumber'))) {
@@ -64,7 +64,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
6464
/**
6565
* {@inheritdoc}
6666
*/
67-
public function lookup($param) {
67+
public function lookup(string $param): CompanyLookupResult {
6868
try {
6969
$response = $this->httpClient->get('hentProduktionsenhedMedPNummer', ['query' => ['ppNummer' => $param]]);
7070
$result = json_decode((string) $response->getBody());

0 commit comments

Comments
 (0)