Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Dec 20, 2024
1 parent bc04861 commit 2ca5bd7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 62 deletions.
7 changes: 5 additions & 2 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 @@ -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 Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ run the checks locally.
### PHP

```shell
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm composer install
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.1-fpm composer coding-standards-apply
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.1-fpm composer coding-standards-check
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm composer coding-standards-check
```

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

```shell
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.1-fpm ./scripts/code-analysis
docker run --rm --volume ${PWD}:/app --workdir /app itkdev/php8.3-fpm ./scripts/code-analysis
```
41 changes: 24 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
"name": "os2web/os2web_datalookup",
"description": "Provides integration with Danish data lookup services such as Service platformen or Datafordeler.",
"license": "EUPL-1.2",
"type": "drupal-module",
"require": {
"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": {
"type": "composer",
Expand All @@ -15,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: 1 addition & 1 deletion src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Drupal\os2web_datalookup\Exception;

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

Expand Down
47 changes: 13 additions & 34 deletions src/Plugin/os2web/DataLookup/DataLookupBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup;

use Drupal\Core\File\FileExists;
use Drupal\Core\File\FileSystem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
Expand All @@ -22,14 +23,16 @@
* @see plugin_api
*/
abstract class DataLookupBase extends PluginBase implements DataLookupInterface, ContainerFactoryPluginInterface {
protected const PROVIDER_TYPE_FORM = 'form';
protected const PROVIDER_TYPE_KEY = 'key';
protected const string PROVIDER_TYPE_FORM = 'form';
protected const string PROVIDER_TYPE_KEY = 'key';

/**
* Local certificate path.
*
* Used to temporarily store a certificate in a file just before calling a webservice.
* For security purposes, the file will be removed right after the webservice calls completes.
* Used to temporarily store a certificate in a file just before calling a
* webservice.
* For security purposes, the file will be removed right after the webservice
* call completes (even unsuccessfully).
*
* @var string
*/
Expand All @@ -42,34 +45,27 @@ abstract class DataLookupBase extends PluginBase implements DataLookupInterface,
*/
protected bool $isReady = TRUE;

/**
* Audit logger.
*
* @var \Drupal\os2web_audit\Service\Logger
*/
protected Logger $auditLogger;

/**
* {@inheritdoc}
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
Logger $auditLogger,
protected Logger $auditLogger,
protected KeyRepositoryInterface $keyRepository,
protected FileSystem $fileSystem,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->auditLogger = $auditLogger;
$this->setConfiguration($configuration);
$this->init();
}

/**
*
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\os2web_audit\Service\Logger $auditLogger */
$auditLogger = $container->get('os2web_audit.logger');
/** @var \Drupal\key\KeyRepositoryInterface $keyRepository */
$keyRepository = $container->get('key.repository');
/** @var \Drupal\Core\File\FileSystem $fileSystem */
Expand All @@ -79,29 +75,12 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$auditLogger,
$keyRepository,
$fileSystem
);
}

/**
* Plugin init method.
*/
protected function init() {
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('os2web_audit.logger'),
);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -194,7 +173,7 @@ protected function writeCertificateToFile(): string {
// Write certificate to local_cert location.
$certificate = $this->getCertificate();
$localCertPath = $this->localCertPath;
$result = $this->fileSystem->saveData($certificate, $localCertPath, FileSystem::EXISTS_REPLACE);
$result = $this->fileSystem->saveData($certificate, $localCertPath, FileExists::Replace);
if (!$result) {
return new RuntimeException(sprintf('Error writing certificate to temporary file %s', $localCertPath));
}
Expand Down
10 changes: 7 additions & 3 deletions src/Plugin/os2web/DataLookup/DatafordelerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup;

use Drupal\Core\File\FileSystem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\key\KeyRepositoryInterface;
use Drupal\os2web_datalookup\Exception\RuntimeException;
use Drupal\os2web_audit\Service\Logger;
use GuzzleHttp\Client;
Expand All @@ -28,15 +30,17 @@ public function __construct(
$plugin_id,
$plugin_definition,
Logger $auditLogger,
KeyRepositoryInterface $keyRepository,
FileSystem $fileSystem,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger);
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger, $keyRepository, $fileSystem);
$this->init();
}

/**
* {@inheritdoc}
*/
private function init(): void {
protected function init(): void {
$this->isReady = FALSE;

$configuration = $this->getConfiguration();
Expand Down Expand Up @@ -159,7 +163,7 @@ protected function getResponse(string $uri, array $options): ResponseInterface {
return $this->httpClient->get($uri, $options);
} finally {
// Remove temporary certificate file.
if (file_exists($localCertPath)) {
if (isset($localCertPath) && file_exists($localCertPath)) {
unlink($localCertPath);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Plugin/os2web/DataLookup/ServiceplatformenBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup;

use Drupal\Core\File\FileSystem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\key\KeyRepositoryInterface;
use Drupal\os2web_datalookup\Exception\RuntimeException;
use Drupal\os2web_audit\Service\Logger;

Expand Down Expand Up @@ -33,8 +35,10 @@ public function __construct(
$plugin_id,
$plugin_definition,
Logger $auditLogger,
KeyRepositoryInterface $keyRepository,
FileSystem $fileSystem,
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger);
parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger, $keyRepository, $fileSystem);
$this->init();
}

Expand Down

0 comments on commit 2ca5bd7

Please sign in to comment.