• 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

75.0
/src/Formatter/IMFormatter.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

11
/**
12
 * Validates and formats the postcodes in the Isle of Man.
13
 *
14
 * Postcodes can have two different formats:
15
 *
16
 * - IM9 9AA
17
 * - IM99 9AA
18
 *
19
 * A stands for a capital letter, 9 stands for a digit.
20
 *
21
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
22
 * @see https://en.wikipedia.org/wiki/IM_postcode_area
23
 */
24
final class IMFormatter implements CountryPostcodeFormatter
25
{
26
    /**
27
     * The regular expression pattern used to validate the postcode and extract the two parts.
28
     */
29
    private const PATTERN
30
        = '/^'
31
        . '(IM[0-9][0-9]?)'
32
        . '([0-9][A-Z][A-Z])'
33
        . '$/';
34

35
    public function hint(): string
36
    {
NEW
37
        return 'Postcodes can have two different formats: IM9 9AA or IM99 9AA. A stands for a capital letter, 9 stands for a digit.';
×
38
    }
39

40
    public function format(string $postcode): ?string
41
    {
42
        if (preg_match(self::PATTERN, $postcode, $matches) !== 1) {
81✔
43
            return null;
79✔
44
        }
45

46
        return $matches[1] . ' ' . $matches[2];
2✔
47
    }
48
}
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