From 2ca5bd7e1b00f78f57b87aa88d57bf62d8840c5e Mon Sep 17 00:00:00 2001 From: Mikkel Ricky Date: Fri, 20 Dec 2024 10:44:38 +0100 Subject: [PATCH] Updated --- .github/workflows/pr.yml | 7 ++- README.md | 8 ++-- composer.json | 41 +++++++++------- src/Exception/RuntimeException.php | 2 +- .../os2web/DataLookup/DataLookupBase.php | 47 +++++-------------- .../os2web/DataLookup/DatafordelerBase.php | 10 ++-- .../DataLookup/ServiceplatformenBase.php | 6 ++- 7 files changed, 59 insertions(+), 62 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 132f08e..c9e4dc2 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 @@ -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 diff --git a/README.md b/README.md index 2280234..ebf5236 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/composer.json b/composer.json index 12bec7a..fb62caa 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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 - } } } diff --git a/src/Exception/RuntimeException.php b/src/Exception/RuntimeException.php index 0dd1e03..1631731 100644 --- a/src/Exception/RuntimeException.php +++ b/src/Exception/RuntimeException.php @@ -3,7 +3,7 @@ namespace Drupal\os2web_datalookup\Exception; /** - * + * Runtime exception. */ class RuntimeException extends \RuntimeException { diff --git a/src/Plugin/os2web/DataLookup/DataLookupBase.php b/src/Plugin/os2web/DataLookup/DataLookupBase.php index a55c6fe..c2aa0b7 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupBase.php +++ b/src/Plugin/os2web/DataLookup/DataLookupBase.php @@ -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; @@ -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 */ @@ -42,13 +45,6 @@ abstract class DataLookupBase extends PluginBase implements DataLookupInterface, */ protected bool $isReady = TRUE; - /** - * Audit logger. - * - * @var \Drupal\os2web_audit\Service\Logger - */ - protected Logger $auditLogger; - /** * {@inheritdoc} */ @@ -56,20 +52,20 @@ 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 */ @@ -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} */ @@ -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)); } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerBase.php b/src/Plugin/os2web/DataLookup/DatafordelerBase.php index 8aac78d..4d39fae 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerBase.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerBase.php @@ -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; @@ -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(); @@ -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); } } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php index a7a727c..835e08f 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php @@ -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; @@ -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(); }