diff --git a/src/Helper/SplitStreet.php b/src/Helper/SplitStreet.php index 403578b7..9ac21047 100644 --- a/src/Helper/SplitStreet.php +++ b/src/Helper/SplitStreet.php @@ -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'], @@ -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 ); diff --git a/src/Helper/ValidateStreet.php b/src/Helper/ValidateStreet.php index 79892ba3..8376e01d 100644 --- a/src/Helper/ValidateStreet.php +++ b/src/Helper/ValidateStreet.php @@ -25,8 +25,7 @@ class ValidateStreet ')?$~i'; const SPLIT_STREET_REGEX_BE = - '~(?P.*?)\s(?P(?P[0-9\-]{1,8})\s?(?P' . self::REGEX_BE_BOX_SEPARATORS . ')?\s?(?P\d{0,8})\s?(?P[A-z]{0,4}$)?)$~'; - + '~(?P)(?P.*?)\s(?P(?P[0-9\-]{0,7}[0-9])(?P[A-z]{0,4})\s?(?P' . self::REGEX_BE_BOX_SEPARATORS . '|\,\s+)*\s?(?P[0-9A-z]{0,7}[0-9])?\s?(?:(?P[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 diff --git a/test/Model/Consignment/ConsignmentSplitStreetTest.php b/test/Model/Consignment/ConsignmentSplitStreetTest.php index bea26b28..1e10d7c2 100644 --- a/test/Model/Consignment/ConsignmentSplitStreetTest.php +++ b/test/Model/Consignment/ConsignmentSplitStreetTest.php @@ -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', @@ -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',