diff --git a/src/Formatter/COFormatter.php b/src/Formatter/COFormatter.php index 3b9ee8b..6b46dce 100644 --- a/src/Formatter/COFormatter.php +++ b/src/Formatter/COFormatter.php @@ -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; } diff --git a/tests/Formatter/COFormatterTest.php b/tests/Formatter/COFormatterTest.php index 69a9473..136f4dc 100644 --- a/tests/Formatter/COFormatterTest.php +++ b/tests/Formatter/COFormatterTest.php @@ -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],