• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / postcode / 19098923587

05 Nov 2025 10:27AM UTC coverage: 81.782% (-17.6%) from 99.396%
19098923587

Pull #19

github

web-flow
Merge 79bf98178 into 8ef37e5aa
Pull Request #19: Add hint to formatter, so a hint can be provided if postcode is invalid

5 of 184 new or added lines in 183 files covered. (2.72%)

2 existing lines in 1 file now uncovered.

826 of 1010 relevant lines covered (81.78%)

15.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/Formatter/ASFormatter.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Postcode\Formatter;
6

7
use Brick\Postcode\CountryPostcodeFormatter;
8

9
use function preg_match;
10
use function strlen;
11
use function substr;
12

13
/**
14
 * Validates and formats postcodes in American Samoa.
15
 *
16
 * Mail service in American Samoa is fully integrated with the United States Postal Service.
17
 * All points in the territory use the same ZIP code, 96799.
18
 *
19
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
20
 * @see https://en.wikipedia.org/wiki/Postal_codes_in_American_Samoa
21
 */
22
final class ASFormatter implements CountryPostcodeFormatter
23
{
24
    public function hint(): string
25
    {
NEW
26
        return 'Mail service in American Samoa is fully integrated with the United States Postal Service.';
×
27
    }
28

29
    public function format(string $postcode): ?string
30
    {
31
        $length = strlen($postcode);
22✔
32

33
        if ($length === 5) {
22✔
34
            if ($postcode !== '96799') {
3✔
35
                return null;
2✔
36
            }
37

38
            return $postcode;
1✔
39
        }
40

41
        if (preg_match('/^[0-9]{9}$/', $postcode) !== 1) {
19✔
42
            return null;
17✔
43
        }
44

45
        $zip = substr($postcode, 0, 5);
2✔
46

47
        if ($zip !== '96799') {
2✔
48
            return null;
1✔
49
        }
50

51
        $plusFour = substr($postcode, 5);
1✔
52

53
        return $zip . '-' . $plusFour;
1✔
54
    }
55
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc