Skip to content

Commit 583b59b

Browse files
committed
Make number param required for address endpoint
1 parent 520732b commit 583b59b

6 files changed

Lines changed: 100 additions & 61 deletions

File tree

README.md

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ echo $address->coordinates->latitude; // 52.30703569036619
5656

5757
The address endpoint allows you to fetch address information from the Nederland Postcode API.
5858

59-
You can find addresses using either the `find` method for a single address or the `list` method for multiple addresses. When you provide only the `postcode`, the `list` method will return all addresses associated with that postcode.
59+
You can search addresses using either the `find` method for a single address or the `list` method for multiple addresses. The `find` method will throw an exception if no address is found or if multiple addresses are found for the given postcode and house number (ie. when the house number has multiple additions like A, B, C, etc.).
6060

6161
The following optional attributes can be requested to be included in the response:
6262

@@ -66,7 +66,7 @@ The following optional attributes can be requested to be included in the respons
6666

6767
To fetch a single address for a given postcode and house number, you can use the `find` method.
6868

69-
The `postcode` and `number` parameters are required to fetch a single address.
69+
The `postcode` and `number` parameters are required. The `addition` parameter is optional.
7070

7171
```php
7272
use Label84\NederlandPostcode\NederlandPostcodeClient;
@@ -89,6 +89,7 @@ This will return an `Address` object like this:
8989
Address {
9090
postcode: "1118BN",
9191
number: 800,
92+
addition: null,
9293
street: "Schiphol Boulevard",
9394
city: "Schiphol",
9495
municipality: "Haarlemmermeer",
@@ -104,9 +105,9 @@ When no address is found for the given postcode and number, an `AddressNotFoundE
104105

105106
#### Multiple Addresses
106107

107-
To fetch multiple addresses for a given postcode, you can use the `list` method.
108+
To fetch multiple addresses for a given postcode and house number, you can use the `list` method.
108109

109-
The `postcode` parameter is required. The `number` and `addition` parameters are optional.
110+
The `postcode` and `number` parameters are required. The `addition` parameter is optional.
110111

111112
```php
112113
use Label84\NederlandPostcode\NederlandPostcodeClient;
@@ -116,8 +117,8 @@ $client = new NederlandPostcodeClient(
116117
);
117118

118119
$address = $client->list(
119-
postcode: '1118BN',
120-
number: null,
120+
postcode: '1015CN',
121+
number: 10,
121122
addition: null,
122123
attributes: ['coordinates']
123124
);
@@ -129,29 +130,57 @@ This will return an `AddressCollection` object like this:
129130
AddressCollection {
130131
items: [
131132
Address {
132-
postcode: "1118BN",
133-
number: 701,
134-
street: "Schiphol Boulevard",
135-
city: "Schiphol",
136-
municipality: "Haarlemmermeer",
133+
postcode: "1015CN",
134+
number: 10,
135+
addition: 'A',
136+
street: "Keizersgracht",
137+
city: "Amsterdam",
138+
municipality: "Amsterdam",
139+
province: "Noord-Holland",
140+
coordinates: Coordinates {
141+
latitude: 52.379401496779124,
142+
longitude: 4.889216673725493
143+
}
144+
},
145+
Address {
146+
postcode: "1015CN",
147+
number: 10,
148+
addition: 'B',
149+
street: "Keizersgracht",
150+
city: "Amsterdam",
151+
municipality: "Amsterdam",
152+
province: "Noord-Holland",
153+
coordinates: Coordinates {
154+
latitude: 52.379401496779124,
155+
longitude: 4.889216673725493
156+
}
157+
},
158+
Address {
159+
postcode: "1015CN",
160+
number: 10,
161+
addition: 'C',
162+
street: "Keizersgracht",
163+
city: "Amsterdam",
164+
municipality: "Amsterdam",
137165
province: "Noord-Holland",
138166
coordinates: Coordinates {
139-
latitude: 52.30703569036619,
140-
longitude: 4.755174782205992
167+
latitude: 52.379401496779124,
168+
longitude: 4.889216673725493
141169
}
142170
},
143171
Address {
144-
postcode: "1118BN",
145-
number: 800,
146-
street: "Schiphol Boulevard",
147-
city: "Schiphol",
148-
municipality: "Haarlemmermeer",
172+
postcode: "1015CN",
173+
number: 10,
174+
addition: 'D',
175+
street: "Keizersgracht",
176+
city: "Amsterdam",
177+
municipality: "Amsterdam",
149178
province: "Noord-Holland",
150179
coordinates: Coordinates {
151-
latitude: 52.30528553688755,
152-
longitude: 4.750645160863609
180+
latitude: 52.379401496779124,
181+
longitude: 4.889216673725493
153182
}
154-
}
183+
},
155184
]
156185
}
157186
```
@@ -161,7 +190,7 @@ AddressCollection {
161190
The quota endpoint allows you to check your current API usage and limits. This endpoint does not increment your usage count.
162191

163192
> [!NOTE]
164-
> Values may lag behind the actual usage. Theyre cached for up to five minutes, so the `used` and `limit` numbers might not be fully up-to-date.
193+
> Values may lag behind the actual usage. They're cached for up to five minutes, so the `used` and `limit` numbers might not be fully up-to-date.
165194
166195
```php
167196
use Label84\NederlandPostcode\NederlandPostcodeClient;
@@ -214,10 +243,6 @@ When a network or HTTP error occurs during the API request, a `NederlandPostcode
214243
./vendor/bin/phpstan analyse
215244
```
216245

217-
```bash
218-
./vendor/bin/pint
219-
```
220-
221246
```bash
222247
./vendor/bin/phpunit
223248
```

src/NederlandPostcodeClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function quota(): QuotaResource
7373
* @param array<int|string, string|AddressAttributesEnum> $attributes
7474
* @return AddressCollection<Address>
7575
*/
76-
public function list(string $postcode, ?int $number = null, ?string $addition = null, array $attributes = []): AddressCollection
76+
public function list(string $postcode, int $number, ?string $addition = null, array $attributes = []): AddressCollection
7777
{
7878
return $this->addresses()->get(
7979
postcode: $postcode,

src/Resources/AddressesResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AddressesResource extends BaseResource
1313
*/
1414
public function get(
1515
string $postcode,
16-
?int $number,
16+
int $number,
1717
?string $addition,
1818
array $attributes = [],
1919
): AddressCollection {

tests/NederlandPostcodeClientTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public function test_find_throws_multiple_addresses_found_exception(): void
4040

4141
$this->client
4242
->find(
43-
postcode: '1118BN',
44-
number: 0,
43+
postcode: '1015CN',
44+
number: 10,
4545
addition: null,
4646
);
4747
}
@@ -50,13 +50,13 @@ public function test_list(): void
5050
{
5151
$result = $this->client
5252
->list(
53-
postcode: '1118BN',
54-
number: null,
53+
postcode: '1015CN',
54+
number: 10,
5555
addition: null,
5656
);
5757

5858
$this->assertInstanceOf(AddressCollection::class, $result);
59-
$this->assertCount(3, $result);
59+
$this->assertCount(4, $result);
6060
}
6161

6262
public function test_usage(): void

tests/Resources/AddressResourceTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public function test_get_multiple_results(): void
2626
$result = $this->client
2727
->addresses()
2828
->get(
29-
postcode: '1118BN',
30-
number: null,
29+
postcode: '1015CN',
30+
number: 10,
3131
addition: null,
3232
);
3333

3434
$this->assertInstanceOf(AddressCollection::class, $result);
35-
$this->assertCount(3, $result);
35+
$this->assertCount(4, $result);
3636
}
3737
}

tests/TestCase.php

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function mockNederlandPostcodeClient(): void
3131
->willReturnCallback(function (string $postcode, ?int $number, ?array $addition, $attributes = []) {
3232
return match (true) {
3333
$postcode === '1118BN' && $number === 800 => $this->singleAddressResponse(),
34-
$postcode === '1118BN' && ($number === null || $number === 0) => $this->multipleAddressesResponse(),
34+
$postcode === '1015CN' && $number === 10 => $this->multipleAddressesResponse(),
3535
default => new AddressCollection([]),
3636
};
3737
});
@@ -85,45 +85,59 @@ private function multipleAddressesResponse(): AddressCollection
8585
{
8686
return new AddressCollection([
8787
new Address(
88-
postcode: '1118BN',
89-
number: 701,
90-
addition: '',
91-
street: 'Schiphol Boulevard',
92-
city: 'Schiphol',
93-
municipality: 'Haarlemmermeer',
88+
postcode: '1015CN',
89+
number: 10,
90+
addition: 'A',
91+
street: 'Keizersgracht',
92+
city: 'Amsterdam',
93+
municipality: 'Amsterdam',
9494
province: 'Noord-Holland',
9595
country: 'Nederland',
9696
coordinates: new Coordinates(
97-
latitude: 52.30703569036619,
98-
longitude: 4.755174782205992,
97+
latitude: 52.379401496779124,
98+
longitude: 4.889216673725493,
9999
),
100100
),
101101
new Address(
102-
postcode: '1118BN',
103-
number: 800,
104-
addition: '',
105-
street: 'Schiphol Boulevard',
106-
city: 'Schiphol',
107-
municipality: 'Haarlemmermeer',
102+
postcode: '1015CN',
103+
number: 10,
104+
addition: 'B',
105+
street: 'Keizersgracht',
106+
city: 'Amsterdam',
107+
municipality: 'Amsterdam',
108108
province: 'Noord-Holland',
109109
country: 'Nederland',
110110
coordinates: new Coordinates(
111-
latitude: 52.30528553688755,
112-
longitude: 4.750645160863609,
111+
latitude: 52.379401496779124,
112+
longitude: 4.889216673725493,
113113
),
114114
),
115115
new Address(
116-
postcode: '1118BN',
117-
number: 810,
118-
addition: '',
119-
street: 'Schiphol Boulevard',
120-
city: 'Schiphol',
121-
municipality: 'Haarlemmermeer',
116+
postcode: '1015CN',
117+
number: 10,
118+
addition: 'C',
119+
street: 'Keizersgracht',
120+
city: 'Amsterdam',
121+
municipality: 'Amsterdam',
122+
province: 'Noord-Holland',
123+
country: 'Nederland',
124+
coordinates: new Coordinates(
125+
latitude: 52.379401496779124,
126+
longitude: 4.889216673725493,
127+
),
128+
),
129+
new Address(
130+
postcode: '1015CN',
131+
number: 10,
132+
addition: 'D',
133+
street: 'Keizersgracht',
134+
city: 'Amsterdam',
135+
municipality: 'Amsterdam',
122136
province: 'Noord-Holland',
123137
country: 'Nederland',
124138
coordinates: new Coordinates(
125-
latitude: 52.30556719835437,
126-
longitude: 4.750419372039126,
139+
latitude: 52.379401496779124,
140+
longitude: 4.889216673725493,
127141
),
128142
),
129143
]);

0 commit comments

Comments
 (0)