|
13 | 13 | * The first 2 digits represent the department and can range from 00 to 32. |
14 | 14 | * |
15 | 15 | * @see https://en.wikipedia.org/wiki/List_of_postal_codes |
16 | | - * @see https://en.wikipedia.org/wiki/Postal_codes_in_Colombia |
| 16 | + * @see https://es.wikipedia.org/wiki/Anexo:C%C3%B3digos_postales_de_Colombia |
17 | 17 | */ |
18 | 18 | class COFormatter implements CountryPostcodeFormatter |
19 | 19 | { |
| 20 | + protected $departments = [ |
| 21 | + '05', '08', '11', '13', |
| 22 | + '15', '17', '18', '19', |
| 23 | + '20', '23', '25', '27', |
| 24 | + '41', '44', '47', '50', |
| 25 | + '52', '54', '63', '66', |
| 26 | + '68', '70', '73', '76', |
| 27 | + '81', '85', '86', '88', |
| 28 | + '91', '94', '95', '97', |
| 29 | + '99' |
| 30 | + ]; |
| 31 | + |
20 | 32 | /** |
21 | 33 | * {@inheritdoc} |
22 | 34 | */ |
23 | 35 | public function format(string $postcode) : ?string |
24 | 36 | { |
25 | | - if (preg_match('/^[0-9]{6}$/', $postcode) !== 1) { |
| 37 | + if (preg_match('/^\d{2}(?!0000)\d{4}$/', $postcode) !== 1) { |
26 | 38 | return null; |
27 | 39 | } |
28 | 40 |
|
| 41 | + |
29 | 42 | $department = substr($postcode, 0, 2); |
30 | 43 |
|
31 | | - if ($department > '32') { |
| 44 | + if (!in_array($department, $this->departments, true)) { |
32 | 45 | return null; |
33 | 46 | } |
34 | 47 |
|
|
0 commit comments