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
7 changes: 7 additions & 0 deletions src/CountryPostcodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ interface CountryPostcodeFormatter
* @return string|null The formatted postcode, or NULL if the postcode is invalid.
*/
public function format(string $postcode): ?string;

/**
* Returns a hint describing the expected postcode format for this country.
*
* @return string A hint describing the expected postcode format.
*/
public function hint(): string;
}
5 changes: 5 additions & 0 deletions src/Formatter/ADFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class ADFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of the letters AD, followed by 3 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (str_starts_with($postcode, 'AD')) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AFFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
final class AFFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be really useful, we would need to mention the 10-43 province code as well.

}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AIFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
final class AIFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Anguilla uses a single postcode for all addresses.';
}

public function format(string $postcode): ?string
{
if ($postcode === '2640' || $postcode === 'AI2640') {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/ALFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class ALFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AMFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class AMFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AQFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
final class AQFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'This country uses a single postcode for all addresses.';
}

public function format(string $postcode): ?string
{
if ($postcode === 'BIQQ1ZZ') {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/ARFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class ARFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'The postcode is either 4 digits, or 1 letter + 4 digits + 3 letters, with no separators.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^(([0-9]{4})|([A-Z][0-9]{4}[A-Z]{3}))$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/ASFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class ASFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Mail service in American Samoa is fully integrated with the United States Postal Service.';
}

public function format(string $postcode): ?string
{
$length = strlen($postcode);
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/ATFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ final class ATFormatter implements CountryPostcodeFormatter
{
use StripPrefix;

public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator. The first digit must be 1-9.';
}

public function format(string $postcode): ?string
{
$postcode = $this->stripPrefix($postcode, 'A');
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AUFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class AUFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AXFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
*/
final class AXFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 5 digits, starting with 22.';
}

public function format(string $postcode): ?string
{
$length = strlen($postcode);
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/AZFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class AZFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'The postcode format is AZ NNNN, where N represents a digit.';
}

public function format(string $postcode): ?string
{
if (str_starts_with($postcode, 'AZ')) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BAFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
final class BAFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 5 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{5}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BBFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class BBFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postal codes in Barbados are 5 digit numeric, with BB prefix.';
}

public function format(string $postcode): ?string
{
if (str_starts_with($postcode, 'BB')) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BDFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class BDFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BEFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ final class BEFormatter implements CountryPostcodeFormatter
{
use StripPrefix;

public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
$postcode = $this->stripPrefix($postcode, 'B');
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BGFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class BGFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BHFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class BHFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Valid post code numbers are 101 to 1216 with gaps in the range. Known as block number formally.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^(1?[0-9])([0-9]{2})$/', $postcode, $matches) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
final class BLFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'This country uses a single postcode, 97133.';
}

public function format(string $postcode): ?string
{
if ($postcode === '97133') {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BMFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class BMFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcode formats are AA NN for street addresses, AA AA for P.O. Box addresses (A=letter, N=digit).';
}

public function format(string $postcode): ?string
{
if (preg_match('/^([A-Z]{2})([A-Z]{2}|[0-9]{2})$/', $postcode, $matches) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BNFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class BNFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcode format is two letters followed by 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[A-Z]{2}[0-9]{4}$/', $postcode, $matches) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BRFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
final class BRFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Format is 5 digits, hyphen, 3 digits.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{8}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BTFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
final class BTFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 5 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{5}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/BYFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
final class BYFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postal codes in Belarus are 6 digit numeric.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{6}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CAFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class CAFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'The format is ANA NAN, where A is a letter and N is a digit.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^([ABCEGHJ-NPRSTV-Z][0-9]){3}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CCFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
final class CCFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CHFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
final class CHFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 4 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CLFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
*/
final class CLFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 7 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{7}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CNFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
*/
final class CNFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'China Post uses a six-digit all-numerical system, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{6}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/COFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ final class COFormatter implements CountryPostcodeFormatter
'99',
];

public function hint(): string
{
return 'Postal codes in Colombia are 6 digit numeric.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^\d{2}(?!0000)\d{4}$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CRFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/
final class CRFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postal codes in Costa Rica are 5 digit numeric.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]+$/', $postcode) !== 1) {
Expand Down
5 changes: 5 additions & 0 deletions src/Formatter/CUFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
final class CUFormatter implements CountryPostcodeFormatter
{
public function hint(): string
{
return 'Postcodes consist of 5 digits, without separator.';
}

public function format(string $postcode): ?string
{
if (preg_match('/^[0-9]{5}$/', $postcode) !== 1) {
Expand Down
Loading