From 27a01c5086272cb7d5f3d3222d3672c3db0af2c1 Mon Sep 17 00:00:00 2001 From: Pierre Queyroi Date: Mon, 30 Nov 2026 04:31:17 +0100 Subject: [PATCH] Restrict CC postcodes to 6799 --- src/Formatter/CCFormatter.php | 13 ++++++------- tests/Formatter/CCFormatterTest.php | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Formatter/CCFormatter.php b/src/Formatter/CCFormatter.php index b88af7c..996073e 100644 --- a/src/Formatter/CCFormatter.php +++ b/src/Formatter/CCFormatter.php @@ -7,24 +7,23 @@ use Brick\Postcode\CountryPostcodeFormatter; use Override; -use function preg_match; - /** - * Validates and formats postcodes in Cocos (Keeling) Island. + * Validates and formats postcodes in Cocos (Keeling) Islands. * - * Postcodes consist of 4 digits, without separator. + * This territory uses a single postcode, 6799. * * @see https://en.wikipedia.org/wiki/List_of_postal_codes + * @see https://en.wikipedia.org/wiki/Cocos_(Keeling)_Islands */ final class CCFormatter implements CountryPostcodeFormatter { #[Override] public function format(string $postcode): ?string { - if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) { - return null; + if ($postcode === '6799') { + return $postcode; } - return $postcode; + return null; } } diff --git a/tests/Formatter/CCFormatterTest.php b/tests/Formatter/CCFormatterTest.php index 97f3aef..ddbbe16 100644 --- a/tests/Formatter/CCFormatterTest.php +++ b/tests/Formatter/CCFormatterTest.php @@ -21,7 +21,10 @@ public static function providerFormat(): array ['1', null], ['12', null], ['123', null], - ['1234', '1234'], + ['1234', null], + ['6798', null], + ['6799', '6799'], + ['6800', null], ['12345', null], ['123456', null],