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/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/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..47be3d8 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..ae1446b 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 hous 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 d553f68..91703cc 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. @@ -164,196 +167,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; @@ -370,7 +457,7 @@ public function setNameAddressProtected(bool $nameAddressProtected): void { * 'name' => full name, * ], * ... - * ] + * ]. */ public function getChildren(): array { return $this->children; @@ -388,7 +475,7 @@ public function getChildren(): array { * 'nameAddressProtected' => TRUE/FALSE * ], * ... - * ] + * ]. */ public function setChildren(array $children): void { $this->children = $children; @@ -406,7 +493,7 @@ public function setChildren(array $children): void { * 'nameAddressProtected' => TRUE/FALSE * ], * ... - * ] + * ]. */ public function getGuardians(): array { return $this->guardians; @@ -423,77 +510,107 @@ 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 is 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 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; @@ -502,13 +619,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 a 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; @@ -521,12 +638,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..128b067 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; @@ -89,14 +89,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 +126,15 @@ 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 { $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..3b597d3 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} diff --git a/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php b/src/Plugin/os2web/DataLookup/DatafordelerPNumber.php index cf67257..efecd5d 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} diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterface.php similarity index 81% rename from src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php rename to src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterface.php index b0d9e61..4112741 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPR.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterface.php @@ -8,7 +8,7 @@ use Drupal\os2web_datalookup\LookupResult\CprLookupResult; /** - * Defines a plugin for ServiceplatformenCPR. + * Defines a plugin for ServiceplatformenCPRInterface. * * @DataLookup( * id = "serviceplatformen_cpr", @@ -16,7 +16,7 @@ * group = "cpr_lookup" * ) */ -class ServiceplatformenCPR extends ServiceplatformenBase implements DataLookupInterfaceCpr { +class ServiceplatformenCPRInterface 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. + // Hide the settings when the "cancel notifies" checkbox is disabled. '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 @@ -119,18 +120,18 @@ public function validateCpr(string $cpr): array { * Fetch address for the specified CPR. * * @param string $cpr - * String - PSN (cpr) ([0-9]{6}\-[0-9]{4}) + * String - PSN (cpr) ([0-9]{6}\-[0-9]{4}) * - * @return array + * @return array * [status] => TRUE/FALSE * [address] => Roadname 10 * [zipcode] => 1212 * [error] => Descriptive text if something goes wrong - *@deprecated use lookup() instead. * + * @deprecated use lookup() instead. */ 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 +140,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 +187,5 @@ public function lookup(string $cpr): CprLookupResult { return $cprResult; } + } diff --git a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterfaceExtended.php similarity index 94% rename from src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php rename to src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterfaceExtended.php index bc38d48..639ee59 100644 --- a/src/Plugin/os2web/DataLookup/ServiceplatformenCPRExtended.php +++ b/src/Plugin/os2web/DataLookup/ServiceplatformenCPRInterfaceExtended.php @@ -2,15 +2,13 @@ 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; use Drupal\os2web_datalookup\LookupResult\CprLookupResult; /** - * Defines a plugin for ServiceplatformenCPRExtended. + * Defines a plugin for ServiceplatformenCPRInterfaceExtended. * * @DataLookup( * id = "serviceplatformen_cpr_extended", @@ -18,7 +16,7 @@ * group = "cpr_lookup" * ) */ -class ServiceplatformenCPRExtended extends ServiceplatformenBase implements DataLookupInterfaceCpr { +class ServiceplatformenCPRInterfaceExtended 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. + // Hide the settings when the cancel notifies checkbox is disabled. 'visible' => [ 'input[name="mode_selector"]' => ['value' => 1], ], @@ -148,7 +146,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); } @@ -157,7 +155,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..4e168e2 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' => '\Drupal\os2web_datalookup\Form\DataLookupPluginGroupSettingsForm', + '_title' => $this->t("Configure group :label", [':label' => $group])->__toString(), + '_group_id' => $group, + ], [ '_permission' => 'administer os2web datalookup configuration', ]