• 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

87.5
/src/Formatter/VGFormatter.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 substr;
12

13
/**
14
 * Validates and formats postcodes in British Virgin Islands.
15
 *
16
 * The postcode format is VG followed by 4 digits, specifically VG1110 through VG1160.
17
 * This formatter accepts inputs with and without the VG prefix, and always outputs the prefix.
18
 *
19
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
20
 */
21
final class VGFormatter implements CountryPostcodeFormatter
22
{
23
    public function hint(): string
24
    {
NEW
25
        return 'The postcode format is VG followed by 4 digits, specifically VG1110 through VG1160.';
×
26
    }
27

28
    public function format(string $postcode): ?string
29
    {
30
        if (str_starts_with($postcode, 'VG')) {
32✔
31
            $postcode = substr($postcode, 2);
14✔
32
        }
33

34
        if (preg_match('/^[0-9]{4}$/', $postcode) !== 1) {
32✔
35
            return null;
20✔
36
        }
37

38
        if ($postcode < '1110' || $postcode > '1160') {
12✔
39
            return null;
4✔
40
        }
41

42
        return 'VG' . $postcode;
8✔
43
    }
44
}
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