Skip to content

Commit 89220a8

Browse files
authored
Improve IE formatter (#8)
there are only 139 Routing Keys, some Unique Identifier were missing, fix tests
1 parent 2e63f06 commit 89220a8

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/Formatter/IEFormatter.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,47 @@
99
/**
1010
* Validates and formats the postcodes in the Republic of Ireland.
1111
*
12-
* Postcodes can have eight different formats:
12+
* Postcodes can have at least the following thirteen different formats:
1313
*
14-
* - ANN ANAN
15-
* - ANN AANN
14+
* - ANN NNNA
15+
* - ANN NANN
1616
* - ANN ANNN
17+
* - ANN ANNA
18+
* - ANN ANAN
1719
* - ANN ANAA
20+
* - ANN AANN
21+
* - ANN AANA
22+
* - ANN AAAN
1823
*
19-
* - ANW ANAN
20-
* - ANW AANN
21-
* - ANW ANAA
22-
* - ANW ANNN (?) @todo ANNN is valid with ANN prefix, but not sure about ANW.
24+
* - D6W ANAN
25+
* - D6W AANN
26+
* - D6W ANAA
27+
* - D6W ANNN
2328
*
24-
* A stands for a capital letter, N stands for a digit, W is the letter W.
29+
* 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.
2530
*
26-
* @todo not all alphabet letters are allowed.
31+
* The first part is one of the 139 Routing Keys, the second is a Unique Identifier.
32+
* The pdf document linked below defines Eircode's character set on page 11.
2733
*
2834
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
2935
* @see https://en.wikipedia.org/wiki/Postal_addresses_in_the_Republic_of_Ireland
30-
* @see https://www.eircode.ie/
36+
* @see https://www.eircode.ie/docs/default-source/Common/prepareyourbusinessforeircode-edition3published.pdf
37+
* @see https://www.autoaddress.ie/support/developer-centre/resources/routing-key-boundaries
3138
*/
3239
class IEFormatter implements CountryPostcodeFormatter
3340
{
3441
/**
3542
* The regular expression pattern used to validate the postcode and extract the two parts.
3643
*/
3744
private const PATTERN = '/^'
38-
. '([A-Z][0-9][0-9W])'
3945
. '('
40-
. '(?:[A-Z][0-9][0-9][0-9])|'
41-
. '(?:[A-Z][0-9][A-Z][0-9])|'
42-
. '(?:[A-Z][A-Z][0-9][0-9])|'
43-
. '(?:[A-Z][0-9][A-Z][A-Z])'
46+
. '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|'
47+
. '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|'
48+
. '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|'
49+
. '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|'
50+
. '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'
4451
. ')'
52+
. '([ACDEFHKNPRTVWXY0-9]{4})'
4553
. '$/';
4654

4755
/**

tests/Formatter/IEFormatterTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public function providerFormat() : array
4545
['ABCDEF', null],
4646
['ABCDEFGH', null],
4747

48-
['A12B3C4', 'A12 B3C4'],
49-
['A12B3CD', 'A12 B3CD'],
50-
['A12BC34', 'A12 BC34'],
48+
['A98C7D6', 'A98 C7D6'],
49+
['A98C7DE', 'A98 C7DE'],
50+
['A98CD76', 'A98 CD76'],
5151
['A98F625', 'A98 F625'],
52+
['T12X23H', 'T12 X23H'],
53+
['V94312N', 'V94 312N'],
5254

53-
['A1WB3C4', 'A1W B3C4'],
54-
['A1WB3CD', 'A1W B3CD'],
55-
['A1WBC34', 'A1W BC34'],
55+
['D6WA1C2', 'D6W A1C2'],
56+
['D6WA1CD', 'D6W A1CD'],
57+
['D6WV593', 'D6W V593'],
5658

5759
['A1XB3C4', null],
5860
['A1XB3CD', null],

0 commit comments

Comments
 (0)