Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Formatter/CXFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 4 additions & 1 deletion tests/Formatter/CXFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],

Expand Down
Loading