diff --git a/src/Formatter/CXFormatter.php b/src/Formatter/CXFormatter.php index 24a261b..737c05f 100644 --- a/src/Formatter/CXFormatter.php +++ b/src/Formatter/CXFormatter.php @@ -7,24 +7,23 @@ use Brick\Postcode\CountryPostcodeFormatter; use Override; -use function preg_match; - /** * Validates and formats postcodes in Christmas Island. * - * Postcodes consist of 4 digits, without separator. + * This territory uses a single postcode, 6798. * * @see https://en.wikipedia.org/wiki/List_of_postal_codes + * @see https://en.wikipedia.org/wiki/Postcodes_in_Australia#External_territories */ final class CXFormatter implements CountryPostcodeFormatter { #[Override] public function format(string $postcode): ?string { - if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) { - return null; + if ($postcode === '6798') { + return $postcode; } - return $postcode; + return null; } } diff --git a/tests/Formatter/CXFormatterTest.php b/tests/Formatter/CXFormatterTest.php index 9f89c0b..5a1ad05 100644 --- a/tests/Formatter/CXFormatterTest.php +++ b/tests/Formatter/CXFormatterTest.php @@ -21,7 +21,10 @@ public static function providerFormat(): array ['1', null], ['12', null], ['123', null], - ['1234', '1234'], + ['1234', null], + ['6797', null], + ['6798', '6798'], + ['6799', null], ['12345', null], ['123456', null],