Skip to content

Commit 9126c98

Browse files
authored
Merge pull request #12 from itk-dev/feature/os2form-audit
Audit logging and code style
2 parents 17f86a6 + 2387bb1 commit 9126c98

31 files changed

+728
-271
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### Link to ticket
2+
3+
Please add a link to the ticket being addressed by this change.
4+
5+
#### Description
6+
7+
Please include a short description of the suggested change and the reasoning behind the approach you have chosen.
8+
9+
#### Screenshot of the result
10+
11+
If your change affects the user interface you should include a screenshot of the result with the pull request.
12+
13+
#### Checklist
14+
15+
- [ ] My code passes our static analysis suite.
16+
- [ ] My code passes our continuous integration process.
17+
18+
If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
19+
should be exempt from the list.
20+
21+
#### Additional comments or questions
22+
23+
If you have any further comments or questions for the reviewer please add them here.

.github/workflows/pr.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,67 @@ jobs:
1717

1818
- name: Check that changelog has been updated.
1919
run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0
20+
21+
test-composer-files:
22+
name: Validate composer
23+
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
php-versions: [ '8.1' ]
27+
dependency-version: [ prefer-lowest, prefer-stable ]
28+
steps:
29+
- uses: actions/checkout@master
30+
- name: Setup PHP, with composer and extensions
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php-versions }}
34+
extensions: json
35+
coverage: none
36+
tools: composer:v2
37+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
38+
- name: Get composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
- name: Cache dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: ${{ steps.composer-cache.outputs.dir }}
45+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
46+
restore-keys: ${{ runner.os }}-composer-
47+
- name: Validate composer files
48+
run: |
49+
composer validate --strict composer.json
50+
# Check that dependencies resolve.
51+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
52+
53+
php-coding-standards:
54+
name: PHP coding standards
55+
runs-on: ubuntu-latest
56+
strategy:
57+
matrix:
58+
php-versions: [ '8.1' ]
59+
steps:
60+
- uses: actions/checkout@master
61+
- name: Setup PHP, with composer and extensions
62+
uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: ${{ matrix.php-versions }}
65+
extensions: json
66+
coverage: none
67+
tools: composer:v2
68+
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
69+
- name: Get composer cache directory
70+
id: composer-cache
71+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
72+
- name: Cache dependencies
73+
uses: actions/cache@v2
74+
with:
75+
path: ${{ steps.composer-cache.outputs.dir }}
76+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
77+
restore-keys: ${{ runner.os }}-composer-
78+
- name: Install Dependencies
79+
run: |
80+
composer install --no-interaction --no-progress
81+
- name: PHPCS
82+
run: |
83+
composer coding-standards-check/phpcs

README.md

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
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:
1415

15-
```
16+
Updating process for OS2Web Data lookup module is similar to the usual Drupal 8
17+
module. Use Composer's built-in command for listing packages that have updates
18+
available:
19+
20+
```shell
1621
composer outdated os2web/os2web_datalookup
1722
```
1823

1924
## Automated testing and code quality
25+
2026
See [OS2Web testing and CI information](https://github.com/OS2Web/docs#testing-and-ci)
2127

2228
## Contribution
2329

2430
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.
31+
If you have any suggestion, or you found a bug in project, you are very welcome
32+
to create an issue in GitHub repository issue tracker. For issue description,
33+
there is expected that you will provide clear and sufficient information about
34+
your feature request or bug report.
2935

3036
### Code review policy
37+
3138
See [OS2Web code review policy](https://github.com/OS2Web/docs#code-review)
3239

3340
### Git name convention
41+
3442
See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)
3543

3644
### Using services in other modules
3745

38-
```
46+
```php
3947
// CVR lookup
4048
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
4149
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
42-
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCompany $cvrPlugin */
50+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCompanyInterface $cvrPlugin */
4351
$cvrPlugin = $pluginManager->createDefaultInstanceByGroup('cvr_lookup');
4452

4553
if ($cvrPlugin->isReady()) {
@@ -49,7 +57,7 @@ if ($cvrPlugin->isReady()) {
4957
// CPR lookup.
5058
/** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */
5159
$pluginManager = \Drupal::service('plugin.manager.os2web_datalookup');
52-
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr $cprPlugin */
60+
/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCprInterface $cprPlugin */
5361
$cprPlugin = $pluginManager->createDefaultInstanceByGroup('cpr_lookup');
5462

5563
if ($cprPlugin->isReady()) {
@@ -68,22 +76,25 @@ if ($cprPlugin->isReady()) {
6876

6977
### Datafordeler integration (https://datafordeler.dk)
7078

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)
79+
In the scope of os2forms project already implemented light integration with
80+
Danmarks Adresseregister (DAR) via fetching data for form elements autocomplete.
81+
82+
See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms)
7483

7584
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.
85+
os2forms_dawa will be refactored to OS2Web Data lookup plugin.
7786

7887
## Important notes
88+
7989
### 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`.
8390

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

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
98+
To avoid/prevent this behavior, we recommend use `Config ignore` module, where
99+
you can add all settings you do not want to export/import via the configuration
89100
management system.

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,30 @@
1717
"type": "composer",
1818
"url": "https://asset-packagist.org"
1919
}
20+
},
21+
"require-dev": {
22+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
23+
"drupal/coder": "^8.3",
24+
"phpunit/phpunit": "^9.5",
25+
"os2web/os2web_audit": "^0.1"
26+
},
27+
"scripts": {
28+
"coding-standards-check/phpcs": [
29+
"phpcs --standard=phpcs.xml.dist"
30+
],
31+
"coding-standards-check": [
32+
"@coding-standards-check/phpcs"
33+
],
34+
"coding-standards-apply/phpcs": [
35+
"phpcbf --standard=phpcs.xml.dist"
36+
],
37+
"coding-standards-apply": [
38+
"@coding-standards-apply/phpcs"
39+
]
40+
},
41+
"config": {
42+
"allow-plugins": {
43+
"dealerdirect/phpcodesniffer-composer-installer": true
44+
}
2045
}
2146
}

os2web_datalookup.info.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ type: module
33
description: 'Provides integration with Danish data lookup services such as Service platformen or Datafordeler.'
44
package: 'OS2web'
55
core_version_requirement: ^8 || ^9 || ^10
6+
dependencies:
7+
- 'os2web:os2web_audit'

os2web_datalookup.install

100755100644
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="PHP_CodeSniffer">
3+
<description>OS2web Datalookup PHP Code Sniffer configuration</description>
4+
5+
<file>.</file>
6+
<exclude-pattern>vendor/</exclude-pattern>
7+
<exclude-pattern>node_modules/</exclude-pattern>
8+
9+
<!-- Show progress of the run -->
10+
<arg value="p"/>
11+
12+
<arg name="extensions" value="php,module,inc,install,test,profile,theme,css,info,txt,yml"/>
13+
<config name="drupal_core_version" value="9"/>
14+
15+
16+
<rule ref="Drupal">
17+
<!-- We want to be able to use "package" and "version" in our custom modules -->
18+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Project"/>
19+
<exclude name="Drupal.InfoFiles.AutoAddedKeys.Version"/>
20+
</rule>
21+
22+
<rule ref="DrupalPractice"/>
23+
</ruleset>

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] = [

0 commit comments

Comments
 (0)