Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Adding Datafordeler P-number lookup

## [3.2.0] - 2026-05-29

* [PR-32](https://github.com/OS2web/os2web_datalookup/pull/32)
Expand Down
84 changes: 58 additions & 26 deletions src/LookupResult/CompanyLookupResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,70 +37,70 @@ class CompanyLookupResult {
*
* @var string
*/
protected string $cvr;
protected string $cvr = '';

/**
* The P-Number number.
*
* @var string
*/
protected string $pNumber = '';

/**
* Company name.
*
* @var string
*/
protected string $name;
protected string $name = '';

/**
* Street of the person.
*
* @var string
*/
protected string $street;
protected string $street = '';

/**
* Street house number of the person.
*
* @var string
*/
protected string $houseNr;
protected string $houseNr = '';

/**
* Floor number of the person.
*
* @var string
*/
protected string $floor;
protected string $floor = '';

/**
* Apartment number of the person.
*
* @var string
*/
protected string $apartmentNr;
protected string $apartmentNr = '';

/**
* Postal code of the person.
*
* @var string
*/
protected string $postalCode;
protected string $postalCode = '';

/**
* City of the person.
*
* @var string
*/
protected string $city;
protected string $city = '';

/**
* Municipality code of the person.
*
* @var string
*/
protected string $municipalityCode;

/**
* Address of the person.
*
* @var string
*/
protected string $address;
protected string $municipalityCode = '';

/**
* Check the state of successful.
Expand Down Expand Up @@ -162,6 +162,26 @@ public function setCvr(string $cpr): void {
$this->cvr = $cpr;
}

/**
* Get P-Number number.
*
* @return string
* P-Number.
*/
public function getPnumber(): string {
return $this->pNumber;
}

/**
* Set P-Number number.
*
* @param string $pNumber
* P-Number.
*/
public function setPnumber(string $pNumber): void {
$this->pNumber = $pNumber;
}

/**
* Get name.
*
Expand Down Expand Up @@ -329,17 +349,21 @@ public function setMunicipalityCode(string $municipalityCode): void {
* The address.
*/
public function getAddress(): string {
return $this->address;
}
$address = $this->getStreet();
if ($this->getHouseNr()) {
$address .= ' ' . $this->getHouseNr();
}
if ($this->getFloor()) {
$address .= ' ' . $this->getFloor();
}
if ($this->getApartmentNr()) {
$address .= ' ' . $this->getApartmentNr();
}
if ($this->getPostalCode() && $this->getCity()) {
$address .= ', ' . $this->getPostalCode() . ' ' . $this->getCity();
}

/**
* Set address.
*
* @param string $address
* The address to set.
*/
public function setAddress(string $address): void {
$this->address = $address;
return $address;
}

/**
Expand All @@ -352,6 +376,14 @@ public function setAddress(string $address): void {
* The field value or the empty string if the field does not exist.
*/
public function getFieldValue(string $field): mixed {
$calculatedFields = [
$this::ADDRESS => fn() => $this->getAddress(),
];

if (isset($calculatedFields[$field])) {
return $calculatedFields[$field]();
}

if (property_exists($this, $field) && isset($this->{$field})) {
return $this->{$field};
}
Expand Down
17 changes: 0 additions & 17 deletions src/Plugin/os2web/DataLookup/DatafordelerCVR.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,6 @@ public function lookup(string $param): CompanyLookupResult {
$city = $address->CVRAdresse_postdistrikt ?? $cvrResult->getPostalCode();
$cvrResult->setCity($city);
$cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? '');

// Composing full address in one line.
$address = $cvrResult->getStreet();
if ($cvrResult->getHouseNr()) {
$address .= ' ' . $cvrResult->getHouseNr();
}
if ($cvrResult->getFloor()) {
$address .= ' ' . $cvrResult->getFloor();
}
if ($cvrResult->getApartmentNr()) {
$address .= ' ' . $cvrResult->getApartmentNr();
}
if ($cvrResult->getPostalCode() && $cvrResult->getCity()) {
$address .= ', ' . $cvrResult->getPostalCode() . ' ' . $cvrResult->getCity();
}

$cvrResult->setAddress($address);
}
}
else {
Expand Down
Loading
Loading