Skip to content

Commit 44a2a6d

Browse files
authored
OS-245 adding P-number lookup (#33)
1 parent 4e06444 commit 44a2a6d

4 files changed

Lines changed: 185 additions & 77 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
* Adding Datafordeler P-number lookup
11+
1012
## [3.2.0] - 2026-05-29
1113

1214
* [PR-32](https://github.com/OS2web/os2web_datalookup/pull/32)

src/LookupResult/CompanyLookupResult.php

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,70 +37,70 @@ class CompanyLookupResult {
3737
*
3838
* @var string
3939
*/
40-
protected string $cvr;
40+
protected string $cvr = '';
41+
42+
/**
43+
* The P-Number number.
44+
*
45+
* @var string
46+
*/
47+
protected string $pNumber = '';
4148

4249
/**
4350
* Company name.
4451
*
4552
* @var string
4653
*/
47-
protected string $name;
54+
protected string $name = '';
4855

4956
/**
5057
* Street of the person.
5158
*
5259
* @var string
5360
*/
54-
protected string $street;
61+
protected string $street = '';
5562

5663
/**
5764
* Street house number of the person.
5865
*
5966
* @var string
6067
*/
61-
protected string $houseNr;
68+
protected string $houseNr = '';
6269

6370
/**
6471
* Floor number of the person.
6572
*
6673
* @var string
6774
*/
68-
protected string $floor;
75+
protected string $floor = '';
6976

7077
/**
7178
* Apartment number of the person.
7279
*
7380
* @var string
7481
*/
75-
protected string $apartmentNr;
82+
protected string $apartmentNr = '';
7683

7784
/**
7885
* Postal code of the person.
7986
*
8087
* @var string
8188
*/
82-
protected string $postalCode;
89+
protected string $postalCode = '';
8390

8491
/**
8592
* City of the person.
8693
*
8794
* @var string
8895
*/
89-
protected string $city;
96+
protected string $city = '';
9097

9198
/**
9299
* Municipality code of the person.
93100
*
94101
* @var string
95102
*/
96-
protected string $municipalityCode;
97-
98-
/**
99-
* Address of the person.
100-
*
101-
* @var string
102-
*/
103-
protected string $address;
103+
protected string $municipalityCode = '';
104104

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

165+
/**
166+
* Get P-Number number.
167+
*
168+
* @return string
169+
* P-Number.
170+
*/
171+
public function getPnumber(): string {
172+
return $this->pNumber;
173+
}
174+
175+
/**
176+
* Set P-Number number.
177+
*
178+
* @param string $pNumber
179+
* P-Number.
180+
*/
181+
public function setPnumber(string $pNumber): void {
182+
$this->pNumber = $pNumber;
183+
}
184+
165185
/**
166186
* Get name.
167187
*
@@ -329,17 +349,21 @@ public function setMunicipalityCode(string $municipalityCode): void {
329349
* The address.
330350
*/
331351
public function getAddress(): string {
332-
return $this->address;
333-
}
352+
$address = $this->getStreet();
353+
if ($this->getHouseNr()) {
354+
$address .= ' ' . $this->getHouseNr();
355+
}
356+
if ($this->getFloor()) {
357+
$address .= ' ' . $this->getFloor();
358+
}
359+
if ($this->getApartmentNr()) {
360+
$address .= ' ' . $this->getApartmentNr();
361+
}
362+
if ($this->getPostalCode() && $this->getCity()) {
363+
$address .= ', ' . $this->getPostalCode() . ' ' . $this->getCity();
364+
}
334365

335-
/**
336-
* Set address.
337-
*
338-
* @param string $address
339-
* The address to set.
340-
*/
341-
public function setAddress(string $address): void {
342-
$this->address = $address;
366+
return $address;
343367
}
344368

345369
/**
@@ -352,6 +376,14 @@ public function setAddress(string $address): void {
352376
* The field value or the empty string if the field does not exist.
353377
*/
354378
public function getFieldValue(string $field): mixed {
379+
$calculatedFields = [
380+
$this::ADDRESS => fn() => $this->getAddress(),
381+
];
382+
383+
if (isset($calculatedFields[$field])) {
384+
return $calculatedFields[$field]();
385+
}
386+
355387
if (property_exists($this, $field) && isset($this->{$field})) {
356388
return $this->{$field};
357389
}

src/Plugin/os2web/DataLookup/DatafordelerCVR.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,6 @@ public function lookup(string $param): CompanyLookupResult {
127127
$city = $address->CVRAdresse_postdistrikt ?? $cvrResult->getPostalCode();
128128
$cvrResult->setCity($city);
129129
$cvrResult->setMunicipalityCode($address->CVRAdresse_kommunekode ?? '');
130-
131-
// Composing full address in one line.
132-
$address = $cvrResult->getStreet();
133-
if ($cvrResult->getHouseNr()) {
134-
$address .= ' ' . $cvrResult->getHouseNr();
135-
}
136-
if ($cvrResult->getFloor()) {
137-
$address .= ' ' . $cvrResult->getFloor();
138-
}
139-
if ($cvrResult->getApartmentNr()) {
140-
$address .= ' ' . $cvrResult->getApartmentNr();
141-
}
142-
if ($cvrResult->getPostalCode() && $cvrResult->getCity()) {
143-
$address .= ', ' . $cvrResult->getPostalCode() . ' ' . $cvrResult->getCity();
144-
}
145-
146-
$cvrResult->setAddress($address);
147130
}
148131
}
149132
else {

0 commit comments

Comments
 (0)