Skip to content

Commit

Permalink
fix(split-street): get actual matches from belgium split street regex (
Browse files Browse the repository at this point in the history
…#494)

* fix(split-street): get actual matches from belgium split street regex

* fix: get actual matches

* style: spaces

* refactor: remove commented debug statement

* fix: implement klappoel 1 bus 5 b address

* fix: prevent getstreet - setstreet error message
  • Loading branch information
joerivanveen authored Aug 2, 2024
1 parent bf99b13 commit 0bc97fd
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Helper/SplitStreet.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static function splitStreet(string $fullStreet, string $local, string $de
$fullStreet = implode(
' ',
array_filter([
$matches['street'],
$matches['street'] ?? $fullStreet,
$matches['number'],
$matches['box_separator'],
$matches['box_number'],
Expand All @@ -123,7 +123,7 @@ public static function splitStreet(string $fullStreet, string $local, string $de

return new FullStreet(
$matches['street'] ?? $fullStreet,
(int) $matches['number'] ?? null,
(int) $matches['number'] ?: null,
$matches['number_suffix'] ?? null,
$matches['box_number'] ?? null
);
Expand Down
3 changes: 1 addition & 2 deletions src/Helper/ValidateStreet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class ValidateStreet
')?$~i';

const SPLIT_STREET_REGEX_BE =
'~(?P<street>.*?)\s(?P<street_suffix>(?P<number>[0-9\-]{1,8})\s?(?P<box_separator>' . self::REGEX_BE_BOX_SEPARATORS . ')?\s?(?P<box_number>\d{0,8})\s?(?P<number_suffix>[A-z]{0,4}$)?)$~';

'~(?P<box_number>)(?P<street>.*?)\s(?P<street_suffix>(?P<number>[0-9\-]{0,7}[0-9])(?P<number_suffix>[A-z]{0,4})\s?(?P<box_separator>' . self::REGEX_BE_BOX_SEPARATORS . '|\,\s+)*\s?(?P<box_number>[0-9A-z]{0,7}[0-9])?\s?(?:(?P<number_suffix>[A-z]{1,4}$)|))?$~J';
const REGEX_BE_BOX_SEPARATORS = SplitStreet::BOX_BTE . '|' . SplitStreet::BOX_EN . '|' . SplitStreet::BOX_FR . '|' . SplitStreet::BOX_NL . '|' . SplitStreet::BOX_DE . '|' . SplitStreet::BOX_SLASH . '|' . SplitStreet::BOX_DASH . '|' . SplitStreet::BOX_B . '.+';
/**
* @param string $fullStreet
Expand Down
38 changes: 38 additions & 0 deletions test/Model/Consignment/ConsignmentSplitStreetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,35 @@ public function provideSplitStreetData(): array
self::expected(self::NUMBER_SUFFIX) => 'R',
self::expected(self::BOX_NUMBER) => '2',
],
[
self::FULL_STREET => 'Eikenstraat 1 Bus2',
self::COUNTRY => 'BE',
self::CARRIER_ID => CarrierBpost::ID,
self::expected(self::FULL_STREET) => 'Eikenstraat 1 bus 2',
self::expected(self::STREET) => 'Eikenstraat',
self::expected(self::NUMBER) => '1',
self::expected(self::NUMBER_SUFFIX) => '',
self::expected(self::BOX_NUMBER) => '2',
],
[
self::FULL_STREET => 'Klappoel 1b, Bus5',
self::COUNTRY => 'BE',
self::CARRIER_ID => CarrierBpost::ID,
self::expected(self::FULL_STREET) => 'Klappoel 1 bus 5 b',
self::expected(self::STREET) => 'Klappoel',
self::expected(self::NUMBER) => '1',
self::expected(self::NUMBER_SUFFIX) => 'b',
self::expected(self::BOX_NUMBER) => '5',
],
[self::FULL_STREET => 'Klappoel 1b/bus5',
self::COUNTRY => 'BE',
self::CARRIER_ID => CarrierBpost::ID,
self::expected(self::FULL_STREET) => 'Klappoel 1 bus 5 b',
self::expected(self::STREET) => 'Klappoel',
self::expected(self::NUMBER) => '1',
self::expected(self::NUMBER_SUFFIX) => 'b',
self::expected(self::BOX_NUMBER) => '5',
],
[
self::FULL_STREET => 'Zennestraat 32 bte 20',
self::COUNTRY => 'BE',
Expand Down Expand Up @@ -347,6 +376,15 @@ public function provideSplitStreetData(): array
self::expected(self::NUMBER) => 23,
self::expected(self::BOX_NUMBER) => '',
],
[
self::FULL_STREET => 'Straat 23-C11',
self::COUNTRY => 'BE',
self::CARRIER_ID => CarrierBpost::ID,
self::expected(self::FULL_STREET) => 'Straat 23 bus C11',
self::expected(self::STREET) => 'Straat',
self::expected(self::NUMBER) => 23,
self::expected(self::BOX_NUMBER) => 'C11',
],
[
self::FULL_STREET => 'Kortenberglaan 4 bus 10',
self::COUNTRY => 'BE',
Expand Down

0 comments on commit 0bc97fd

Please sign in to comment.