• 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

94.12
/src/Formatter/AXFormatter.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 str_starts_with;
11
use function strlen;
12
use function substr;
13

14
/**
15
 * Validates and formats postcodes in Ă…land Islands.
16
 *
17
 * Postcodes consist of 5 digits, starting with 22.
18
 * Postcodes may optionally start with "AX-" when used from abroad.
19
 * This formatter only outputs the prefix if present in the input.
20
 *
21
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
22
 */
23
final class AXFormatter implements CountryPostcodeFormatter
24
{
25
    public function hint(): string
26
    {
NEW
27
        return 'Postcodes consist of 5 digits, starting with 22.';
×
28
    }
29

30
    public function format(string $postcode): ?string
31
    {
32
        $length = strlen($postcode);
16✔
33
        $prefix = false;
16✔
34

35
        if ($length === 7) {
16✔
36
            if (! str_starts_with($postcode, 'AX')) {
2✔
37
                return null;
1✔
38
            }
39

40
            $postcode = substr($postcode, 2);
1✔
41
            $prefix = true;
1✔
42
        } elseif (strlen($postcode) !== 5) {
14✔
43
            return null;
11✔
44
        }
45

46
        if (preg_match('/^[0-9]+$/', $postcode) !== 1) {
4✔
47
            return null;
1✔
48
        }
49

50
        if (! str_starts_with($postcode, '22')) {
3✔
51
            return null;
1✔
52
        }
53

54
        if ($prefix) {
2✔
55
            return 'AX-' . $postcode;
1✔
56
        }
57

58
        return $postcode;
1✔
59
    }
60
}
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