Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/Formatter/COFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,35 @@
* The first 2 digits represent the department and can range from 00 to 32.
*
* @see https://en.wikipedia.org/wiki/List_of_postal_codes
* @see https://en.wikipedia.org/wiki/Postal_codes_in_Colombia
* @see https://es.wikipedia.org/wiki/Anexo:C%C3%B3digos_postales_de_Colombia
*/
class COFormatter implements CountryPostcodeFormatter
{
protected $departments = [
'05', '08', '11', '13',
'15', '17', '18', '19',
'20', '23', '25', '27',
'41', '44', '47', '50',
'52', '54', '63', '66',
'68', '70', '73', '76',
'81', '85', '86', '88',
'91', '94', '95', '97',
'99'
];

/**
* {@inheritdoc}
*/
public function format(string $postcode) : ?string
{
if (preg_match('/^[0-9]{6}$/', $postcode) !== 1) {
if (preg_match('/^\d{2}(?!0000)\d{4}$/', $postcode) !== 1) {
return null;
}


$department = substr($postcode, 0, 2);

if ($department > '32') {
if (!in_array($department, $this->departments, true)) {
return null;
}

Expand Down
10 changes: 6 additions & 4 deletions tests/Formatter/COFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public function providerFormat() : array
['123', null],
['1234', null],
['12345', null],
['000000', '000000'],
['123456', '123456'],
['320000', '320000'],
['330000', null],
['000000', null],
['123456', null],
['661001', '661001'],
['760002', '760002'],
['850000', null],
['850001', '850001'],
['990000', null],
['1234567', null],

Expand Down