From 2d603d2882b9cbf7fd64b7063e8e32a4eb61487f Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2024 12:46:09 +0200 Subject: [PATCH 01/18] ITKDev: Code style fixes in plugins --- README.md | 52 +++++++++++-------- src/Plugin/DataLookupManager.php | 19 +++---- .../os2web/DataLookup/DataLookupBase.php | 15 +++--- .../os2web/DataLookup/DataLookupInterface.php | 9 ++-- .../DataLookup/DataLookupInterfaceCompany.php | 4 +- .../DataLookup/DataLookupInterfaceCpr.php | 4 +- .../os2web/DataLookup/DatafordelerBase.php | 21 ++++---- .../os2web/DataLookup/DatafordelerCVR.php | 12 ++--- .../os2web/DataLookup/DatafordelerPNumber.php | 8 +-- .../DataLookup/ServiceplatformenBase.php | 22 ++++---- .../DataLookup/ServiceplatformenCPR.php | 28 +++++----- .../ServiceplatformenCPRExtended.php | 13 ++--- .../DataLookup/ServiceplatformenCVR.php | 14 ++--- .../DataLookup/ServiceplatformenPNumber.php | 14 ++--- 14 files changed, 128 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index bde9d52..0fb17a1 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,48 @@ # OS2Web Data lookup [![Build Status](https://travis-ci.org/OS2web/os2web_datalookup.svg?branch=8.x)](https://travis-ci.org/OS2web/os2web_datalookup) + ## Install -OS2Web Data lookup provides integration with Danish data lookup services such as Service platformen or Datafordeler. -Module is available to download via composer. -``` +OS2Web Data lookup provides integration with Danish data lookup services such as +Service platformen or Datafordeler. Module is available to download via +composer. + +```shell composer require os2web/os2web_datalookup drush en os2web_datalookup ``` ## Update -Updating process for OS2Web Data lookup module is similar to usual Drupal 8 module. -Use Composer's built-in command for listing packages that have updates available: +Updating process for OS2Web Data lookup module is similar to the usual Drupal 8 +module. Use Composer's built-in command for listing packages that have updates +available: -``` +```shell composer outdated os2web/os2web_datalookup ``` ## Automated testing and code quality + See [OS2Web testing and CI information](https://github.com/OS2Web/docs#testing-and-ci) ## Contribution Project is opened for new features and os course bugfixes. -If you have any suggestion or you found a bug in project, you are very welcome -to create an issue in github repository issue tracker. -For issue description there is expected that you will provide clear and -sufficient information about your feature request or bug report. +If you have any suggestion, or you found a bug in project, you are very welcome +to create an issue in GitHub repository issue tracker. For issue description, +there is expected that you will provide clear and sufficient information about +your feature request or bug report. ### Code review policy + See [OS2Web code review policy](https://github.com/OS2Web/docs#code-review) ### Git name convention + See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline) ### Using services in other modules -``` +```php // CVR lookup /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */ $pluginManager = \Drupal::service('plugin.manager.os2web_datalookup'); @@ -68,22 +75,25 @@ if ($cprPlugin->isReady()) { ### Datafordeler integration (https://datafordeler.dk) -In scope of os2forms project already implemented light integration -with Danmarks Adresseregister (DAR) via fetching data for form elements -autocomplete. See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms) +In the scope of os2forms project already implemented light integration with +Danmarks Adresseregister (DAR) via fetching data for form elements autocomplete. + +See [os2forms_dawa submodule](https://github.com/OS2Forms/os2forms) As soon as it is clear how the integration is going to be used, then -os2forms_dawa will be refactored to OS2Web Data lookup plugin plugin. +os2forms_dawa will be refactored to OS2Web Data lookup plugin. ## Important notes + ### Serviceplatformen plugins -Settings for CPR and CVR serviceplantormen plugins are storing as configuration -in db and will(could) be exported as `yml` file via Drupal configuration -management system. And afterwards could be tracked by `git`. -If case you have public access to your git repository all setting from plugins +Settings for CPR and CVR serviceplatformen plugins are storing as configuration +in db and will(could) be exported as `yml` file via Drupal's configuration +management system. And afterward could be tracked by `git`. + +If case you have public access to your git repository, all settings from plugins 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 configuration +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. diff --git a/src/Plugin/DataLookupManager.php b/src/Plugin/DataLookupManager.php index 2899b2d..b0744c0 100644 --- a/src/Plugin/DataLookupManager.php +++ b/src/Plugin/DataLookupManager.php @@ -23,10 +23,10 @@ class DataLookupManager extends DefaultPluginManager { * * @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $configFactory; + protected ConfigFactoryInterface $configFactory; /** - * Constructs an DataLookupManager object. + * Constructs a DataLookupManager object. * * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths @@ -54,7 +54,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac /** * {@inheritdoc} */ - public function createInstance($plugin_id, array $configuration = []) { + public function createInstance($plugin_id, array $configuration = []): object { // Hard switch to another plugin fallback - see // https://os2web.atlassian.net/browse/OS2FORMS-359. if ($plugin_id == 'serviceplatformen_cpr') { @@ -81,7 +81,7 @@ public function createInstance($plugin_id, array $configuration = []) { * @throws \Drupal\Component\Plugin\Exception\PluginException * If the instance cannot be created, such as if the ID is invalid. */ - public function createDefaultInstanceByGroup($group_id) { + public function createDefaultInstanceByGroup(string $group_id): object { $plugin_id = $this->getGroupDefaultPlugin($group_id); return $this->createInstance($plugin_id); } @@ -92,11 +92,11 @@ public function createDefaultInstanceByGroup($group_id) { * @param $group_id * Group id. * - * @return mixed[] + * @return array * An array of plugin definitions (empty array if no definitions were * found). Keys are plugin IDs. */ - public function getDefinitionsByGroup($group_id) { + public function getDefinitionsByGroup($group_id): array { $definitions = []; foreach ($this->getDefinitions() as $id => $plugin_definition) { if ($plugin_definition['group'] == $group_id) { @@ -113,11 +113,11 @@ public function getDefinitionsByGroup($group_id) { * @return array * Array of groups, keyed by group_id. */ - public function getDatalookupGroups() { + public function getDatalookupGroups(): array { $definitions = $this->getDefinitions(); $groups = []; foreach ($definitions as $definition) { - if (isset($definition['group']) && !empty($definition['group'])) { + if (!empty($definition['group'])) { $groups[$definition['group']] = $definition['group']; } } @@ -134,8 +134,9 @@ public function getDatalookupGroups() { * @return string|null * Plugin ID or NULL is not set. */ - public function getGroupDefaultPlugin($group_id) { + public function getGroupDefaultPlugin($group_id): ?string { $config = \Drupal::config(DataLookupPluginGroupSettingsForm::$configName); + return $config->get("$group_id.default_plugin"); } diff --git a/src/Plugin/os2web/DataLookup/DataLookupBase.php b/src/Plugin/os2web/DataLookup/DataLookupBase.php index 357a1cc..4402e9d 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupBase.php +++ b/src/Plugin/os2web/DataLookup/DataLookupBase.php @@ -22,7 +22,7 @@ abstract class DataLookupBase extends PluginBase implements DataLookupInterface * * @var bool */ - protected $isReady = TRUE; + protected bool $isReady = TRUE; /** * {@inheritdoc} @@ -42,22 +42,23 @@ public function label() { /** * {@inheritdoc} */ - public function getConfiguration() { + public function getConfiguration(): array { return $this->configuration; } /** * {@inheritdoc} */ - public function setConfiguration(array $configuration) { + public function setConfiguration(array $configuration): static { $this->configuration = $configuration + $this->defaultConfiguration(); + return $this; } /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return []; } @@ -71,21 +72,21 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form /** * {@inheritdoc} */ - public function getStatus() { + public function getStatus(): string { return 'N/A'; } /** * {@inheritdoc} */ - public function getGroup() { + public function getGroup(): string { return $this->pluginDefinition['group']; } /** * {@inheritdoc} */ - public function isReady() { + public function isReady(): bool { return $this->isReady; } diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterface.php b/src/Plugin/os2web/DataLookup/DataLookupInterface.php index e5e8649..e703814 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterface.php +++ b/src/Plugin/os2web/DataLookup/DataLookupInterface.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginFormInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * DataLookupInterface plugin interface for providing some metadata inspection. @@ -19,16 +20,16 @@ interface DataLookupInterface extends PluginInspectionInterface, PluginFormInter /** * Get plugin status. */ - public function getStatus(); + public function getStatus(): string; /** - * Get plugin group. + * Get a plugin group. */ - public function getGroup(); + public function getGroup(): string; /** * Get plugin readiness. */ - public function isReady(); + public function isReady(): bool; } diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php b/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php index 0caded9..82b9fb2 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php +++ b/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php @@ -2,6 +2,8 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; +use Drupal\os2web_datalookup\LookupResult\CompanyLookupResult; + interface DataLookupInterfaceCompany extends DataLookupInterface { /** @@ -13,6 +15,6 @@ interface DataLookupInterfaceCompany extends DataLookupInterface { * @return \Drupal\os2web_datalookup\LookupResult\CompanyLookupResult * The company lookup Result. */ - public function lookup($param); + public function lookup(string $param): CompanyLookupResult; } diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php b/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php index 000edf1..8e36140 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php +++ b/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php @@ -2,6 +2,8 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; +use Drupal\os2web_datalookup\LookupResult\CprLookupResult; + interface DataLookupInterfaceCpr extends DataLookupInterface { /** @@ -13,6 +15,6 @@ interface DataLookupInterfaceCpr extends DataLookupInterface { * @return \Drupal\os2web_datalookup\LookupResult\CprLookupResult * The CPR lookup Result. */ - public function lookup($cpr); + public function lookup(string $cpr): CprLookupResult; } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerBase.php b/src/Plugin/os2web/DataLookup/DatafordelerBase.php index 1e05287..4757272 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerBase.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerBase.php @@ -3,6 +3,7 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use GuzzleHttp\Client; /** @@ -11,11 +12,11 @@ abstract class DatafordelerBase extends DataLookupBase { /** - * Plugin readiness flag. + * Http client. * - * @var bool + * @var Client */ - protected $httpClient; + protected Client $httpClient; /** * {@inheritdoc} @@ -28,7 +29,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition /** * Plugin init method. */ - private function init() { + private function init(): void { $this->isReady = FALSE; $configuration = $this->getConfiguration(); @@ -51,19 +52,19 @@ private function init() { /** * {@inheritdoc} */ - public function getStatus() { - if ($this->httpClient) { - return $this->t('Plugin is ready to work'); + public function getStatus(): string { + if (isset($this->httpClient)) { + return $this->t('Plugin is ready to work')->render(); } else { - return $this->t('Configuration is not completed'); + return $this->t('Configuration is not completed')->render(); } } /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form['webserviceurl_live'] = [ '#type' => 'textfield', '#title' => $this->t('Webservice URL (LIVE)'), @@ -91,7 +92,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { if ($form_state->getValue('cert_passphrase_live') == '') { $form_state->unsetValue('cert_passphrase_live'); } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php index 4b81f52..1c4c5b3 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php @@ -22,7 +22,7 @@ class DatafordelerCVR extends DatafordelerBase implements DataLookupInterfaceCom /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return [ 'webserviceurl_live' => 'https://s5-certservices.datafordeler.dk/CVR/HentCVRData/1/REST/', 'cert_path_live' => '', @@ -33,7 +33,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['test_cvr'] = [ @@ -47,7 +47,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { parent::submitConfigurationForm($form, $form_state); if (!empty($form_state->getValue('test_cvr'))) { @@ -64,9 +64,9 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s /** * {@inheritdoc} */ - public function lookup($cvr) { + public function lookup(string $param): CompanyLookupResult { try { - $response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $cvr]]); + $response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $param]]); $result = json_decode((string) $response->getBody()); } catch (ClientException $e) { @@ -76,7 +76,7 @@ public function lookup($cvr) { $cvrResult = new CompanyLookupResult(); if ($result && isset($result->virksomhed) && !empty((array) $result->virksomhed)) { $cvrResult->setSuccessful(); - $cvrResult->setCvr($cvr); + $cvrResult->setCvr($param); if ($result->virksomhedsnavn) { $cvrResult->setName($result->virksomhedsnavn->vaerdi); diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index 0a8d495..714632b 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php @@ -22,7 +22,7 @@ class DatafordelerPNumber extends DatafordelerBase implements DataLookupInterfac /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return [ 'webserviceurl_live' => 'https://s5-certservices.datafordeler.dk/CVR/HentCVRData/1/REST/', 'cert_path_live' => '', @@ -33,7 +33,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['test_pnumber'] = [ @@ -47,7 +47,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { parent::submitConfigurationForm($form, $form_state); if (!empty($form_state->getValue('test_pnumber'))) { @@ -64,7 +64,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s /** * {@inheritdoc} */ - public function lookup($param) { + public function lookup(string $param): CompanyLookupResult { try { $response = $this->httpClient->get('hentProduktionsenhedMedPNummer', ['query' => ['ppNummer' => $param]]); $result = json_decode((string) $response->getBody()); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php index 51c3291..63ade00 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php @@ -14,14 +14,14 @@ abstract class ServiceplatformenBase extends DataLookupBase { * * @var string */ - protected $status; + protected string $status; /** * Service object. * * @var \SoapClient */ - protected $client; + protected \SoapClient $client; /** * {@inheritdoc} @@ -34,7 +34,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return [ 'mode_selector' => 0, 'serviceagreementuuid' => '', @@ -54,7 +54,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form['mode_fieldset'] = [ '#type' => 'fieldset', '#title' => $this->t('Mode'), @@ -143,7 +143,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { if ($form_state->getValue('certfile_passphrase') == '') { $form_state->unsetValue('certfile_passphrase'); } @@ -159,14 +159,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s /** * {@inheritdoc} */ - public function getStatus() { + public function getStatus(): string { return $this->status; } /** * Plugin init method. */ - private function init() { + private function init(): void { ini_set('soap.wsdl_cache_enabled', 0); ini_set('soap.wsdl_cache_ttl', 0); $this->status = $this->t('Plugin is ready to work')->__toString(); @@ -193,6 +193,7 @@ private function init() { 'certfile_test', ], ]; + $this->isReady = TRUE; foreach ($required_configuration[$this->configuration['mode_selector']] as $key) { if (empty($this->configuration[$key])) { @@ -235,7 +236,7 @@ private function init() { * @return string * WSDL URL. */ - protected function getWsdlUrl() { + protected function getWsdlUrl(): string { $url = $this->configuration['wsdl']; // Anything that's not an absolute path or url will be resolved relative to // the location of the os2web_datalookup module. @@ -254,8 +255,7 @@ protected function getWsdlUrl() { * @return array * Prepared request with general info. */ - protected function prepareRequest() { - /** @var \Drupal\Core\Session\AccountProxyInterface $user */ + protected function prepareRequest(): array { $user = \Drupal::currentUser(); return [ 'InvocationContext' => [ @@ -280,7 +280,7 @@ protected function prepareRequest() { * @return array * Method response or FALSE. */ - protected function query($method, array $request) { + protected function query(string $method, array $request): array { if (!$this->isReady()) { return [ 'status' => FALSE, diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php index b2e0f24..b0d9e61 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php @@ -21,7 +21,7 @@ class ServiceplatformenCPR extends ServiceplatformenBase implements DataLookupIn /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return array_merge(parent::defaultConfiguration(), [ 'test_mode_fixed_cpr' => '', ]); @@ -30,7 +30,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['mode_fieldset']['test_mode_fixed_cpr'] = [ '#type' => 'textfield', @@ -38,7 +38,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['test_mode_fixed_cpr'], '#description' => $this->t('Fixed CPR that will be used for all requests to the serviceplatformen instead of the provided CPR.'), '#states' => [ - // Hide the settings when the cancel notify checkbox is disabled. + // Hide the settings when the "cancel notify" checkbox is disabled. 'visible' => [ 'input[name="mode_selector"]' => ['value' => 1], ], @@ -60,7 +60,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { if ($form_state->getValue('mode_selector') == 0) { $form_state->setValue('test_mode_fixed_cpr', ''); } @@ -94,7 +94,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s * [status] => TRUE/FALSE * [error] => Descriptive text shown when CPR doesn't validate */ - public function cprBasicInformation($cpr) { + public function cprBasicInformation(string $cpr): array { \Drupal::logger('os2web_datalookup')->warning('"Serviceplatformen CPR (SF6008)" is obsolete and will be phased out. Please switch to "Serviceplatformen CPR - extended (SF1520)" as soon as possible'); $request = $this->prepareRequest(); @@ -105,36 +105,36 @@ public function cprBasicInformation($cpr) { /** * Validate cpr callback. * - * @cpr String - PSN (cpr) ([0-9]{6}\-[0-9]{4}) + * @param string $cpr - PSN (cpr) ([0-9]{6}\-[0-9]{4}) * * @return array * [status] => TRUE/FALSE * [error] => Descriptive text shown when CPR doesn't validate */ - public function validateCpr($cpr) { + public function validateCpr(string $cpr): array { return $this->cprBasicInformation($cpr); } /** * Fetch address for the specified CPR. * - * @cpr + * @param string $cpr * String - PSN (cpr) ([0-9]{6}\-[0-9]{4}) * - * @deprecated use lookup() instead. - * * @return array * [status] => TRUE/FALSE * [address] => Roadname 10 * [zipcode] => 1212 * [error] => Descriptive text if something goes wrong + *@deprecated use lookup() instead. + * */ - public function getAddress($cpr) { + public function getAddress(string $cpr): array { \Drupal::logger('os2web_datalookup')->notice('Calling \'getAddress()\' directly is deprecated, use DataLookupInterfaceCpr::lookup() method.'); $result = $this->cprBasicInformation($cpr); - // If all goes well we return address array. + // If all goes well, we return an address array. if ($result['status']) { return [ 'status' => $result['status'], @@ -159,12 +159,12 @@ public function getAddress($cpr) { /** * @inheritDoc */ - public function lookup($cpr) { + public function lookup(string $cpr): CprLookupResult { $result = $this->cprBasicInformation($cpr); $cprResult = new CprLookupResult(); - // If all goes well we return address array. + // If all goes well, we return an address array. if ($result['status']) { $cprResult->setSuccessful(); $cprResult->setCpr($cpr); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php index 395efda..cb94e3d 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php @@ -3,6 +3,7 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; use DateTime; +use DateTimeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\Markup; @@ -52,7 +53,7 @@ class ServiceplatformenCPRExtended extends ServiceplatformenBase implements Data /** * {@inheritdoc} */ - public function defaultConfiguration() { + public function defaultConfiguration(): array { return array_merge(parent::defaultConfiguration(), [ 'test_mode_fixed_cpr' => '', ]); @@ -61,7 +62,7 @@ public function defaultConfiguration() { /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['mode_fieldset']['test_mode_fixed_cpr'] = [ '#type' => 'textfield', @@ -85,7 +86,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { parent::submitConfigurationForm($form, $form_state); if (!empty($form_state->getValue('test_cpr'))) { @@ -106,7 +107,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s /** * {@inheritDoc} */ - public function lookup($cpr, $fetchChildren = TRUE, $allowCprTestModeReplace = TRUE) { + public function lookup(string $cpr, $fetchChildren = TRUE, $allowCprTestModeReplace = TRUE): CprLookupResult { if ($this->configuration['mode_selector'] == 1 && $this->configuration['test_mode_fixed_cpr']) { if ($allowCprTestModeReplace) { $cpr = $this->configuration['test_mode_fixed_cpr']; @@ -123,7 +124,7 @@ public function lookup($cpr, $fetchChildren = TRUE, $allowCprTestModeReplace = T $result = $this->query('PersonLookup', $request); $cprResult = new CprLookupResult(); - // If all goes well we return address array. + // If all goes well, we return an address array. if ($result['status']) { $cprResult->setSuccessful(); $cprResult->setCpr($cpr); @@ -149,7 +150,7 @@ public function lookup($cpr, $fetchChildren = TRUE, $allowCprTestModeReplace = T $cprResult->setCitizen(FALSE); } - $citizenshipDate = DateTime::createFromFormat(DateTime::RFC3339_EXTENDED, $persondata->statsborgerskab->statsborgerskabDato->dato); + $citizenshipDate = DateTime::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, $persondata->statsborgerskab->statsborgerskabDato->dato); $cprResult->setCitizenshipDate($citizenshipDate); } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php index 7dd7c8e..ec30650 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php @@ -21,7 +21,7 @@ class ServiceplatformenCVR extends ServiceplatformenBase implements DataLookupIn /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['test_cvr'] = [ '#type' => 'textfield', @@ -33,7 +33,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { parent::submitConfigurationForm($form, $form_state); if (!empty($form_state->getValue('test_cvr'))) { $response = $this->getInfo($form_state->getValue('test_cvr')); @@ -60,7 +60,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s * [company_zipcode] => ZIP code * [company_city] => City */ - public function getLegalUnit($cvr) { + public function getLegalUnit(string $cvr): array { $request = $this->prepareRequest(); $request['GetLegalUnitRequest'] = [ 'level' => 1, @@ -89,7 +89,7 @@ public function getLegalUnit($cvr) { * [company_city] => City * [company_municipalitycode] => Municipality code, */ - public function getInfo($cvr) { + public function getInfo(string $cvr): array { $result = $this->getLegalUnit($cvr); if ($result['status']) { $legalUnit = (array) $result['GetLegalUnitResponse']->LegalUnit; @@ -114,13 +114,13 @@ public function getInfo($cvr) { /** * {@inheritdoc} */ - public function lookup($cvr) { - $result = $this->getInfo($cvr); + public function lookup(string $param): CompanyLookupResult { + $result = $this->getInfo($param); $cvrResult = new CompanyLookupResult(); if ($result['status']) { $cvrResult->setSuccessful(); - $cvrResult->setCvr($cvr); + $cvrResult->setCvr($param); $cvrResult->setName($result['company_name']); $cvrResult->setStreet($result['company_street']); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php index 3b3dd74..941361f 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php @@ -21,7 +21,7 @@ class ServiceplatformenPNumber extends ServiceplatformenBase implements DataLook /** * {@inheritdoc} */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + public function buildConfigurationForm(array $form, FormStateInterface $form_state): array { $form = parent::buildConfigurationForm($form, $form_state); $form['test_p_number'] = [ '#type' => 'textfield', @@ -33,7 +33,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta /** * {@inheritdoc} */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void { parent::submitConfigurationForm($form, $form_state); if (!empty($form_state->getValue('test_p_number'))) { $response = $this->getInfo($form_state->getValue('test_p_number')); @@ -61,7 +61,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s * [company_zipcode] => ZIP code * [company_city] => City */ - public function getProductionUnit($pNumber) { + public function getProductionUnit(string $pNumber): array { $request = $this->prepareRequest(); $request['GetProductionUnitRequest'] = [ 'level' => 1, @@ -89,7 +89,7 @@ public function getProductionUnit($pNumber) { * [company_zipcode] => ZIP code * [company_city] => City, */ - public function getInfo($pNumber) { + public function getInfo(string $pNumber): array { $result = $this->getProductionUnit($pNumber); if ($result['status']) { $productionUnit = (array) $result['GetProductionUnitResponse']->ProductionUnit; @@ -113,8 +113,8 @@ public function getInfo($pNumber) { /** * {@inheritdoc} */ - public function lookup($pNumber) { - $result = $this->getInfo($pNumber); + public function lookup(string $param): CompanyLookupResult { + $result = $this->getInfo($param); $cvrResult = new CompanyLookupResult(); if ($result['status']) { @@ -137,6 +137,8 @@ public function lookup($pNumber) { $cvrResult->setSuccessful(FALSE); $cvrResult->setErrorMessage($result['error']); } + + // @todo: Noting returned? } } From d97324e0d18493e7ea3e0430fb3111b1974c1715 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2024 15:17:17 +0200 Subject: [PATCH 02/18] ITKDev: Added audit logging to lookups --- src/Plugin/os2web/DataLookup/DatafordelerCVR.php | 7 +++++-- src/Plugin/os2web/DataLookup/DatafordelerPNumber.php | 5 ++++- src/Plugin/os2web/DataLookup/ServiceplatformenBase.php | 4 ++++ src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php index 1c4c5b3..ef6bf05 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php @@ -66,10 +66,13 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function lookup(string $param): CompanyLookupResult { try { + os2forms_audit_log('DataLookup', time(), 'Hent virksomhed med CVRNummer: ' . $param, TRUE); $response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $param]]); $result = json_decode((string) $response->getBody()); } catch (ClientException $e) { + $msg = sprintf('Hent virksomhed med CVRNummer (%s): %s', $param, $e->getMessage()); + os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); $result = $e->getMessage(); } @@ -90,7 +93,7 @@ public function lookup(string $param): CompanyLookupResult { $cvrResult->setFloor($address->CVRAdresse_etagebetegnelse ?? ''); $cvrResult->setApartmentNr($address->CVRAdresse_doerbetegnelse ?? ''); $cvrResult->setPostalCode($address->CVRAdresse_postnummer ?? ''); - $city = $address->CVRAdresse_postdistrikt ?? '' . $cvrResult->getPostalCode(); + $city = ($address->CVRAdresse_postdistrikt ?? '') . $cvrResult->getPostalCode() ?? ''; $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); @@ -109,7 +112,7 @@ public function lookup(string $param): CompanyLookupResult { $address .= ', ' . $cvrResult->getPostalCode() . ' ' . $cvrResult->getCity(); } - $cvrResult->setAddress($address ?? ''); + $cvrResult->setAddress($address); } } else { diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index 714632b..a168d80 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php @@ -66,10 +66,13 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function lookup(string $param): CompanyLookupResult { try { + os2forms_audit_log('DataLookup', time(), 'Hent produktionsenhed med PNummer: ' . $param, TRUE); $response = $this->httpClient->get('hentProduktionsenhedMedPNummer', ['query' => ['ppNummer' => $param]]); $result = json_decode((string) $response->getBody()); } catch (ClientException $e) { + $msg = sprintf('Hent produktionsenhed med PNummer (%s): %s', $param, $e->getMessage()); + os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); $result = $e->getMessage(); } @@ -90,7 +93,7 @@ public function lookup(string $param): CompanyLookupResult { $cvrResult->setFloor($address->CVRAdresse_etagebetegnelse ?? ''); $cvrResult->setApartmentNr($address->CVRAdresse_doerbetegnelse ?? ''); $cvrResult->setPostalCode($address->CVRAdresse_postnummer ?? ''); - $city = $address->CVRAdresse_postdistrikt ?? '' . $cvrResult->getPostalCode(); + $city = ($address->CVRAdresse_postdistrikt ?? '') . $cvrResult->getPostalCode() ?? ''; $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); $address = $cvrResult->getStreet() . ' ' . $cvrResult->getHouseNr() . ' ' . $cvrResult->getFloor() . $cvrResult->getApartmentNr(); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php index 63ade00..e4faae1 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php @@ -289,10 +289,14 @@ protected function query(string $method, array $request): array { } try { + $msg = sprintf('Method %s called with (%s)', $method, implode(', ', $request)); + os2forms_audit_log('DataLookup', time(), $msg, TRUE); $response = (array) $this->client->$method($request); $response['status'] = TRUE; } catch (\SoapFault $e) { + $msg = sprintf('Method %s called with (%s): %s', $method, implode(', ', $request), $e->faultstring); + os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); $response = [ 'status' => FALSE, 'error' => $e->faultstring, diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php index 941361f..1363dfc 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php @@ -138,7 +138,7 @@ public function lookup(string $param): CompanyLookupResult { $cvrResult->setErrorMessage($result['error']); } - // @todo: Noting returned? + return $cvrResult; } } From 9ff36c684b9bccf805bc20ec0c05d09545e971ab Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 24 Apr 2024 15:34:50 +0200 Subject: [PATCH 03/18] ITKDev: Install file should not be executable --- os2web_datalookup.install | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 os2web_datalookup.install diff --git a/os2web_datalookup.install b/os2web_datalookup.install old mode 100755 new mode 100644 From 90268465bc9dcff3bef82b18428dd4468f843ab4 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 26 Apr 2024 13:19:14 +0200 Subject: [PATCH 04/18] ITKDev: Refactored audit logging --- .../os2web/DataLookup/DataLookupBase.php | 18 ++++++++++++++++-- .../os2web/DataLookup/DatafordelerBase.php | 11 ++++++++--- .../os2web/DataLookup/DatafordelerCVR.php | 5 +++-- .../os2web/DataLookup/DatafordelerPNumber.php | 6 ++++-- .../DataLookup/ServiceplatformenBase.php | 4 ++-- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Plugin/os2web/DataLookup/DataLookupBase.php b/src/Plugin/os2web/DataLookup/DataLookupBase.php index 4402e9d..2087814 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupBase.php +++ b/src/Plugin/os2web/DataLookup/DataLookupBase.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; +use Drupal\os2web_audit\Service\Logger; /** * Provides a base class for image effects. @@ -24,18 +25,31 @@ 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) { + public function __construct( + array $configuration, + $plugin_id, + $plugin_definition, + Logger $auditLogger, + ) { parent::__construct($configuration, $plugin_id, $plugin_definition); + $this->auditLogger = $auditLogger; $this->setConfiguration($configuration); } /** * {@inheritdoc} */ - public function label() { + public function label(): string { return $this->pluginDefinition['label']; } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerBase.php b/src/Plugin/os2web/DataLookup/DatafordelerBase.php index 4757272..f5ee198 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerBase.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerBase.php @@ -3,7 +3,7 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\TranslatableMarkup; +use Drupal\os2web_audit\Service\Logger; use GuzzleHttp\Client; /** @@ -21,8 +21,13 @@ abstract class DatafordelerBase extends DataLookupBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct( + array $configuration, + $plugin_id, + $plugin_definition, + Logger $auditLogger, + ) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger); $this->init(); } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php index ef6bf05..b35db08 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php @@ -66,13 +66,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function lookup(string $param): CompanyLookupResult { try { - os2forms_audit_log('DataLookup', time(), 'Hent virksomhed med CVRNummer: ' . $param, TRUE); + $msg = sprintf('Hent virksomhed med CVRNummer: %s', $param); + $this->auditLogger->info('DataLookup', $msg); $response = $this->httpClient->get('hentVirksomhedMedCVRNummer', ['query' => ['pCVRNummer' => $param]]); $result = json_decode((string) $response->getBody()); } catch (ClientException $e) { $msg = sprintf('Hent virksomhed med CVRNummer (%s): %s', $param, $e->getMessage()); - os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); + $this->auditLogger->error('DataLookup', $msg); $result = $e->getMessage(); } diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index a168d80..cf67257 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php @@ -7,6 +7,7 @@ use Drupal\Core\Render\Markup; use Drupal\os2web_datalookup\LookupResult\CompanyLookupResult; use GuzzleHttp\Exception\ClientException; +use function Symfony\Component\String\s; /** * Defines a plugin for DatafordelerPNumber. @@ -66,13 +67,14 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function lookup(string $param): CompanyLookupResult { try { - os2forms_audit_log('DataLookup', time(), 'Hent produktionsenhed med PNummer: ' . $param, TRUE); + $msg = sprintf('Hent produktionsenhed med PNummer: ', $param); + $this->auditLogger->info('DataLookup', $msg); $response = $this->httpClient->get('hentProduktionsenhedMedPNummer', ['query' => ['ppNummer' => $param]]); $result = json_decode((string) $response->getBody()); } catch (ClientException $e) { $msg = sprintf('Hent produktionsenhed med PNummer (%s): %s', $param, $e->getMessage()); - os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); + $this->auditLogger->error('DataLookup', $msg); $result = $e->getMessage(); } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php index e4faae1..80b7acc 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php @@ -290,13 +290,13 @@ protected function query(string $method, array $request): array { try { $msg = sprintf('Method %s called with (%s)', $method, implode(', ', $request)); - os2forms_audit_log('DataLookup', time(), $msg, TRUE); + $this->auditLogger->info('DataLookup', $msg); $response = (array) $this->client->$method($request); $response['status'] = TRUE; } catch (\SoapFault $e) { $msg = sprintf('Method %s called with (%s): %s', $method, implode(', ', $request), $e->faultstring); - os2forms_audit_log('DataLookup', time(), $msg, TRUE, ['error' => TRUE]); + $this->auditLogger->error('DataLookup', $msg); $response = [ 'status' => FALSE, 'error' => $e->faultstring, From 2d58f15b7958f84307a5523d27f0ec7aa3f48a26 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 26 Apr 2024 13:23:15 +0200 Subject: [PATCH 05/18] ITKDev: Added github actions to check code style --- .github/PULL_REQUEST_TEMPLATE.md | 23 +++++++++ .github/workflows/pr.yml | 89 ++++++++++++++++++++++++++++++++ composer.json | 28 ++++++++++ package.json | 13 +++++ 4 files changed, 153 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 package.json diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..a4b263e --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,23 @@ +#### Link to ticket + +Please add a link to the ticket being addressed by this change. + +#### Description + +Please include a short description of the suggested change and the reasoning behind the approach you have chosen. + +#### Screenshot of the result + +If your change affects the user interface you should include a screenshot of the result with the pull request. + +#### Checklist + +- [ ] My code passes our static analysis suite. +- [ ] My code passes our continuous integration process. + +If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change +should be exempt from the list. + +#### Additional comments or questions + +If you have any further comments or questions for the reviewer please add them here. diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d6df738..f436964 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -17,3 +17,92 @@ jobs: - name: Check that changelog has been updated. run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0 + + test-composer-files: + name: Validate composer + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.1' ] + dependency-version: [ prefer-lowest, prefer-stable ] + steps: + - uses: actions/checkout@master + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: json + coverage: none + tools: composer:v2 + # https://github.com/shivammathur/setup-php#cache-composer-dependencies + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Validate composer files + run: | + composer validate --strict composer.json + # Check that dependencies resolve. + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction + + php-coding-standards: + name: PHP coding standards + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.1' ] + steps: + - uses: actions/checkout@master + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: json + coverage: none + tools: composer:v2 + # https://github.com/shivammathur/setup-php#cache-composer-dependencies + - name: Get composer cache directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + - name: Install Dependencies + run: | + composer install --no-interaction --no-progress + - name: PHPCS + run: | + composer coding-standards-check/phpcs + + markdownlint: + runs-on: ubuntu-latest + name: markdownlint + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Cache yarn packages + uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Yarn install + uses: actions/setup-node@v2 + with: + node-version: '20' + - run: yarn install + - name: markdownlint + run: yarn coding-standards-check/markdownlint diff --git a/composer.json b/composer.json index bc478a1..5c44f2f 100644 --- a/composer.json +++ b/composer.json @@ -17,5 +17,33 @@ "type": "composer", "url": "https://asset-packagist.org" } + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "drupal/coder": "^8.3", + "mglaman/phpstan-drupal": "^1.1", + "phpstan/extension-installer": "^1.3", + "phpstan/phpstan-deprecation-rules": "^1.1", + "phpunit/phpunit": "^9.5" + }, + "scripts": { + "code-analysis/phpstan": [ + "phpstan analyse" + ], + "code-analysis": [ + "@code-analysis/phpstan" + ], + "coding-standards-check/phpcs": [ + "phpcs --standard=phpcs.xml.dist" + ], + "coding-standards-check": [ + "@coding-standards-check/phpcs" + ], + "coding-standards-apply/phpcs": [ + "phpcbf --standard=phpcs.xml.dist" + ], + "coding-standards-apply": [ + "@coding-standards-apply/phpcs" + ] } } diff --git a/package.json b/package.json new file mode 100644 index 0000000..52fcd34 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "license": "UNLICENSED", + "private": true, + "devDependencies": { + "markdownlint-cli": "^0.32.2" + }, + "scripts": { + "coding-standards-check/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md'", + "coding-standards-check": "yarn coding-standards-check/markdownlint", + "coding-standards-apply/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md' --fix", + "coding-standards-apply": "yarn coding-standards-apply/markdownlint" + } +} From b111ebbe0b81dcfa1251f2173780511c488c53fc Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 7 May 2024 15:14:58 +0200 Subject: [PATCH 06/18] ITKDev: Removed markdown check --- .github/workflows/pr.yml | 25 ------------------------- README.md | 1 + package.json | 13 ------------- 3 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 package.json diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f436964..132f08e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -81,28 +81,3 @@ jobs: - name: PHPCS run: | composer coding-standards-check/phpcs - - markdownlint: - runs-on: ubuntu-latest - name: markdownlint - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Cache yarn packages - uses: actions/cache@v2 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - name: Yarn install - uses: actions/setup-node@v2 - with: - node-version: '20' - - run: yarn install - - name: markdownlint - run: yarn coding-standards-check/markdownlint diff --git a/README.md b/README.md index 0fb17a1..b6fea44 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ drush en os2web_datalookup ``` ## Update + Updating process for OS2Web Data lookup module is similar to the usual Drupal 8 module. Use Composer's built-in command for listing packages that have updates available: diff --git a/package.json b/package.json deleted file mode 100644 index 52fcd34..0000000 --- a/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "license": "UNLICENSED", - "private": true, - "devDependencies": { - "markdownlint-cli": "^0.32.2" - }, - "scripts": { - "coding-standards-check/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md'", - "coding-standards-check": "yarn coding-standards-check/markdownlint", - "coding-standards-apply/markdownlint": "yarn markdownlint --ignore LICENSE.md --ignore vendor --ignore node_modules '*.md' 'modules/os2forms_digital_post/**/*.md' --fix", - "coding-standards-apply": "yarn coding-standards-apply/markdownlint" - } -} From 90c5090d7cb40e42369297f1d46a8a54fbf7d0a0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 7 May 2024 15:17:59 +0200 Subject: [PATCH 07/18] ITKDev: Allow plugins in composer --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index 5c44f2f..c97e622 100644 --- a/composer.json +++ b/composer.json @@ -45,5 +45,11 @@ "coding-standards-apply": [ "@coding-standards-apply/phpcs" ] + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true + } } } From babbaf1d2ca26abb7885e949f62ba579a38b26c6 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 7 May 2024 15:20:18 +0200 Subject: [PATCH 08/18] ITKDev: Added code style --- phpcs.xml.dist | 23 +++++++++++++++++++++++ phpstan.neon | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 phpcs.xml.dist create mode 100644 phpstan.neon diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..e6cd9bb --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,23 @@ + + + OS2web Audit PHP Code Sniffer configuration + + . + vendor/ + node_modules/ + + + + + + + + + + + + + + + + diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..2715fef --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,28 @@ +parameters: + level: 6 + paths: + - ./ + excludePaths: + # @see https://github.com/mglaman/drupal-check/issues/261#issuecomment-1030141772/ + - vendor + - '*/node_modules/*' + ignoreErrors: + # This is how drupal works.... + - '#Unsafe usage of new static\(\).#' + - '#getEditableConfigNames\(\) return type has no value type specified in iterable type array#' + - '#buildForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#buildForm\(\) return type has no value type specified in iterable type array.#' + - '#validateForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#submitForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#getDerivativeDefinitions\(\) has parameter \$base_plugin_definition with no value type specified in iterable type array.#' + - '#getDerivativeDefinitions\(\) return type has no value type specified in iterable type array.#' + - '#LoggerManager::__construct\(\) has parameter \$namespaces with no value type specified in iterable type Traversable.#' + - '#__construct\(\) has parameter \$configuration with no value type specified in iterable type array.#' + - '#getConfiguration\(\) return type has no value type specified in iterable type array.#' + - '#setConfiguration\(\) has parameter \$configuration with no value type specified in iterable type array.#' + - '#defaultConfiguration\(\) return type has no value type specified in iterable type array.#' + - '#buildConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#buildConfigurationForm\(\) return type has no value type specified in iterable type array.#' + - '#validateConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#submitConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' + - '#getForm\(\) invoked with 2 parameters, 1 required.#' From 996ff2734a2cc1f4295c4cc122292325c3d37e09 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 7 May 2024 15:27:23 +0200 Subject: [PATCH 09/18] ITKDev: Code review changes Co-authored-by: Mikkel Ricky --- README.md | 4 +- composer.json | 2 +- os2web_datalookup.install | 11 +- phpcs.xml.dist | 2 +- phpstan.neon | 21 +- src/Annotation/DataLookup.php | 13 +- src/Controller/DatalookupController.php | 19 +- .../DataLookupPluginGroupSettingsForm.php | 23 ++- src/Form/DataLookupPluginSettingsForm.php | 4 +- src/Form/PluginSettingsFormBase.php | 22 ++- src/Form/PluginSettingsFormInterface.php | 2 +- src/LookupResult/CompanyLookupResult.php | 108 ++++++++-- src/LookupResult/CprLookupResult.php | 184 +++++++++++++++--- src/Plugin/DataLookupManager.php | 16 +- .../Derivative/GroupSettingsLocalTasks.php | 20 +- ...any.php => DataLookupCompanyInterface.php} | 10 +- ...faceCpr.php => DataLookupCprInterface.php} | 5 +- .../os2web/DataLookup/DataLookupInterface.php | 1 - .../os2web/DataLookup/DatafordelerBase.php | 2 +- .../os2web/DataLookup/DatafordelerCVR.php | 7 +- .../os2web/DataLookup/DatafordelerPNumber.php | 8 +- .../DataLookup/ServiceplatformenCPR.php | 48 +++-- .../ServiceplatformenCPRExtended.php | 10 +- .../DataLookup/ServiceplatformenCVR.php | 2 +- .../DataLookup/ServiceplatformenPNumber.php | 2 +- src/Routing/DataLookupRoutes.php | 29 +-- 26 files changed, 403 insertions(+), 172 deletions(-) rename src/Plugin/os2web/DataLookup/{DataLookupInterfaceCompany.php => DataLookupCompanyInterface.php} (62%) rename src/Plugin/os2web/DataLookup/{DataLookupInterfaceCpr.php => DataLookupCprInterface.php} (80%) diff --git a/README.md b/README.md index b6fea44..a84bb1a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline) // CVR lookup /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */ $pluginManager = \Drupal::service('plugin.manager.os2web_datalookup'); -/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCompany $cvrPlugin */ +/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCompanyInterface $cvrPlugin */ $cvrPlugin = $pluginManager->createDefaultInstanceByGroup('cvr_lookup'); if ($cvrPlugin->isReady()) { @@ -57,7 +57,7 @@ if ($cvrPlugin->isReady()) { // CPR lookup. /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager $pluginManager */ $pluginManager = \Drupal::service('plugin.manager.os2web_datalookup'); -/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterfaceCpr $cprPlugin */ +/** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupCprInterface $cprPlugin */ $cprPlugin = $pluginManager->createDefaultInstanceByGroup('cpr_lookup'); if ($cprPlugin->isReady()) { diff --git a/composer.json b/composer.json index c97e622..e6d46db 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.1", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", "mglaman/phpstan-drupal": "^1.1", "phpstan/extension-installer": "^1.3", diff --git a/os2web_datalookup.install b/os2web_datalookup.install index 2ef175e..55bc8c5 100644 --- a/os2web_datalookup.install +++ b/os2web_datalookup.install @@ -1,11 +1,16 @@ getEditable(DataLookupPluginGroupSettingsForm::$configName); $config->set("cpr_lookup.default_plugin", 'serviceplatformen_cpr_extended'); $config->save(); @@ -14,7 +19,7 @@ function os2web_datalookup_update_9001() { /** * Setting "datafordeler_cvr" as default CVR lookup plugin. */ -function os2web_datalookup_update_9002() { +function os2web_datalookup_update_9002(): void { $config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName); $config->set("cvr_lookup.default_plugin", 'datafordeler_cvr'); $config->save(); @@ -23,7 +28,7 @@ function os2web_datalookup_update_9002() { /** * Setting "datafordeler_pnumber" as default P-Number lookup plugin. */ -function os2web_datalookup_update_9003() { +function os2web_datalookup_update_9003(): void { $config = \Drupal::service('config.factory')->getEditable(DataLookupPluginGroupSettingsForm::$configName); $config->set("pnumber_lookup.default_plugin", 'datafordeler_pnumber'); $config->save(); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index e6cd9bb..cc0cccf 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,6 +1,6 @@ - OS2web Audit PHP Code Sniffer configuration + OS2web Datalookup PHP Code Sniffer configuration . vendor/ diff --git a/phpstan.neon b/phpstan.neon index 2715fef..56bf890 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,21 +8,6 @@ parameters: - '*/node_modules/*' ignoreErrors: # This is how drupal works.... - - '#Unsafe usage of new static\(\).#' - - '#getEditableConfigNames\(\) return type has no value type specified in iterable type array#' - - '#buildForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#buildForm\(\) return type has no value type specified in iterable type array.#' - - '#validateForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#submitForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#getDerivativeDefinitions\(\) has parameter \$base_plugin_definition with no value type specified in iterable type array.#' - - '#getDerivativeDefinitions\(\) return type has no value type specified in iterable type array.#' - - '#LoggerManager::__construct\(\) has parameter \$namespaces with no value type specified in iterable type Traversable.#' - - '#__construct\(\) has parameter \$configuration with no value type specified in iterable type array.#' - - '#getConfiguration\(\) return type has no value type specified in iterable type array.#' - - '#setConfiguration\(\) has parameter \$configuration with no value type specified in iterable type array.#' - - '#defaultConfiguration\(\) return type has no value type specified in iterable type array.#' - - '#buildConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#buildConfigurationForm\(\) return type has no value type specified in iterable type array.#' - - '#validateConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#submitConfigurationForm\(\) has parameter \$form with no value type specified in iterable type array.#' - - '#getForm\(\) invoked with 2 parameters, 1 required.#' + - '#\Drupal calls should be avoided in classes, use dependency injection instead#' + - '#The text '@deprecated use lookup\(\) instead.' does not match the standard format: @deprecated in %deprecation-version% and is#' + - '#Each @deprecated tag must have a @see tag immediately following it#' diff --git a/src/Annotation/DataLookup.php b/src/Annotation/DataLookup.php index 807383f..1d00608 100644 --- a/src/Annotation/DataLookup.php +++ b/src/Annotation/DataLookup.php @@ -3,6 +3,7 @@ namespace Drupal\os2web_datalookup\Annotation; use Drupal\Component\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; /** * Defines a AuthProvider annotation object. @@ -22,7 +23,7 @@ class DataLookup extends Plugin { * * @var string */ - public $id; + public string $id; /** * The human-readable name of the consent storage. @@ -31,24 +32,24 @@ class DataLookup extends Plugin { * * @ingroup plugin_translatable */ - public $label; + public Translation $label; /** * A brief description of the consent storage. * * This will be shown when adding or configuring this consent storage. * - * @var \Drupal\Core\Annotation\Translation + * @var \Drupal\Core\Annotation\Translation|string * * @ingroup plugin_translatable */ - public $description = ''; + public Translation|string $description = ''; /** - * Group of the plugin lookup plugin. + * Group of the plugin lookup plugins. * * @var string */ - public $group = ''; + public string $group = ''; } diff --git a/src/Controller/DatalookupController.php b/src/Controller/DatalookupController.php index 5550f9f..a778eb7 100644 --- a/src/Controller/DatalookupController.php +++ b/src/Controller/DatalookupController.php @@ -5,11 +5,10 @@ use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Link; -use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** - * Class DatalookupController. + * Data lookup controller. * * @package Drupal\os2web_datalookup\Controller */ @@ -20,10 +19,13 @@ class DatalookupController extends ControllerBase { * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $manager; + protected PluginManagerInterface $manager; /** - * {@inheritdoc} + * Default constructor. + * + * @param \Drupal\Component\Plugin\PluginManagerInterface $manager + * The plugin manger. */ public function __construct(PluginManagerInterface $manager) { $this->manager = $manager; @@ -40,8 +42,13 @@ public static function create(ContainerInterface $container) { /** * Status list callback. + * + * @return array + * An render array. + * + * @throws \Drupal\Component\Plugin\Exception\PluginException */ - public function statusList() { + public function statusList(): array { $headers = [ 'title' => $this ->t('Title'), @@ -55,7 +62,7 @@ public function statusList() { $rows = []; foreach ($this->manager->getDefinitions() as $id => $plugin_definition) { - /** @var DataLookupInterface $plugin */ + /** @var \Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupInterface $plugin */ $plugin = $this->manager->createInstance($id); $status = $plugin->getStatus(); $rows[$id] = [ diff --git a/src/Form/DataLookupPluginGroupSettingsForm.php b/src/Form/DataLookupPluginGroupSettingsForm.php index 057accc..11ef7f2 100644 --- a/src/Form/DataLookupPluginGroupSettingsForm.php +++ b/src/Form/DataLookupPluginGroupSettingsForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; +use Drupal\os2web_datalookup\Plugin\DataLookupManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -18,16 +19,20 @@ class DataLookupPluginGroupSettingsForm extends ConfigFormBase { * * @var string */ - public static $configName = 'os2web_datalookup.groups.settings'; + public static string $configName = 'os2web_datalookup.groups.settings'; - /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager */ - protected $dataLookupManager; + /** + * Data lookup manager. + * + * @var \Drupal\os2web_datalookup\Plugin\DataLookupManager + */ + protected DataLookupManager $dataLookupManager; /** * Constructs a new DataLookupPluginGroupSettingsForm object. * - * @param \Drupal\os2web_datalookup\Plugin\DataLookupManager - * Datalookup manager. + * @param \Drupal\os2web_datalookup\Plugin\DataLookupManager $dataLookupManager + * Data lookup manager. */ public function __construct(PluginManagerInterface $dataLookupManager) { $this->dataLookupManager = $dataLookupManager; @@ -36,7 +41,7 @@ public function __construct(PluginManagerInterface $dataLookupManager) { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container) { + public static function create(ContainerInterface $container): static { return new static( $container->get('plugin.manager.os2web_datalookup') ); @@ -52,7 +57,7 @@ public function getFormId() { /** * {@inheritdoc} */ - protected function getEditableConfigNames() { + protected function getEditableConfigNames(): array { return [DataLookupPluginGroupSettingsForm::$configName]; } @@ -69,7 +74,7 @@ protected function getGroupIdFromRequest() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state): array { $group_id = $this->getGroupIdFromRequest(); $plugin_definitions = $this->dataLookupManager->getDefinitionsByGroup($group_id); @@ -114,7 +119,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $group_id = $this->getGroupIdFromRequest(); $config = $this->config(DataLookupPluginGroupSettingsForm::$configName); diff --git a/src/Form/DataLookupPluginSettingsForm.php b/src/Form/DataLookupPluginSettingsForm.php index e36ace3..5a96c69 100644 --- a/src/Form/DataLookupPluginSettingsForm.php +++ b/src/Form/DataLookupPluginSettingsForm.php @@ -22,7 +22,7 @@ public function __construct(ConfigFactoryInterface $config_factory, PluginManage /** * {@inheritdoc} */ - public static function create(ContainerInterface $container) { + public static function create(ContainerInterface $container): static { return new static( $container->get('config.factory'), $container->get('plugin.manager.os2web_datalookup') @@ -32,7 +32,7 @@ public static function create(ContainerInterface $container) { /** * {@inheritdoc} */ - public static function getConfigName() { + public static function getConfigName(): string { return 'os2web_datalookup'; } diff --git a/src/Form/PluginSettingsFormBase.php b/src/Form/PluginSettingsFormBase.php index 2927a55..e4874e6 100644 --- a/src/Form/PluginSettingsFormBase.php +++ b/src/Form/PluginSettingsFormBase.php @@ -7,6 +7,7 @@ * Abstract class for PluginSettingsForm implementation. */ +use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; @@ -20,36 +21,37 @@ abstract class PluginSettingsFormBase extends ConfigFormBase implements PluginSe * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $manager; + protected PluginManagerInterface $manager; /** * {@inheritdoc} */ - protected function getEditableConfigNames() { + protected function getEditableConfigNames(): array { return [$this->getConfigId()]; } /** * {@inheritdoc} */ - public function getFormId() { + public function getFormId(): string { return $this->getConfigName() . '_settings_form_' . $this->getPluginIdFromRequest(); } /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state): array { $plugin_id = $this->getPluginIdFromRequest(); $instance = $this->getPluginInstance($plugin_id); $form = $instance->buildConfigurationForm($form, $form_state); + return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ - public function validateForm(array &$form, FormStateInterface $form_state) { + public function validateForm(array &$form, FormStateInterface $form_state): void { $plugin_id = $this->getPluginIdFromRequest(); $instance = $this->getPluginInstance($plugin_id); $instance->validateConfigurationForm($form, $form_state); @@ -58,7 +60,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { /** * {@inheritdoc} */ - public function submitForm(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state): void { $plugin_id = $this->getPluginIdFromRequest(); $instance = $this->getPluginInstance($plugin_id); $instance->submitConfigurationForm($form, $form_state); @@ -77,6 +79,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { */ protected function getPluginIdFromRequest() { $request = $this->getRequest(); + return $request->get('_plugin_id'); } @@ -89,11 +92,12 @@ protected function getPluginIdFromRequest() { * @return object * Plugin instance. * - * @throws PluginException + * @throws \Drupal\Component\Plugin\Exception\PluginException */ - public function getPluginInstance($plugin_id) { + public function getPluginInstance($plugin_id): object { $configuration = $this->config($this->getConfigId())->get(); $instance = $this->manager->createInstance($plugin_id, $configuration); + return $instance; } @@ -103,7 +107,7 @@ public function getPluginInstance($plugin_id) { * @return string * Configuration object name. */ - protected function getConfigId() { + protected function getConfigId(): string { return $this->getConfigName() . '.' . $this->getPluginIdFromRequest(); } diff --git a/src/Form/PluginSettingsFormInterface.php b/src/Form/PluginSettingsFormInterface.php index 5636c40..3cc4f3c 100644 --- a/src/Form/PluginSettingsFormInterface.php +++ b/src/Form/PluginSettingsFormInterface.php @@ -15,6 +15,6 @@ interface PluginSettingsFormInterface { * @return string * Configuration name for plugins. */ - public static function getConfigName(); + public static function getConfigName(): string; } diff --git a/src/LookupResult/CompanyLookupResult.php b/src/LookupResult/CompanyLookupResult.php index 96bc0b7..cf21e9e 100644 --- a/src/LookupResult/CompanyLookupResult.php +++ b/src/LookupResult/CompanyLookupResult.php @@ -2,6 +2,9 @@ namespace Drupal\os2web_datalookup\LookupResult; +/** + * Representation or value object for the result of a company lookup. + */ class CompanyLookupResult { const CVR = 'cvr'; @@ -20,248 +23,320 @@ class CompanyLookupResult { * * @var bool */ - protected $successful = FALSE; + protected bool $successful = FALSE; /** * Status of the request. * * @var string */ - protected $errorMessage; + protected string $errorMessage; /** - * CVR + * The CVR number. * * @var string */ - protected $cvr; + protected string $cvr; /** * Company name. * * @var string */ - protected $name; + protected string $name; /** * Street of the person. * * @var string */ - protected $street; + protected string $street; /** * Street house number of the person. * * @var string */ - protected $houseNr; + protected string $houseNr; /** - * Floor number the person. + * Floor number of the person. * * @var string */ - protected $floor; + protected string $floor; /** * Apartment number of the person. * * @var string */ - protected $apartmentNr; + protected string $apartmentNr; /** * Postal code of the person. * * @var string */ - protected $postalCode; + protected string $postalCode; /** * City of the person. * * @var string */ - protected $city; + protected string $city; /** * Municipality code of the person. * * @var string */ - protected $municipalityCode; + protected string $municipalityCode; /** * Address of the person. * * @var string */ - protected $address; + protected string $address; /** + * Check the state of successful. + * * @return bool + * TRUE if successfully else FALSE. */ public function isSuccessful(): bool { return $this->successful; } /** + * The state of successful. + * * @param bool $successful + * The state. */ public function setSuccessful(bool $successful = TRUE): void { $this->successful = $successful; } /** + * Get error message. + * * @return string + * The error message. */ public function getErrorMessage(): string { return $this->errorMessage; } /** + * Set error message. + * * @param string $errorMessage + * The error message. */ public function setErrorMessage(string $errorMessage): void { $this->errorMessage = $errorMessage; } /** + * Get CVR number. + * * @return string + * The number. */ public function getCvr(): string { return $this->cvr; } /** + * Set CVR number. + * * @param string $cpr + * The number. */ public function setCvr(string $cpr): void { $this->cvr = $cpr; } /** + * Get name. + * * @return string + * The name. */ public function getName(): string { return $this->name; } /** + * Set name. + * * @param string $name + * The name. */ public function setName(string $name): void { $this->name = $name; } /** + * Get street. + * * @return string + * The street. */ public function getStreet(): string { return $this->street; } /** + * Set street. + * * @param string $street + * The street. */ public function setStreet(string $street): void { $this->street = $street; } /** + * Get house number. + * * @return string + * The number. */ public function getHouseNr(): string { return $this->houseNr; } /** + * Set house number. + * * @param string $houseNr + * The number. */ public function setHouseNr(string $houseNr): void { $this->houseNr = $houseNr; } /** + * Get a floor. + * * @return string + * The floor. */ public function getFloor(): string { return $this->floor; } /** + * Set floor. + * * @param string $floor + * The floor. */ public function setFloor(string $floor): void { $this->floor = $floor; } /** + * Get apartment number. + * * @return string + * The number. */ public function getApartmentNr(): string { return $this->apartmentNr; } /** + * Set apartment number. + * * @param string $apartmentNr + * The number. */ public function setApartmentNr(string $apartmentNr): void { $this->apartmentNr = $apartmentNr; } /** + * Get postal code. + * * @return string + * The code. */ public function getPostalCode(): string { return $this->postalCode; } /** + * Set postal code. + * * @param string $postalCode + * The code. */ public function setPostalCode(string $postalCode): void { $this->postalCode = $postalCode; } /** + * Get city. + * * @return string + * The city. */ public function getCity(): string { return $this->city; } /** + * Set city. + * * @param string $city + * The city. */ public function setCity(string $city): void { $this->city = $city; } /** + * Get municipality code. + * * @return string + * The code. */ public function getMunicipalityCode(): string { return $this->municipalityCode; } /** + * Set municipality code. + * * @param string $municipalityCode + * The code. */ public function setMunicipalityCode(string $municipalityCode): void { $this->municipalityCode = $municipalityCode; } /** + * Get address. + * * @return string + * The address. */ public function getAddress(): string { return $this->address; } /** + * Set address. + * * @param string $address + * The address to set. */ public function setAddress(string $address): void { $this->address = $address; @@ -270,12 +345,13 @@ public function setAddress(string $address): void { /** * Returns the value of the provided field. * - * @param $field + * @param string $field * Field name. * * @return mixed + * The field value or the empty string if the field does not exist. */ - public function getFieldValue($field) { + public function getFieldValue(string $field): mixed { if (property_exists($this, $field)) { return $this->{$field}; } diff --git a/src/LookupResult/CprLookupResult.php b/src/LookupResult/CprLookupResult.php index 845fe58..1b9f67c 100644 --- a/src/LookupResult/CprLookupResult.php +++ b/src/LookupResult/CprLookupResult.php @@ -2,6 +2,9 @@ namespace Drupal\os2web_datalookup\LookupResult; +/** + * Representation or value object for the result of a CPR lookup. + */ class CprLookupResult { const CPR = 'cpr'; @@ -21,133 +24,133 @@ class CprLookupResult { * * @var bool */ - protected $successful = FALSE; + protected bool $successful = FALSE; /** * Status of the request. * * @var string */ - protected $errorMessage; + protected string $errorMessage; /** - * CPR + * CPR number. * * @var string */ - protected $cpr; + protected string $cpr; /** * Name of the person. * * @var string */ - protected $name; + protected string $name; /** * Street of the person. * * @var string */ - protected $street; + protected string $street; /** * Street house number of the person. * * @var string */ - protected $houseNr; + protected string $houseNr; /** * Floor number the person. * * @var string */ - protected $floor; + protected string $floor; /** * Apartment number of the person. * * @var string */ - protected $apartmentNr; + protected string $apartmentNr; /** * Postal code of the person. * * @var string */ - protected $postalCode; + protected string $postalCode; /** * City of the person. * * @var string */ - protected $city; + protected string $city; /** * Municipality code of the person. * * @var string */ - protected $municipalityCode; + protected string $municipalityCode; /** * Address of the person. * * @var string */ - protected $address; + protected string $address; /** * CO Name of the person. * * @var string */ - protected $coName; + protected string $coName; /** * Is name/address protected of the person. * * @var bool */ - protected $nameAddressProtected = FALSE; + protected bool $nameAddressProtected = FALSE; /** * Array of children. * * @var array */ - protected $children = []; + protected array $children = []; /** * Array of guardians. * * @var array */ - protected $guardians = []; + protected array $guardians = []; /** - * Is subscribe to digital post. + * Is subscribed to digital post. * * @var bool */ - protected $digitalPostSubscribed = FALSE; + protected bool $digitalPostSubscribed = FALSE; /** * Is alive. * * @var bool */ - protected $alive = TRUE; + protected bool $alive = TRUE; /** * Is Danish citizen. * * @var bool */ - protected $citizen = TRUE; + protected bool $citizen = TRUE; /** * Citizenship date obtained. @@ -171,196 +174,280 @@ class CprLookupResult { protected \DateTime $birthDate; /** + * Check successfulness state. + * * @return bool + * TRUE on success else FALSE. */ public function isSuccessful(): bool { return $this->successful; } /** + * Set state of successfulness. + * * @param bool $successful + * The state. */ public function setSuccessful(bool $successful = TRUE): void { $this->successful = $successful; } /** + * Get an error message. + * * @return string + * The message. */ public function getErrorMessage(): string { return $this->errorMessage; } /** + * Set error message. + * * @param string $errorMessage + * The message. */ public function setErrorMessage(string $errorMessage): void { $this->errorMessage = $errorMessage; } /** + * Get CPR number. + * * @return string + * The number. */ public function getCpr(): string { return $this->cpr; } /** + * Set CPR number. + * * @param string $cpr + * The number. */ public function setCpr(string $cpr): void { $this->cpr = $cpr; } /** + * Get name. + * * @return string + * The name. */ public function getName(): string { return $this->name; } /** + * Set name. + * * @param string $name + * The name. */ public function setName(string $name): void { $this->name = $name; } /** + * Get street. + * * @return string + * The street. */ public function getStreet(): string { return $this->street; } /** + * Set street. + * * @param string $street + * The street. */ public function setStreet(string $street): void { $this->street = $street; } /** + * Get house number. + * * @return string + * The number. */ public function getHouseNr(): string { return $this->houseNr; } /** + * Set house number. + * * @param string $houseNr + * The number. */ public function setHouseNr(string $houseNr): void { $this->houseNr = $houseNr; } /** + * Get floor. + * * @return string + * The floor. */ public function getFloor(): string { return $this->floor; } /** + * Set floor. + * * @param string $floor + * The floor. */ public function setFloor(string $floor): void { $this->floor = $floor; } /** + * Get apartment number. + * * @return string + * The number. */ public function getApartmentNr(): string { return $this->apartmentNr; } /** + * Set apartment number. + * * @param string $apartmentNr + * The number. */ public function setApartmentNr(string $apartmentNr): void { $this->apartmentNr = $apartmentNr; } /** + * Get postal code. + * * @return string + * The code. */ public function getPostalCode(): string { return $this->postalCode; } /** + * Set postal code. + * * @param string $postalCode + * The code. */ public function setPostalCode(string $postalCode): void { $this->postalCode = $postalCode; } /** + * Get city name. + * * @return string + * The name. */ public function getCity(): string { return $this->city; } /** + * Set city. + * * @param string $city + * The city name. */ public function setCity(string $city): void { $this->city = $city; } /** + * Get municipality code. + * * @return string + * The code. */ public function getMunicipalityCode(): string { return $this->municipalityCode; } /** + * Set municipality code. + * * @param string $municipalityCode + * The code. */ public function setMunicipalityCode(string $municipalityCode): void { $this->municipalityCode = $municipalityCode; } /** + * Get address. + * * @return string + * The address. */ public function getAddress(): string { return $this->address; } /** + * Set address. + * * @param string $address + * The address. */ public function setAddress(string $address): void { $this->address = $address; } /** + * Get CO name. + * * @return string + * The CO name. */ public function getCoName(): string { return $this->coName; } /** + * Set CO name. + * * @param string $coName + * The CO name to set. */ public function setCoName(string $coName): void { $this->coName = $coName; } /** + * Check if the address is protected. + * * @return bool + * TRUE if it is else FALSE. */ public function isNameAddressProtected(): bool { return $this->nameAddressProtected; } /** + * Set address protected state. + * * @param bool $nameAddressProtected + * TRUE if protected else FALSE. */ public function setNameAddressProtected(bool $nameAddressProtected): void { $this->nameAddressProtected = $nameAddressProtected; @@ -377,7 +464,7 @@ public function setNameAddressProtected(bool $nameAddressProtected): void { * 'name' => full name, * ], * ... - * ] + * ]. */ public function getChildren(): array { return $this->children; @@ -395,7 +482,7 @@ public function getChildren(): array { * 'nameAddressProtected' => TRUE/FALSE * ], * ... - * ] + * ]. */ public function setChildren(array $children): void { $this->children = $children; @@ -413,7 +500,7 @@ public function setChildren(array $children): void { * 'nameAddressProtected' => TRUE/FALSE * ], * ... - * ] + * ]. */ public function getGuardians(): array { return $this->guardians; @@ -430,91 +517,127 @@ public function getGuardians(): array { * 'type' => 1|2|3|4, * ], * ... - * ] + * ]. */ public function setGuardians(array $guardians): void { $this->guardians = $guardians; } /** + * Set digital post subscriber state. + * * @param bool $digitalPostSubscribed + * The state. */ public function setDigitalPostSubscribed(bool $digitalPostSubscribed): void { $this->digitalPostSubscribed = $digitalPostSubscribed; } /** + * Check the state of digital post subscription. + * * @return bool + * TRUE if subscriber else FALSE. */ public function isDigitalPostSubscribed(): bool { return $this->digitalPostSubscribed; } /** + * Check if citizen is alive. + * * @return bool + * The living state. */ public function isAlive(): bool { return $this->alive; } /** + * Set is alive. + * * @param bool $alive + * TRUE if alive else FALSE. */ public function setAlive(bool $alive): void { $this->alive = $alive; } /** + * Check if this is a citizen. + * * @return bool + * TRUE if it is else FALSE. */ public function isCitizen(): bool { return $this->citizen; } /** + * Set citizen. + * * @param bool $citizen + * The citizen (TRUE or FALSE). */ public function setCitizen(bool $citizen): void { $this->citizen = $citizen; } /** + * Get citizenship date. + * * @return \DateTime + * The date. */ public function getCitizenshipDate(): \DateTime { return $this->citizenshipDate; } /** + * Set citizenship date. + * * @param \DateTime $citizenshipDate + * The date. */ public function setCitizenshipDate(\DateTime $citizenshipDate): void { $this->citizenshipDate = $citizenshipDate; } /** + * Get citizenship country code. + * * @return int + * The citizenship country code. */ public function getCitizenshipCountryCode(): int { return $this->citizenshipCountryCode; } /** + * Set citizenship country code. + * * @param int $citizenshipCountryCode + * The citizenship country code. */ public function setCitizenshipCountryCode(int $citizenshipCountryCode): void { $this->citizenshipCountryCode = $citizenshipCountryCode; } /** + * Get birthdate. + * * @return \DateTime + * The date. */ public function getBirthDate(): \DateTime { return $this->birthDate; } /** + * Set birthdate. + * * @param \DateTime $birthDate + * The date. */ public function setBirthDate(\DateTime $birthDate): void { $this->birthDate = $birthDate; @@ -523,13 +646,13 @@ public function setBirthDate(\DateTime $birthDate): void { /** * Checks if the provided CPR is in list of guardians. * - * @param $cpr + * @param string $cpr * Cpr number. * * @return bool - * TRUE if person has provided CPR as guardian, FALSE otherwise. + * TRUE if the person has provided CPR as guardian, FALSE otherwise. */ - public function hasGuardian($cpr): bool { + public function hasGuardian(string $cpr): bool { foreach ($this->guardians as $guardian) { if ($guardian['cpr'] == $cpr) { return TRUE; @@ -542,12 +665,13 @@ public function hasGuardian($cpr): bool { /** * Returns the value of the provided field. * - * @param $field + * @param string $field * Field name. * * @return mixed + * The value of the field or the empty string. */ - public function getFieldValue($field) { + public function getFieldValue(string $field): mixed { if (property_exists($this, $field)) { return $this->{$field}; } diff --git a/src/Plugin/DataLookupManager.php b/src/Plugin/DataLookupManager.php index b0744c0..77f5b4d 100644 --- a/src/Plugin/DataLookupManager.php +++ b/src/Plugin/DataLookupManager.php @@ -2,10 +2,10 @@ namespace Drupal\os2web_datalookup\Plugin; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Plugin\DefaultPluginManager; use Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm; use Drupal\os2web_datalookup\Form\DataLookupPluginSettingsForm; @@ -58,6 +58,7 @@ public function createInstance($plugin_id, array $configuration = []): object { // Hard switch to another plugin fallback - see // https://os2web.atlassian.net/browse/OS2FORMS-359. if ($plugin_id == 'serviceplatformen_cpr') { + // phpcs:ignore \Drupal::logger('os2web_datalookup')->warning('"Serviceplatformen CPR (SF6008)" is obsolete and will be phased out. Automatically switched to "Serviceplatformen CPR - extended (SF1520)"'); $plugin_id = 'serviceplatformen_cpr_extended'; } @@ -89,14 +90,14 @@ public function createDefaultInstanceByGroup(string $group_id): object { /** * Gets the definition of all plugins for this type based on group. * - * @param $group_id + * @param string $group_id * Group id. * * @return array * An array of plugin definitions (empty array if no definitions were * found). Keys are plugin IDs. */ - public function getDefinitionsByGroup($group_id): array { + public function getDefinitionsByGroup(string $group_id): array { $definitions = []; foreach ($this->getDefinitions() as $id => $plugin_definition) { if ($plugin_definition['group'] == $group_id) { @@ -126,15 +127,16 @@ public function getDatalookupGroups(): array { } /** - * Returns the group default plugin + * Returns the group default plugin. * - * @param $group_id + * @param string $group_id * Group ID. * * @return string|null * Plugin ID or NULL is not set. */ - public function getGroupDefaultPlugin($group_id): ?string { + public function getGroupDefaultPlugin(string $group_id): ?string { + // phpcs:ignore $config = \Drupal::config(DataLookupPluginGroupSettingsForm::$configName); return $config->get("$group_id.default_plugin"); diff --git a/src/Plugin/Derivative/GroupSettingsLocalTasks.php b/src/Plugin/Derivative/GroupSettingsLocalTasks.php index 78e5ee6..631e3bf 100644 --- a/src/Plugin/Derivative/GroupSettingsLocalTasks.php +++ b/src/Plugin/Derivative/GroupSettingsLocalTasks.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\os2web_datalookup\Plugin\DataLookupManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -12,14 +13,18 @@ */ class GroupSettingsLocalTasks extends DeriverBase implements ContainerDeriverInterface { - /** @var \Drupal\os2web_datalookup\Plugin\DataLookupManager */ - protected $dataLookupManager; + /** + * Data lookup manager. + * + * @var \Drupal\os2web_datalookup\Plugin\DataLookupManager + */ + protected DataLookupManager $dataLookupManager; /** * Constructs a new GroupSettingsLocalTasks object. * - * @param \Drupal\os2web_datalookup\Plugin\DataLookupManager - * Datalookup manager. + * @param \Drupal\Component\Plugin\PluginManagerInterface $dataLookupManager + * Data lookup manager. */ public function __construct(PluginManagerInterface $dataLookupManager) { $this->dataLookupManager = $dataLookupManager; @@ -28,7 +33,7 @@ public function __construct(PluginManagerInterface $dataLookupManager) { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, $base_plugin_id) { + public static function create(ContainerInterface $container, $base_plugin_id): static { return new static( $container->get('plugin.manager.os2web_datalookup') ); @@ -37,8 +42,9 @@ public static function create(ContainerInterface $container, $base_plugin_id) { /** * {@inheritdoc} */ - public function getDerivativeDefinitions($base_plugin_definition) { - // Implement dynamic logic to provide values for the same keys as in example.links.task.yml. + public function getDerivativeDefinitions($base_plugin_definition): array { + // Implement dynamic logic to provide values for the same keys as in + // example.links.task.yml. $groups = $this->dataLookupManager->getDatalookupGroups(); foreach ($groups as $group) { diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php b/src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php similarity index 62% rename from src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php rename to src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php index 82b9fb2..fa0fd19 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php +++ b/src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php @@ -4,7 +4,15 @@ use Drupal\os2web_datalookup\LookupResult\CompanyLookupResult; -interface DataLookupInterfaceCompany extends DataLookupInterface { +/** + * DataLookupInterfaceCompany plugin interface. + * + * This interface provides some simple tools for code receiving a plugin to + * interact with the plugin system. + * + * @ingroup plugin_api + */ +interface DataLookupCompanyInterface extends DataLookupInterface { /** * Performs lookup for the provided param. diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php b/src/Plugin/os2web/DataLookup/DataLookupCprInterface.php similarity index 80% rename from src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php rename to src/Plugin/os2web/DataLookup/DataLookupCprInterface.php index 8e36140..3662f0a 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCpr.php +++ b/src/Plugin/os2web/DataLookup/DataLookupCprInterface.php @@ -4,7 +4,10 @@ use Drupal\os2web_datalookup\LookupResult\CprLookupResult; -interface DataLookupInterfaceCpr extends DataLookupInterface { +/** + * Data lookup CPR interface. + */ +interface DataLookupCprInterface extends DataLookupInterface { /** * Performs lookup for the provided CPR. diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterface.php b/src/Plugin/os2web/DataLookup/DataLookupInterface.php index e703814..2ce2e39 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupInterface.php +++ b/src/Plugin/os2web/DataLookup/DataLookupInterface.php @@ -5,7 +5,6 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Core\Plugin\PluginFormInterface; -use Drupal\Core\StringTranslation\TranslatableMarkup; /** * DataLookupInterface plugin interface for providing some metadata inspection. diff --git a/src/Plugin/os2web/DataLookup/DatafordelerBase.php b/src/Plugin/os2web/DataLookup/DatafordelerBase.php index f5ee198..9c3179a 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerBase.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerBase.php @@ -14,7 +14,7 @@ abstract class DatafordelerBase extends DataLookupBase { /** * Http client. * - * @var Client + * @var \GuzzleHttp\Client */ protected Client $httpClient; diff --git a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php index b35db08..9ba23ef 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php @@ -17,7 +17,7 @@ * group = "cvr_lookup" * ) */ -class DatafordelerCVR extends DatafordelerBase implements DataLookupInterfaceCompany { +class DatafordelerCVR extends DatafordelerBase implements DataLookupCompanyInterface { /** * {@inheritdoc} @@ -94,7 +94,10 @@ public function lookup(string $param): CompanyLookupResult { $cvrResult->setFloor($address->CVRAdresse_etagebetegnelse ?? ''); $cvrResult->setApartmentNr($address->CVRAdresse_doerbetegnelse ?? ''); $cvrResult->setPostalCode($address->CVRAdresse_postnummer ?? ''); - $city = ($address->CVRAdresse_postdistrikt ?? '') . $cvrResult->getPostalCode() ?? ''; + $city = implode(' ', array_filter([ + $address->CVRAdresse_postdistrikt ?? NULL, + $cvrResult->getPostalCode() ?? NULL, + ]); $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index cf67257..32eed44 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php @@ -7,7 +7,6 @@ use Drupal\Core\Render\Markup; use Drupal\os2web_datalookup\LookupResult\CompanyLookupResult; use GuzzleHttp\Exception\ClientException; -use function Symfony\Component\String\s; /** * Defines a plugin for DatafordelerPNumber. @@ -18,7 +17,7 @@ * group = "pnumber_lookup" * ) */ -class DatafordelerPNumber extends DatafordelerBase implements DataLookupInterfaceCompany { +class DatafordelerPNumber extends DatafordelerBase implements DataLookupCompanyInterface { /** * {@inheritdoc} @@ -95,7 +94,10 @@ public function lookup(string $param): CompanyLookupResult { $cvrResult->setFloor($address->CVRAdresse_etagebetegnelse ?? ''); $cvrResult->setApartmentNr($address->CVRAdresse_doerbetegnelse ?? ''); $cvrResult->setPostalCode($address->CVRAdresse_postnummer ?? ''); - $city = ($address->CVRAdresse_postdistrikt ?? '') . $cvrResult->getPostalCode() ?? ''; + $city = implode(' ', array_filter([ + $address->CVRAdresse_postdistrikt ?? NULL, + $cvrResult->getPostalCode() ?? NULL, + ]); $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); $address = $cvrResult->getStreet() . ' ' . $cvrResult->getHouseNr() . ' ' . $cvrResult->getFloor() . $cvrResult->getApartmentNr(); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php index b0d9e61..d71d94f 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php @@ -16,7 +16,7 @@ * group = "cpr_lookup" * ) */ -class ServiceplatformenCPR extends ServiceplatformenBase implements DataLookupInterfaceCpr { +class ServiceplatformenCPR extends ServiceplatformenBase implements DataLookupCprInterface { /** * {@inheritdoc} @@ -38,7 +38,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['test_mode_fixed_cpr'], '#description' => $this->t('Fixed CPR that will be used for all requests to the serviceplatformen instead of the provided CPR.'), '#states' => [ - // Hide the settings when the "cancel notify" checkbox is disabled. + // Show the element only when running in test mode. 'visible' => [ 'input[name="mode_selector"]' => ['value' => 1], ], @@ -105,7 +105,8 @@ public function cprBasicInformation(string $cpr): array { /** * Validate cpr callback. * - * @param string $cpr - PSN (cpr) ([0-9]{6}\-[0-9]{4}) + * @param string $cpr + * PSN (cpr) ([0-9]{6}\-[0-9]{4}) * * @return array * [status] => TRUE/FALSE @@ -118,19 +119,16 @@ public function validateCpr(string $cpr): array { /** * Fetch address for the specified CPR. * - * @param string $cpr - * String - PSN (cpr) ([0-9]{6}\-[0-9]{4}) + * You should not use this function, but use lookup. * - * @return array - * [status] => TRUE/FALSE - * [address] => Roadname 10 - * [zipcode] => 1212 - * [error] => Descriptive text if something goes wrong - *@deprecated use lookup() instead. + * @param string $cpr + * String - PSN (cpr) ([0-9]{6}\-[0-9]{4}). * + * @return array + * Address information. */ public function getAddress(string $cpr): array { - \Drupal::logger('os2web_datalookup')->notice('Calling \'getAddress()\' directly is deprecated, use DataLookupInterfaceCpr::lookup() method.'); + \Drupal::logger('os2web_datalookup')->notice('Calling \'getAddress()\' directly is deprecated, use DataLookupCprInterface::lookup() method.'); $result = $this->cprBasicInformation($cpr); @@ -139,25 +137,24 @@ public function getAddress(string $cpr): array { return [ 'status' => $result['status'], 'cpr' => $cpr, - 'name' => isset($result['adresseringsnavn']) ? $result['adresseringsnavn'] : '', - 'road' => isset($result['vejadresseringsnavn']) ? $result['vejadresseringsnavn'] : '', + 'name' => $result['adresseringsnavn'] ?? '', + 'road' => $result['vejadresseringsnavn'] ?? '', 'road_no' => isset($result['husnummer']) ? ltrim($result['husnummer'], '0') : '', - 'floor' => isset($result['etage']) ? $result['etage'] : '', - 'door' => isset($result['sidedoer']) ? ltrim($result['sidedoer'], '0') : '', - 'zipcode' => isset($result['postnummer']) ? $result['postnummer'] : '', - 'city' => isset($result['postdistrikt']) ? $result['postdistrikt'] : '', - 'coname' => isset($result['conavn']) ? $result['conavn'] : '', - 'kommunekode' => isset($result['kommunekode']) ? $result['kommunekode'] : '', - 'name_address_protected' => isset($result['navneOgAdressebeskyttelse']) ? $result['navneOgAdressebeskyttelse'] : '', + 'floor' => $result['etage'] ?? '', + 'door' => isset($result['sidedoer']) ? ltrim($result['sidedoer'], '0') : '', + 'zipcode' => $result['postnummer'] ?? '', + 'city' => $result['postdistrikt'] ?? '', + 'coname' => $result['conavn'] ?? '', + 'kommunekode' => $result['kommunekode'] ?? '', + 'name_address_protected' => $result['navneOgAdressebeskyttelse'] ?? '', ]; } - else { - return $result; - } + + return $result; } /** - * @inheritDoc + * {@inheritDoc} */ public function lookup(string $cpr): CprLookupResult { $result = $this->cprBasicInformation($cpr); @@ -187,4 +184,5 @@ public function lookup(string $cpr): CprLookupResult { return $cprResult; } + } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php index cb94e3d..af73d22 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php @@ -2,8 +2,6 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; -use DateTime; -use DateTimeInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\Markup; @@ -18,7 +16,7 @@ * group = "cpr_lookup" * ) */ -class ServiceplatformenCPRExtended extends ServiceplatformenBase implements DataLookupInterfaceCpr { +class ServiceplatformenCPRExtended extends ServiceplatformenBase implements DataLookupCprInterface { /** * Status = DEAD. @@ -70,7 +68,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#default_value' => $this->configuration['test_mode_fixed_cpr'], '#description' => $this->t('Fixed CPR that will be used for all requests to the serviceplatformen instead of the provided CPR.'), '#states' => [ - // Hide the settings when the cancel notify checkbox is disabled. + // Show the element only when running in test mode. 'visible' => [ 'input[name="mode_selector"]' => ['value' => 1], ], @@ -150,7 +148,7 @@ public function lookup(string $cpr, $fetchChildren = TRUE, $allowCprTestModeRepl $cprResult->setCitizen(FALSE); } - $citizenshipDate = DateTime::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, $persondata->statsborgerskab->statsborgerskabDato->dato); + $citizenshipDate = \DateTime::createFromFormat(\DateTimeInterface::RFC3339_EXTENDED, $persondata->statsborgerskab->statsborgerskabDato->dato); $cprResult->setCitizenshipDate($citizenshipDate); } @@ -159,7 +157,7 @@ public function lookup(string $cpr, $fetchChildren = TRUE, $allowCprTestModeRepl } if ($persondata->foedselsdato) { - $birthDate = DateTime::createFromFormat("Y-m-dP", $persondata->foedselsdato->dato); + $birthDate = \DateTime::createFromFormat("Y-m-dP", $persondata->foedselsdato->dato); $cprResult->setBirthDate($birthDate); } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php index ec30650..b59e762 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCVR.php @@ -16,7 +16,7 @@ * group = "cvr_lookup" * ) */ -class ServiceplatformenCVR extends ServiceplatformenBase implements DataLookupInterfaceCompany { +class ServiceplatformenCVR extends ServiceplatformenBase implements DataLookupCompanyInterface { /** * {@inheritdoc} diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php index 1363dfc..3487d33 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenPNumber.php @@ -16,7 +16,7 @@ * group = "pnumber_lookup" * ) */ -class ServiceplatformenPNumber extends ServiceplatformenBase implements DataLookupInterfaceCompany { +class ServiceplatformenPNumber extends ServiceplatformenBase implements DataLookupCompanyInterface { /** * {@inheritdoc} diff --git a/src/Routing/DataLookupRoutes.php b/src/Routing/DataLookupRoutes.php index 046943e..929ce75 100644 --- a/src/Routing/DataLookupRoutes.php +++ b/src/Routing/DataLookupRoutes.php @@ -2,8 +2,9 @@ namespace Drupal\os2web_datalookup\Routing; -use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Component\Plugin\PluginManagerInterface; +use Drupal\Core\DependencyInjection\ContainerInjectionInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Routing\Route; @@ -12,12 +13,14 @@ */ class DataLookupRoutes implements ContainerInjectionInterface { + use StringTranslationTrait; + /** * The manager to be used for instantiating plugins. * * @var \Drupal\Component\Plugin\PluginManagerInterface */ - protected $manager; + protected PluginManagerInterface $manager; /** * Constructs a new AuthProvider route subscriber. @@ -32,7 +35,7 @@ public function __construct(PluginManagerInterface $manager) { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container) { + public static function create(ContainerInterface $container): static { return new static( $container->get('plugin.manager.os2web_datalookup') ); @@ -41,19 +44,20 @@ public static function create(ContainerInterface $container) { /** * Provides route definition for AuthProvider plugins settings form. * - * @return array + * @return array * Array with route definitions. */ - public function routes() { + public function routes(): array { $pluginDefinitions = $this->manager->getDefinitions(); $routes = []; $groups = []; foreach ($pluginDefinitions as $id => $plugin) { $routes["os2web_datalookup.$id"] = new Route( - "/admin/config/system/os2web-datalookup/" . str_replace('_', '-', $plugin['id']), [ + "/admin/config/system/os2web-datalookup/" . str_replace('_', '-', $plugin['id']), + [ '_form' => '\Drupal\os2web_datalookup\Form\DataLookupPluginSettingsForm', - '_title' => t("Configure :label", [':label' => $plugin['label']->__toString()])->__toString(), + '_title' => $this->t("Configure :label", [':label' => $plugin['label']->__toString()])->__toString(), '_plugin_id' => $id, ], [ @@ -68,11 +72,12 @@ public function routes() { // Creating routes for group configuration. foreach ($groups as $group) { $routes["os2web_datalookup.groups.$group"] = new Route( - "/admin/config/system/os2web-datalookup/" . str_replace('_', '-', $group), [ - '_form' => '\Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm', - '_title' => t("Configure group :label", [':label' => $group])->__toString(), - '_group_id' => $group, - ], + "/admin/config/system/os2web-datalookup/" . str_replace('_', '-', $group), + [ + '_form' => DataLookupPluginGroupSettingsForm::class, + '_title' => $this->t("Configure group :label", [':label' => $group])->__toString(), + '_group_id' => $group, + ], [ '_permission' => 'administer os2web datalookup configuration', ] From 711de2158897f135c0a4a219b9251debe3a0431c Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Tue, 14 May 2024 08:48:51 +0200 Subject: [PATCH 10/18] ITKDev: Removed not used phpstan --- composer.json | 12 +----------- phpstan.neon | 13 ------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index e6d46db..d0874ae 100644 --- a/composer.json +++ b/composer.json @@ -21,18 +21,9 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", - "mglaman/phpstan-drupal": "^1.1", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan-deprecation-rules": "^1.1", "phpunit/phpunit": "^9.5" }, "scripts": { - "code-analysis/phpstan": [ - "phpstan analyse" - ], - "code-analysis": [ - "@code-analysis/phpstan" - ], "coding-standards-check/phpcs": [ "phpcs --standard=phpcs.xml.dist" ], @@ -48,8 +39,7 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true, - "phpstan/extension-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 56bf890..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,13 +0,0 @@ -parameters: - level: 6 - paths: - - ./ - excludePaths: - # @see https://github.com/mglaman/drupal-check/issues/261#issuecomment-1030141772/ - - vendor - - '*/node_modules/*' - ignoreErrors: - # This is how drupal works.... - - '#\Drupal calls should be avoided in classes, use dependency injection instead#' - - '#The text '@deprecated use lookup\(\) instead.' does not match the standard format: @deprecated in %deprecation-version% and is#' - - '#Each @deprecated tag must have a @see tag immediately following it#' From 0f4896e3982293d1b0f11200452711d122f7d1c0 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 21 Aug 2024 10:05:09 +0200 Subject: [PATCH 11/18] ITKDev: Added messing ")" to CVR plugin --- src/Plugin/os2web/DataLookup/DatafordelerCVR.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php index 9ba23ef..9d98623 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerCVR.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerCVR.php @@ -97,7 +97,7 @@ public function lookup(string $param): CompanyLookupResult { $city = implode(' ', array_filter([ $address->CVRAdresse_postdistrikt ?? NULL, $cvrResult->getPostalCode() ?? NULL, - ]); + ])); $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); From 8d52bb8b8d1cd4beeee89aa849ccbe6f71388ddc Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Wed, 16 Oct 2024 13:43:28 +0200 Subject: [PATCH 12/18] ITKDev: Added audit module requirement to composer --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d0874ae..0ddf113 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "os2web/os2web_audit": "^0.0.2" }, "scripts": { "coding-standards-check/phpcs": [ From 591848029b6451e4ce03683176c313d326d28cba Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Fri, 18 Oct 2024 14:53:19 +0200 Subject: [PATCH 13/18] ITKDev: revert interface name --- composer.json | 2 +- ...CompanyInterface.php => DataLookupInterfaceCompany.php .php} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/Plugin/os2web/DataLookup/{DataLookupCompanyInterface.php => DataLookupInterfaceCompany.php .php} (100%) diff --git a/composer.json b/composer.json index 0ddf113..d2c0d2a 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", "phpunit/phpunit": "^9.5", - "os2web/os2web_audit": "^0.0.2" + "os2web/os2web_audit": "^0.0.3" }, "scripts": { "coding-standards-check/phpcs": [ diff --git a/src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php b/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php .php similarity index 100% rename from src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php rename to src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php .php From 5abb577a891106b80e0d237f1b151a098155b435 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 21 Oct 2024 12:49:13 +0200 Subject: [PATCH 14/18] Added dependencies to os2web_audit module --- composer.json | 3 ++- os2web_datalookup.info.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d0874ae..39d7ede 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,8 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "os2web/os2web_audit": "^0.1", }, "scripts": { "coding-standards-check/phpcs": [ diff --git a/os2web_datalookup.info.yml b/os2web_datalookup.info.yml index 3ee2322..5c5f684 100644 --- a/os2web_datalookup.info.yml +++ b/os2web_datalookup.info.yml @@ -3,3 +3,5 @@ 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' \ No newline at end of file From 876c756aec9d6bcad08aa24214547c6789e1a870 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Mon, 21 Oct 2024 12:51:36 +0200 Subject: [PATCH 15/18] ITKDev: fixed composer json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 39d7ede..aa34269 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "drupal/coder": "^8.3", "phpunit/phpunit": "^9.5", - "os2web/os2web_audit": "^0.1", + "os2web/os2web_audit": "^0.1" }, "scripts": { "coding-standards-check/phpcs": [ From 827099dd3962ffff1346b982fee172992128122b Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 28 Oct 2024 12:56:30 +0100 Subject: [PATCH 16/18] ITKDev: Minor fixes --- os2web_datalookup.info.yml | 2 +- ...Company.php .php => DataLookupCompanyInterface.php} | 0 src/Plugin/os2web/DataLookup/DatafordelerPNumber.php | 4 ++-- src/Plugin/os2web/DataLookup/ServiceplatformenBase.php | 10 ++++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) rename src/Plugin/os2web/DataLookup/{DataLookupInterfaceCompany.php .php => DataLookupCompanyInterface.php} (100%) diff --git a/os2web_datalookup.info.yml b/os2web_datalookup.info.yml index 5c5f684..c0abace 100644 --- a/os2web_datalookup.info.yml +++ b/os2web_datalookup.info.yml @@ -4,4 +4,4 @@ description: 'Provides integration with Danish data lookup services such as Serv package: 'OS2web' core_version_requirement: ^8 || ^9 || ^10 dependencies: - - 'os2web/os2web_audit' \ No newline at end of file + - 'os2web:os2web_audit' diff --git a/src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php .php b/src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php similarity index 100% rename from src/Plugin/os2web/DataLookup/DataLookupInterfaceCompany.php .php rename to src/Plugin/os2web/DataLookup/DataLookupCompanyInterface.php diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index 32eed44..14ac1ba 100644 --- a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php +++ b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php @@ -66,7 +66,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s */ public function lookup(string $param): CompanyLookupResult { try { - $msg = sprintf('Hent produktionsenhed med PNummer: ', $param); + $msg = sprintf('Hent produktionsenhed med PNummer: %s', $param); $this->auditLogger->info('DataLookup', $msg); $response = $this->httpClient->get('hentProduktionsenhedMedPNummer', ['query' => ['ppNummer' => $param]]); $result = json_decode((string) $response->getBody()); @@ -97,7 +97,7 @@ public function lookup(string $param): CompanyLookupResult { $city = implode(' ', array_filter([ $address->CVRAdresse_postdistrikt ?? NULL, $cvrResult->getPostalCode() ?? NULL, - ]); + ])); $cvrResult->setCity($city); $cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? ''); $address = $cvrResult->getStreet() . ' ' . $cvrResult->getHouseNr() . ' ' . $cvrResult->getFloor() . $cvrResult->getApartmentNr(); diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php index 80b7acc..ab95032 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenBase.php @@ -3,6 +3,7 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; use Drupal\Core\Form\FormStateInterface; +use Drupal\os2web_audit\Service\Logger; /** * Defines base plugin class for Serviceplatformen plugins. @@ -26,8 +27,13 @@ abstract class ServiceplatformenBase extends DataLookupBase { /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct( + array $configuration, + $plugin_id, + $plugin_definition, + Logger $auditLogger, + ) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $auditLogger); $this->init(); } From 5d19dd447db13d06ca4fe6f8cdb6df709fc53864 Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Mon, 28 Oct 2024 15:12:43 +0100 Subject: [PATCH 17/18] ITKDev: Update create method --- src/Plugin/os2web/DataLookup/DataLookupBase.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Plugin/os2web/DataLookup/DataLookupBase.php b/src/Plugin/os2web/DataLookup/DataLookupBase.php index 2087814..bd40653 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\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\os2web_audit\Service\Logger; @@ -46,6 +47,18 @@ public function __construct( $this->setConfiguration($configuration); } + /** + * {@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} */ From afa495f4ad1ab1308f89fae7a8a4e1c26aa162ce Mon Sep 17 00:00:00 2001 From: jekuaitk Date: Tue, 29 Oct 2024 10:09:22 +0100 Subject: [PATCH 18/18] ITKDev: Use ContainerFactoryPluginInterface --- src/Plugin/os2web/DataLookup/DataLookupBase.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Plugin/os2web/DataLookup/DataLookupBase.php b/src/Plugin/os2web/DataLookup/DataLookupBase.php index bd40653..4c8dc25 100644 --- a/src/Plugin/os2web/DataLookup/DataLookupBase.php +++ b/src/Plugin/os2web/DataLookup/DataLookupBase.php @@ -2,10 +2,11 @@ namespace Drupal\os2web_datalookup\Plugin\os2web\DataLookup; -use Drupal\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\os2web_audit\Service\Logger; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a base class for image effects. @@ -17,7 +18,7 @@ * @see \Drupal\image\ImageEffectManager * @see plugin_api */ -abstract class DataLookupBase extends PluginBase implements DataLookupInterface { +abstract class DataLookupBase extends PluginBase implements DataLookupInterface, ContainerFactoryPluginInterface { /** * Plugin readiness flag.