diff --git a/src/Formatter/NFFormatter.php b/src/Formatter/NFFormatter.php index 6626d83..0fcaecb 100644 --- a/src/Formatter/NFFormatter.php +++ b/src/Formatter/NFFormatter.php @@ -7,25 +7,24 @@ use Brick\Postcode\CountryPostcodeFormatter; use Override; -use function preg_match; - /** * Validates and formats postcodes in Norfolk Island. * - * Postcodes consist of 4 digits, without separator. + * This territory uses a single postcode, 2899. * Part of the Australian postal code system. * * @see https://en.wikipedia.org/wiki/List_of_postal_codes + * @see https://en.wikipedia.org/wiki/Postcodes_in_Australia#External_territories */ final class NFFormatter implements CountryPostcodeFormatter { #[Override] public function format(string $postcode): ?string { - if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) { - return null; + if ($postcode === '2899') { + return $postcode; } - return $postcode; + return null; } } diff --git a/tests/Formatter/NFFormatterTest.php b/tests/Formatter/NFFormatterTest.php index 0e2a8dc..524343c 100644 --- a/tests/Formatter/NFFormatterTest.php +++ b/tests/Formatter/NFFormatterTest.php @@ -21,7 +21,10 @@ public static function providerFormat(): array ['1', null], ['12', null], ['123', null], - ['1234', '1234'], + ['1234', null], + ['2898', null], + ['2899', '2899'], + ['2900', null], ['12345', null], ['A', null],