Skip to content

Commit

Permalink
fix: support capital letters in box number detection (#508)
Browse files Browse the repository at this point in the history
* feat: add support for correct 'BUS' handling

* feat: add test for BUS

* feat: add test for BUS
  • Loading branch information
GravendeelJochem authored Nov 7, 2024
1 parent e6bacc5 commit 98d4a0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Helper/ValidateStreet.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class ValidateStreet
'[a-z][a-z\s]{0,5}'. // has up to 6 letters with a space
')?$~i';

const SPLIT_STREET_REGEX_BE =
'~(?P<box_separator>)(?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 SPLIT_STREET_REGEX_BE = '~(?P<box_separator>)(?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>(?i:' . 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
9 changes: 9 additions & 0 deletions test/Model/Consignment/ConsignmentSplitStreetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ public function provideSplitStreetData(): array
self::expected(self::NUMBER) => '4',
self::expected(self::BOX_NUMBER) => '10',
],
[
self::FULL_STREET => 'Kortenberglaan 4 BUS 10',
self::COUNTRY => 'BE',
self::CARRIER_ID => CarrierBpost::ID,
self::expected(self::FULL_STREET) => 'Kortenberglaan 4 bus 10',
self::expected(self::STREET) => 'Kortenberglaan',
self::expected(self::NUMBER) => '4',
self::expected(self::BOX_NUMBER) => '10',
],
[
self::FULL_STREET => 'Ildefonse Vandammestraat 5 D',
self::COUNTRY => 'BE',
Expand Down

0 comments on commit 98d4a0d

Please sign in to comment.