Skip to content

os2web_key #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
php-versions: [ '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
Expand All @@ -39,7 +39,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -49,13 +49,16 @@ jobs:
composer validate --strict composer.json
# Check that dependencies resolve.
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Check that composer file is normalized
run: |
composer normalize --dry-run

php-coding-standards:
name: PHP coding standards
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ '8.1' ]
php-versions: [ '8.3' ]
steps:
- uses: actions/checkout@master
- name: Setup PHP, with composer and extensions
Expand All @@ -70,7 +73,7 @@ jobs:
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor/
19 changes: 19 additions & 0 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// @see https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md
"MD013": {
// Exclude code blocks
"code_blocks": false,
"line_length": 120
},

// Prevent complaining on duplicated headings in CHANGELOG.md
// https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md
"MD024": {
"siblings_only": true
}
}

// Local Variables:
// mode: json
// End:
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* [PR-13](https://github.com/OS2web/os2web_datalookup/pull/13)
Added support for [os2web_key](https://github.com/OS2web/os2web_key)

## [2.0.4] 2025-01-29

* Ensure postal code is only added to city if `CVRAdresse_postdistrikt` is not set.
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ if ($cprPlugin->isReady()) {

## New services/features

### Datafordeler integration (https://datafordeler.dk)
### Datafordeler integration (<https://datafordeler.dk>)

In the scope of os2forms project already implemented light integration with
Danmarks Adresseregister (DAR) via fetching data for form elements autocomplete.
Expand All @@ -98,3 +98,37 @@ will be exposed for third persons.
To avoid/prevent this behavior, we recommend use `Config ignore` module, where
you can add all settings you do not want to export/import via the configuration
management system.

## Coding standards

Our coding are checked by GitHub Actions (cf.
[.github/workflows/pr.yml](.github/workflows/pr.yml)). Use the commands below to
run the checks locally.

### PHP

```shell
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer install
# Fix (some) coding standards issues
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-apply
# Check that code adheres to the coding standards
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-check
```

### Markdown

```shell
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md' --fix
docker run --rm --volume $PWD:/md peterdavehello/markdownlint markdownlint --ignore vendor --ignore LICENSE.md '**/*.md'
```

## Code analysis

We use [PHPStan](https://phpstan.org/) for static code analysis.

Running statis code analysis on a standalone Drupal module is a bit tricky, so we use a helper script to run the
analysis:

```shell
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/code-analysis
```
46 changes: 25 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{
"name": "os2web/os2web_datalookup",
"type": "drupal-module",
"description": "Provides integration with Danish data lookup services such as Service platformen or Datafordeler.",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "EUPL-1.2",
"type": "drupal-module",
"require": {
"ext-soap": "*"
"ext-soap": "*",
"os2web/os2web_key": "^1.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"ergebnis/composer-normalize": "^2.45",
"os2web/os2web_audit": "^0.1",
"phpunit/phpunit": "^9.5"
},
"repositories": {
"drupal": {
Expand All @@ -18,29 +24,27 @@
"url": "https://asset-packagist.org"
}
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"drupal/coder": "^8.3",
"phpunit/phpunit": "^9.5",
"os2web/os2web_audit": "^0.1"
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
},
"sort-packages": true
},
"scripts": {
"coding-standards-check/phpcs": [
"phpcs --standard=phpcs.xml.dist"
],
"coding-standards-check": [
"@coding-standards-check/phpcs"
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
],
"coding-standards-apply/phpcs": [
"phpcbf --standard=phpcs.xml.dist"
],
"coding-standards-apply": [
"@coding-standards-apply/phpcs"
"coding-standards-check": [
"@coding-standards-check/phpcs"
],
"coding-standards-check/phpcs": [
"phpcs --standard=phpcs.xml.dist"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
2 changes: 2 additions & 0 deletions os2web_datalookup.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ type: module
description: 'Provides integration with Danish data lookup services such as Service platformen or Datafordeler.'
package: 'OS2web'
core_version_requirement: ^8 || ^9 || ^10

dependencies:
- 'os2web:os2web_audit'
- 'os2web_key:os2web_key'
9 changes: 9 additions & 0 deletions os2web_datalookup.install
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ function os2web_datalookup_update_9003(): void {
$config->set("pnumber_lookup.default_plugin", 'datafordeler_pnumber');
$config->save();
}

/**
* Implements hook_update_N().
*/
function os2web_datalookup_update_9004() {
\Drupal::service('module_installer')->install([
'os2web_key',
], TRUE);
}
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
parameters:
level: 6
paths:
- src

ignoreErrors:
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ has parameter \\$[a-zA-Z0-9_]+ with no value type specified in iterable type array#"
- "#Method [a-zA-Z0-9\\_\\\\:\\(\\)]+ return type has no value type specified in iterable type array#"
- '#Unsafe usage of new static\(\).#'

# Local Variables:
# mode: yaml
# End:
47 changes: 47 additions & 0 deletions scripts/code-analysis
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
script_dir=$(pwd)
module_name=$(basename "$script_dir")
drupal_dir=vendor/drupal-module-code-analysis
# Relative to $drupal_dir
module_path=web/modules/contrib/$module_name

cd "$script_dir" || exit

drupal_composer() {
composer --working-dir="$drupal_dir" --no-interaction "$@"
}

# # Create new Drupal 9 project
# if [ ! -f "$drupal_dir/composer.json" ]; then
# composer --no-interaction create-project drupal/recommended-project:^9 "$drupal_dir"
# fi
# # Copy our code into the modules folder

# # Clean up
# rm -fr "${drupal_dir:?}/$module_path"

# # https://stackoverflow.com/a/15373763
# # rsync --archive --compress . --filter=':- .gitignore' --exclude "$drupal_dir" --exclude .git "$drupal_dir/$module_path"

# # The rsync command in not available in itkdev/php8.1-fpm

# git config --global --add safe.directory /app
# # Copy module files into module path
# for f in $(git ls-files); do
# mkdir -p "$drupal_dir/$module_path/$(dirname "$f")"
# cp "$f" "$drupal_dir/$module_path/$f"
# done

# drupal_composer config minimum-stability dev

# # Allow ALL plugins
# # https://getcomposer.org/doc/06-config.md#allow-plugins
# drupal_composer config --no-plugins allow-plugins true

# drupal_composer require wikimedia/composer-merge-plugin
# drupal_composer config extra.merge-plugin.include "$module_path/composer.json"
# # https://www.drupal.org/project/drupal/issues/3220043#comment-14845434
# drupal_composer require --dev symfony/phpunit-bridge

# Run PHPStan
(cd "$drupal_dir" && vendor/bin/phpstan --configuration="$module_path/phpstan.neon")
10 changes: 10 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Drupal\os2web_datalookup\Exception;

/**
* Runtime exception.
*/
class RuntimeException extends \RuntimeException {

}
Loading
Loading