Skip to content

Commit 6ed51fd

Browse files
committed
Add support for 4-digit LB postcodes
1 parent 59d1c90 commit 6ed51fd

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/Formatter/LBFormatter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
* Postcode format is NNNN NNNN, where N stands for a digit.
1717
*
1818
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
19+
* @see https://github.com/brick/postcode/issues/22
1920
*/
2021
final class LBFormatter implements CountryPostcodeFormatter
2122
{
2223
#[Override]
2324
public function format(string $postcode): ?string
2425
{
25-
if (preg_match('/^[0-9]{8}$/', $postcode) !== 1) {
26-
return null;
26+
if (preg_match('/^[0-9]{4}$/', $postcode) === 1) {
27+
return $postcode;
2728
}
2829

29-
return substr($postcode, 0, 4) . ' ' . substr($postcode, 4);
30+
if (preg_match('/^[0-9]{8}$/', $postcode) === 1) {
31+
return substr($postcode, 0, 4) . ' ' . substr($postcode, 4);
32+
}
33+
34+
return null;
3035
}
3136
}

tests/Formatter/LBFormatterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function providerFormat(): array
2222
['12', null],
2323
['012', null],
2424
['123', null],
25-
['1234', null],
25+
['1234', '1234'],
2626
['01234', null],
2727
['12345', null],
2828
['123456', null],

0 commit comments

Comments
 (0)