• 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/IEFormatter.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 Republic of Ireland.
13
 *
14
 * Postcodes can have at least the following thirteen different formats:
15
 *
16
 * - ANN NNNA
17
 * - ANN NANN
18
 * - ANN ANNN
19
 * - ANN ANNA
20
 * - ANN ANAN
21
 * - ANN ANAA
22
 * - ANN AANN
23
 * - ANN AANA
24
 * - ANN AAAN
25
 *
26
 * - D6W ANAN
27
 * - D6W AANN
28
 * - D6W ANAA
29
 * - D6W ANNN
30
 *
31
 * A stands for the capital letter A,C,D,E,F,H,K,N,P,R,T,V,W,X or Y. N stands for a digit. D6W stans literally for D6W.
32
 *
33
 * The first part is one of the 139 Routing Keys, the second is a Unique Identifier.
34
 * The pdf document linked below defines Eircode's character set on page 11.
35
 *
36
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
37
 * @see https://en.wikipedia.org/wiki/Postal_addresses_in_the_Republic_of_Ireland
38
 * @see https://www.eircode.ie/docs/default-source/Common/prepareyourbusinessforeircode-edition3published.pdf
39
 * @see https://www.autoaddress.ie/support/developer-centre/resources/routing-key-boundaries
40
 */
41
final class IEFormatter implements CountryPostcodeFormatter
42
{
43
    /**
44
     * The regular expression pattern used to validate the postcode and extract the two parts.
45
     */
46
    private const PATTERN = '/^'
47
        . '('
48
        . 'A41|A42|A45|A63|A67|A75|A81|A82|A83|A84|A85|A86|A91|A92|A94|A96|A98|C15|D01|D02|D03|D04|D05|D06|D6W|D07|D08|D09|'
49
        . 'D10|D11|D12|D13|D14|D15|D16|D17|D18|D20|D22|D24|E21|E25|E32|E34|E41|E45|E53|E91|F12|F23|F26|F28|F31|F35|F42|F45|'
50
        . 'F52|F56|F91|F92|F93|F94|H12|H14|H16|H18|H23|H53|H54|H62|H65|H71|H91|K32|K34|K36|K45|K56|K67|K78|N37|N39|N41|N91|'
51
        . 'P12|P14|P17|P24|P25|P31|P32|P36|P43|P47|P51|P56|P61|P67|P72|P75|P81|P85|R14|R21|R32|R35|R42|R45|R51|R56|R93|R95|'
52
        . 'T12|T23|T34|T45|T56|V14|V15|V23|V31|V35|V42|V92|V93|V94|V95|W12|W23|W34|W91|X35|X42|X91|Y14|Y21|Y25|Y34|Y35'
53
        . ')'
54
        . '([ACDEFHKNPRTVWXY0-9]{4})'
55
        . '$/';
56

57
    public function hint(): string
58
    {
NEW
59
        return 'Postcodes can have at least the following thirteen different formats:';
×
60
    }
61

62
    public function format(string $postcode): ?string
63
    {
64
        if (preg_match(self::PATTERN, $postcode, $matches) !== 1) {
151✔
65
            return null;
142✔
66
        }
67

68
        return $matches[1] . ' ' . $matches[2];
9✔
69
    }
70
}
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