Skip to content

Commit 2ca5bd7

Browse files
committed
Updated
1 parent bc04861 commit 2ca5bd7

File tree

7 files changed

+59
-62
lines changed

7 files changed

+59
-62
lines changed

.github/workflows/pr.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
php-versions: [ '8.1' ]
26+
php-versions: [ '8.3' ]
2727
dependency-version: [ prefer-lowest, prefer-stable ]
2828
steps:
2929
- uses: actions/checkout@master
@@ -49,13 +49,16 @@ jobs:
4949
composer validate --strict composer.json
5050
# Check that dependencies resolve.
5151
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
52+
- name: Check that composer file is normalized
53+
run: |
54+
composer normalize --dry-run
5255
5356
php-coding-standards:
5457
name: PHP coding standards
5558
runs-on: ubuntu-latest
5659
strategy:
5760
matrix:
58-
php-versions: [ '8.1' ]
61+
php-versions: [ '8.3' ]
5962
steps:
6063
- uses: actions/checkout@master
6164
- name: Setup PHP, with composer and extensions

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ run the checks locally.
108108
### PHP
109109

110110
```shell
111-
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer install
111+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer install
112112
# Fix (some) coding standards issues
113-
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-apply
113+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-apply
114114
# Check that code adheres to the coding standards
115-
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer coding-standards-check
115+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-check
116116
```
117117

118118
### Markdown
@@ -130,5 +130,5 @@ Running statis code analysis on a standalone Drupal module is a bit tricky, so w
130130
analysis:
131131

132132
```shell
133-
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
133+
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/code-analysis
134134
```

composer.json

+24-17
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
"name": "os2web/os2web_datalookup",
33
"description": "Provides integration with Danish data lookup services such as Service platformen or Datafordeler.",
44
"license": "EUPL-1.2",
5+
"type": "drupal-module",
56
"require": {
7+
"ext-soap": "*",
68
"os2web/os2web_key": "^1.0"
79
},
10+
"require-dev": {
11+
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
12+
"drupal/coder": "^8.3",
13+
"ergebnis/composer-normalize": "^2.45",
14+
"os2web/os2web_audit": "^0.1",
15+
"phpunit/phpunit": "^9.5"
16+
},
817
"repositories": {
918
"drupal": {
1019
"type": "composer",
@@ -15,29 +24,27 @@
1524
"url": "https://asset-packagist.org"
1625
}
1726
},
18-
"require-dev": {
19-
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
20-
"drupal/coder": "^8.3",
21-
"phpunit/phpunit": "^9.5",
22-
"os2web/os2web_audit": "^0.1"
27+
"minimum-stability": "dev",
28+
"prefer-stable": true,
29+
"config": {
30+
"allow-plugins": {
31+
"dealerdirect/phpcodesniffer-composer-installer": true,
32+
"ergebnis/composer-normalize": true
33+
},
34+
"sort-packages": true
2335
},
2436
"scripts": {
25-
"coding-standards-check/phpcs": [
26-
"phpcs --standard=phpcs.xml.dist"
27-
],
28-
"coding-standards-check": [
29-
"@coding-standards-check/phpcs"
37+
"coding-standards-apply": [
38+
"@coding-standards-apply/phpcs"
3039
],
3140
"coding-standards-apply/phpcs": [
3241
"phpcbf --standard=phpcs.xml.dist"
3342
],
34-
"coding-standards-apply": [
35-
"@coding-standards-apply/phpcs"
43+
"coding-standards-check": [
44+
"@coding-standards-check/phpcs"
45+
],
46+
"coding-standards-check/phpcs": [
47+
"phpcs --standard=phpcs.xml.dist"
3648
]
37-
},
38-
"config": {
39-
"allow-plugins": {
40-
"dealerdirect/phpcodesniffer-composer-installer": true
41-
}
4249
}
4350
}

src/Exception/RuntimeException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\os2web_datalookup\Exception;
44

55
/**
6-
*
6+
* Runtime exception.
77
*/
88
class RuntimeException extends \RuntimeException {
99

src/Plugin/os2web/DataLookup/DataLookupBase.php

+13-34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
use Drupal\Core\File\FileExists;
56
use Drupal\Core\File\FileSystem;
67
use Drupal\Core\Form\FormStateInterface;
78
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
@@ -22,14 +23,16 @@
2223
* @see plugin_api
2324
*/
2425
abstract class DataLookupBase extends PluginBase implements DataLookupInterface, ContainerFactoryPluginInterface {
25-
protected const PROVIDER_TYPE_FORM = 'form';
26-
protected const PROVIDER_TYPE_KEY = 'key';
26+
protected const string PROVIDER_TYPE_FORM = 'form';
27+
protected const string PROVIDER_TYPE_KEY = 'key';
2728

2829
/**
2930
* Local certificate path.
3031
*
31-
* Used to temporarily store a certificate in a file just before calling a webservice.
32-
* For security purposes, the file will be removed right after the webservice calls completes.
32+
* Used to temporarily store a certificate in a file just before calling a
33+
* webservice.
34+
* For security purposes, the file will be removed right after the webservice
35+
* call completes (even unsuccessfully).
3336
*
3437
* @var string
3538
*/
@@ -42,34 +45,27 @@ abstract class DataLookupBase extends PluginBase implements DataLookupInterface,
4245
*/
4346
protected bool $isReady = TRUE;
4447

45-
/**
46-
* Audit logger.
47-
*
48-
* @var \Drupal\os2web_audit\Service\Logger
49-
*/
50-
protected Logger $auditLogger;
51-
5248
/**
5349
* {@inheritdoc}
5450
*/
5551
public function __construct(
5652
array $configuration,
5753
$plugin_id,
5854
$plugin_definition,
59-
Logger $auditLogger,
55+
protected Logger $auditLogger,
6056
protected KeyRepositoryInterface $keyRepository,
6157
protected FileSystem $fileSystem,
6258
) {
6359
parent::__construct($configuration, $plugin_id, $plugin_definition);
64-
$this->auditLogger = $auditLogger;
6560
$this->setConfiguration($configuration);
66-
$this->init();
6761
}
6862

6963
/**
70-
*
64+
* {@inheritdoc}
7165
*/
7266
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
67+
/** @var \Drupal\os2web_audit\Service\Logger $auditLogger */
68+
$auditLogger = $container->get('os2web_audit.logger');
7369
/** @var \Drupal\key\KeyRepositoryInterface $keyRepository */
7470
$keyRepository = $container->get('key.repository');
7571
/** @var \Drupal\Core\File\FileSystem $fileSystem */
@@ -79,29 +75,12 @@ public static function create(ContainerInterface $container, array $configuratio
7975
$configuration,
8076
$plugin_id,
8177
$plugin_definition,
78+
$auditLogger,
8279
$keyRepository,
8380
$fileSystem
8481
);
8582
}
8683

87-
/**
88-
* Plugin init method.
89-
*/
90-
protected function init() {
91-
}
92-
93-
/**
94-
* {@inheritdoc}
95-
*/
96-
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
97-
return new static(
98-
$configuration,
99-
$plugin_id,
100-
$plugin_definition,
101-
$container->get('os2web_audit.logger'),
102-
);
103-
}
104-
10584
/**
10685
* {@inheritdoc}
10786
*/
@@ -194,7 +173,7 @@ protected function writeCertificateToFile(): string {
194173
// Write certificate to local_cert location.
195174
$certificate = $this->getCertificate();
196175
$localCertPath = $this->localCertPath;
197-
$result = $this->fileSystem->saveData($certificate, $localCertPath, FileSystem::EXISTS_REPLACE);
176+
$result = $this->fileSystem->saveData($certificate, $localCertPath, FileExists::Replace);
198177
if (!$result) {
199178
return new RuntimeException(sprintf('Error writing certificate to temporary file %s', $localCertPath));
200179
}

src/Plugin/os2web/DataLookup/DatafordelerBase.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

5+
use Drupal\Core\File\FileSystem;
56
use Drupal\Core\Form\FormStateInterface;
7+
use Drupal\key\KeyRepositoryInterface;
68
use Drupal\os2web_datalookup\Exception\RuntimeException;
79
use Drupal\os2web_audit\Service\Logger;
810
use GuzzleHttp\Client;
@@ -28,15 +30,17 @@ public function __construct(
2830
$plugin_id,
2931
$plugin_definition,
3032
Logger $auditLogger,
33+
KeyRepositoryInterface $keyRepository,
34+
FileSystem $fileSystem,
3135
) {
32-
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger);
36+
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger, $keyRepository, $fileSystem);
3337
$this->init();
3438
}
3539

3640
/**
3741
* {@inheritdoc}
3842
*/
39-
private function init(): void {
43+
protected function init(): void {
4044
$this->isReady = FALSE;
4145

4246
$configuration = $this->getConfiguration();
@@ -159,7 +163,7 @@ protected function getResponse(string $uri, array $options): ResponseInterface {
159163
return $this->httpClient->get($uri, $options);
160164
} finally {
161165
// Remove temporary certificate file.
162-
if (file_exists($localCertPath)) {
166+
if (isset($localCertPath) && file_exists($localCertPath)) {
163167
unlink($localCertPath);
164168
}
165169
}

src/Plugin/os2web/DataLookup/ServiceplatformenBase.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

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

5+
use Drupal\Core\File\FileSystem;
56
use Drupal\Core\Form\FormStateInterface;
7+
use Drupal\key\KeyRepositoryInterface;
68
use Drupal\os2web_datalookup\Exception\RuntimeException;
79
use Drupal\os2web_audit\Service\Logger;
810

@@ -33,8 +35,10 @@ public function __construct(
3335
$plugin_id,
3436
$plugin_definition,
3537
Logger $auditLogger,
38+
KeyRepositoryInterface $keyRepository,
39+
FileSystem $fileSystem,
3640
) {
37-
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger);
41+
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger, $keyRepository, $fileSystem);
3842
$this->init();
3943
}
4044

0 commit comments

Comments
 (0)