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

brick / postcode / 19098978650

05 Nov 2025 10:29AM UTC coverage: 81.719% (-17.7%) from 99.396%
19098978650

Pull #19

github

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

6 of 186 new or added lines in 184 files covered. (3.23%)

827 of 1012 relevant lines covered (81.72%)

15.0 hits per line

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

87.5
/src/Formatter/MSFormatter.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 Montserrat.
15
 *
16
 * The format is MSR followed by a space then 4 digits, in the range 1110 to 1350.
17
 *
18
 * This formatter accepts the postcode both with and without the MSR prefix, and always outputs the prefix.
19
 *
20
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
21
 */
22
final class MSFormatter implements CountryPostcodeFormatter
23
{
24
    public function hint(): string
25
    {
NEW
26
        return 'The format is MSR followed by a space then 4 digits, in the range 1110 to 1350.';
×
27
    }
28

29
    public function format(string $postcode): ?string
30
    {
31
        if (str_starts_with($postcode, 'MSR')) {
35✔
32
            $postcode = substr($postcode, 3);
12✔
33
        }
34

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

39
        if ($postcode < '1110' || $postcode > '1350') {
14✔
40
            return null;
4✔
41
        }
42

43
        return 'MSR ' . $postcode;
10✔
44
    }
45
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc