From 5d18c4e16a57d4107debce9714918ef848073bef Mon Sep 17 00:00:00 2001 From: Stanislav Kutasevits Date: Fri, 21 Jun 2024 15:38:09 +0300 Subject: [PATCH] phpcs fixes --- .../Element/DawaElementAddressMatrikula.php | 5 +- .../src/Entity/DatafordelerMatrikula.php | 27 +++++++-- .../DataLookup/DatafordelerDataLookup.php | 60 +++---------------- .../DatafordelerDataLookupInterface.php | 5 +- .../os2forms_dawa/src/Service/DawaService.php | 2 +- 5 files changed, 36 insertions(+), 63 deletions(-) diff --git a/modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php b/modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php index 12cb99f..2e75805 100644 --- a/modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php +++ b/modules/os2forms_dawa/src/Element/DawaElementAddressMatrikula.php @@ -3,7 +3,6 @@ namespace Drupal\os2forms_dawa\Element; use Drupal\Core\Form\FormStateInterface; -use Drupal\os2forms_dawa\Plugin\os2web\DataLookup\DatafordelerDataLookupInterface; use Drupal\webform\Element\WebformCompositeBase; use Symfony\Component\HttpFoundation\ParameterBag; @@ -100,9 +99,7 @@ private static function getMatrikulaOptions($addressValue, array $element) { /** @var \Drupal\os2forms_dawa\Service\DawaService $dawaService */ $dawaService = \Drupal::service('os2forms_dawa.service'); - /** @var \Drupal\os2forms_dawa\Service\DatafordelerService $datafordelerService */ - - /** @var DatafordelerDataLookupInterface $datafordelerLookup */ + /** @var \Drupal\os2forms_dawa\Plugin\os2web\DataLookup\DatafordelerDataLookupInterface $datafordelerLookup */ $datafordelerLookup = \Drupal::service('plugin.manager.os2web_datalookup')->createInstance('datafordeler_data_lookup'); // Getting address. diff --git a/modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php b/modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php index 96ab322..0e05a27 100644 --- a/modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php +++ b/modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php @@ -5,19 +5,21 @@ /** * Class DatafordelerMatrikula. * - * Wrapper class for Datafordeler matrikula object that easies the matrikula property - * access. + * Wrapper class for Datafordeler matrikula object that easies + * the matrikula property access. */ class DatafordelerMatrikula { /** * Owner licence code / ejerlavskode. + * * @var string */ protected string $ownerLicenseCode; /** * Ownership name / ejerlavsnavn. + * * @var string */ protected string $ownershipName; @@ -25,6 +27,7 @@ class DatafordelerMatrikula { /** * Matrikula number / matrikelnummer. + * * @var string */ protected string $matrikulaNumber; @@ -47,18 +50,34 @@ public function __construct(array $json) { } } + /** + * Returns owner licence code. + * + * @return string + * Owners licence code. + */ public function getOwnerLicenseCode(): string { return $this->ownerLicenseCode; } + /** + * Returns ownership name. + * + * @return string + * ownership name. + */ public function getOwnershipName(): string { return $this->ownershipName; } + /** + * Returns makrikula number. + * + * @return string + * Matrikula number + */ public function getMatrikulaNumber(): string { return $this->matrikulaNumber; } - - } diff --git a/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php b/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php index 4a5ef8d..a702e2d 100644 --- a/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php +++ b/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookup.php @@ -8,7 +8,6 @@ use Drupal\os2web_datalookup\Plugin\os2web\DataLookup\DataLookupBase; use GuzzleHttp\ClientInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpClient\HttpClient; /** * Defines a plugin for Datafordeler Data. @@ -23,7 +22,7 @@ class DatafordelerDataLookup extends DataLookupBase implements DatafordelerDataL /** * The HTTP client to fetch the feed data with. * - * @var ClientInterface + * @var \GuzzleHttp\ClientInterface */ protected $httpClient; @@ -43,7 +42,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, - $container->get('http_client') + $container->get('http_client'), ); } @@ -51,7 +50,7 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function getMatrikulaIds(string $addressAccessId) : array { - $url = "https://services.datafordeler.dk/BBR/BBRPublic/1/rest/grund";// + $url = "https://services.datafordeler.dk/BBR/BBRPublic/1/rest/grund"; $configuration = $this->getConfiguration(); $json = $this->httpClient->request('GET', $url, [ @@ -59,8 +58,8 @@ public function getMatrikulaIds(string $addressAccessId) : array { 'husnummer' => $addressAccessId, 'status' => 7, 'username' => $configuration['username'], - 'password' => $configuration['password'] - ] + 'password' => $configuration['password'], + ], ])->getBody(); $jsonDecoded = json_decode($json, TRUE); @@ -82,8 +81,8 @@ public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula 'query' => [ 'jordstykkeid' => $matrikulaId, 'username' => $configuration['username'], - 'password' => $configuration['password'] - ] + 'password' => $configuration['password'], + ], ])->getBody(); $jsonDecoded = json_decode($json, TRUE); @@ -126,50 +125,6 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta return $form; } - /** - * {@inheritdoc} - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - parent::validateConfigurationForm($form, $form_state); - -// // Validating 'address_autocomplete_path', 'block_autocomplete_path', -// // 'matrikula_autocomplete_path'. -// $elementsToValidate = [ -// 'address_autocomplete_path', -// 'block_autocomplete_path', -// 'matrikula_autocomplete_path', -// ]; -// foreach ($elementsToValidate as $elementKey) { -// $autocomplete_path = $form_state->getValue($elementKey); -// $json = file_get_contents($autocomplete_path); -// $jsonDecoded = json_decode($json, TRUE); -// if (empty($jsonDecoded)) { -// $form_state->setErrorByName($elementKey, $this->t('URL is not valid or it does not provide the result in the required format')); -// } -// else { -// $entry = reset($jsonDecoded); -// if (!array_key_exists('tekst', $entry)) { -// $form_state->setErrorByName($elementKey, $this->t('URL is not valid or it does not provide the result in the required format')); -// } -// } -// } -// -// // Validating address_api_path. -// $autocomplete_path = $form_state->getValue('address_api_path'); -// // Limiting the output. -// $json = file_get_contents($autocomplete_path . '?per_side=1'); -// $jsonDecoded = json_decode($json, TRUE); -// if (empty($jsonDecoded)) { -// $form_state->setErrorByName('address_api_path', $this->t('URL is not valid or it does not provide the result in the required format')); -// } -// else { -// $entry = reset($jsonDecoded); -// if (!array_key_exists('id', $entry)) { -// $form_state->setErrorByName('address_api_path', $this->t('URL is not valid or it does not provide the result in the required format')); -// } -// } - } - /** * {@inheritdoc} */ @@ -179,4 +134,5 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $configuration['password'] = $form_state->getValue('password'); $this->setConfiguration($configuration); } + } diff --git a/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookupInterface.php b/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookupInterface.php index fb24a71..4dd71a3 100644 --- a/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookupInterface.php +++ b/modules/os2forms_dawa/src/Plugin/os2web/DataLookup/DatafordelerDataLookupInterface.php @@ -15,7 +15,7 @@ interface DatafordelerDataLookupInterface extends DataLookupInterface { /** - * Returns list of ID for Matrikula / jordstykke that is related with this address. + * Returns list of ID for Matrikula / jordstykke related with this address. * * @param string $addressAccessId * Address to make search against. @@ -31,8 +31,9 @@ public function getMatrikulaIds(string $addressAccessId) : array; * @param string $matrikulaId * Id to make search against. * - * @return DatafordelerMatrikula|NULL + * @return \Drupal\os2forms_dawa\Entity\DatafordelerMatrikula|null * Matrikula entry or NULL. */ public function getMatrikulaEntry(string $matrikulaId) : ?DatafordelerMatrikula; + } diff --git a/modules/os2forms_dawa/src/Service/DawaService.php b/modules/os2forms_dawa/src/Service/DawaService.php index 1c68fa7..671edcb 100644 --- a/modules/os2forms_dawa/src/Service/DawaService.php +++ b/modules/os2forms_dawa/src/Service/DawaService.php @@ -7,7 +7,7 @@ use Symfony\Component\HttpFoundation\ParameterBag; /** - * Class DawaService. + * DAWA API service class. * * @package Drupal\os2forms_dawa\Service */