Skip to content

Commit 79bf981

Browse files
committed
Add hint to formatter, so a hint can be provided if postcode is invalid
1 parent 8ef37e5 commit 79bf981

File tree

184 files changed

+919
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+919
-2
lines changed

src/CountryPostcodeFormatter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ interface CountryPostcodeFormatter
2121
* @return string|null The formatted postcode, or NULL if the postcode is invalid.
2222
*/
2323
public function format(string $postcode): ?string;
24+
25+
/**
26+
* Returns a hint describing the expected postcode format for this country.
27+
*
28+
* @return string A hint describing the expected postcode format.
29+
*/
30+
public function hint(): string;
2431
}

src/Formatter/ADFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
*/
2222
final class ADFormatter implements CountryPostcodeFormatter
2323
{
24+
public function hint(): string
25+
{
26+
return 'Postcodes consist of the letters AD, followed by 3 digits, without separator.';
27+
}
28+
2429
public function format(string $postcode): ?string
2530
{
2631
if (str_starts_with($postcode, 'AD')) {

src/Formatter/AFFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
*/
2424
final class AFFormatter implements CountryPostcodeFormatter
2525
{
26+
public function hint(): string
27+
{
28+
return 'Postcodes consist of 4 digits, without separator.';
29+
}
30+
2631
public function format(string $postcode): ?string
2732
{
2833
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {

src/Formatter/AIFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
*/
1717
final class AIFormatter implements CountryPostcodeFormatter
1818
{
19+
public function hint(): string
20+
{
21+
return 'Anguilla uses a single postcode for all addresses.';
22+
}
23+
1924
public function format(string $postcode): ?string
2025
{
2126
if ($postcode === '2640' || $postcode === 'AI2640') {

src/Formatter/ALFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
final class ALFormatter implements CountryPostcodeFormatter
2020
{
21+
public function hint(): string
22+
{
23+
return 'Postcodes consist of 4 digits, without separator.';
24+
}
25+
2126
public function format(string $postcode): ?string
2227
{
2328
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {

src/Formatter/AMFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
final class AMFormatter implements CountryPostcodeFormatter
2020
{
21+
public function hint(): string
22+
{
23+
return 'Postcodes consist of 4 digits, without separator.';
24+
}
25+
2126
public function format(string $postcode): ?string
2227
{
2328
if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {

src/Formatter/AQFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
*/
1616
final class AQFormatter implements CountryPostcodeFormatter
1717
{
18+
public function hint(): string
19+
{
20+
return 'This country uses a single postcode for all addresses.';
21+
}
22+
1823
public function format(string $postcode): ?string
1924
{
2025
if ($postcode === 'BIQQ1ZZ') {

src/Formatter/ARFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
*/
1919
final class ARFormatter implements CountryPostcodeFormatter
2020
{
21+
public function hint(): string
22+
{
23+
return 'The postcode is either 4 digits, or 1 letter + 4 digits + 3 letters, with no separators.';
24+
}
25+
2126
public function format(string $postcode): ?string
2227
{
2328
if (preg_match('/^(([0-9]{4})|([A-Z][0-9]{4}[A-Z]{3}))$/', $postcode) !== 1) {

src/Formatter/ASFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
*/
2222
final class ASFormatter implements CountryPostcodeFormatter
2323
{
24+
public function hint(): string
25+
{
26+
return 'Mail service in American Samoa is fully integrated with the United States Postal Service.';
27+
}
28+
2429
public function format(string $postcode): ?string
2530
{
2631
$length = strlen($postcode);

src/Formatter/ATFormatter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ final class ATFormatter implements CountryPostcodeFormatter
2121
{
2222
use StripPrefix;
2323

24+
public function hint(): string
25+
{
26+
return 'Postcodes consist of 4 digits, without separator. The first digit must be 1-9.';
27+
}
28+
2429
public function format(string $postcode): ?string
2530
{
2631
$postcode = $this->stripPrefix($postcode, 'A');

0 commit comments

Comments
 (0)