Skip to content

Commit

Permalink
phpcs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut committed Jun 21, 2024
1 parent 83d72a4 commit 5d18c4e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down
27 changes: 23 additions & 4 deletions modules/os2forms_dawa/src/Entity/DatafordelerMatrikula.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
/**
* 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;


/**
* Matrikula number / matrikelnummer.
*
* @var string
*/
protected string $matrikulaNumber;
Expand All @@ -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;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -43,24 +42,24 @@ public static function create(ContainerInterface $container, array $configuratio
$configuration,
$plugin_id,
$plugin_definition,
$container->get('http_client')
$container->get('http_client'),
);
}

/**
* {@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, [
'query' => [
'husnummer' => $addressAccessId,
'status' => 7,
'username' => $configuration['username'],
'password' => $configuration['password']
]
'password' => $configuration['password'],
],
])->getBody();

$jsonDecoded = json_decode($json, TRUE);
Expand All @@ -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);
Expand Down Expand Up @@ -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}
*/
Expand All @@ -179,4 +134,5 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
$configuration['password'] = $form_state->getValue('password');
$this->setConfiguration($configuration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

}
2 changes: 1 addition & 1 deletion modules/os2forms_dawa/src/Service/DawaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\HttpFoundation\ParameterBag;

/**
* Class DawaService.
* DAWA API service class.
*
* @package Drupal\os2forms_dawa\Service
*/
Expand Down

0 comments on commit 5d18c4e

Please sign in to comment.