• 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

85.71
/src/Formatter/COFormatter.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 in_array;
10
use function preg_match;
11
use function substr;
12

13
/**
14
 * Validates and formats postcodes in Colombia.
15
 *
16
 * Postal codes in Colombia are 6 digit numeric.
17
 * The first 2 digits represent the department and can range from 00 to 32.
18
 *
19
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
20
 * @see https://es.wikipedia.org/wiki/Anexo:C%C3%B3digos_postales_de_Colombia
21
 */
22
final class COFormatter implements CountryPostcodeFormatter
23
{
24
    private const DEPARTMENTS = [
25
        '05', '08', '11', '13',
26
        '15', '17', '18', '19',
27
        '20', '23', '25', '27',
28
        '41', '44', '47', '50',
29
        '52', '54', '63', '66',
30
        '68', '70', '73', '76',
31
        '81', '85', '86', '88',
32
        '91', '94', '95', '97',
33
        '99',
34
    ];
35

36
    public function hint(): string
37
    {
NEW
38
        return 'Postal codes in Colombia are 6 digit numeric.';
×
39
    }
40

41
    public function format(string $postcode): ?string
42
    {
43
        if (preg_match('/^\d{2}(?!0000)\d{4}$/', $postcode) !== 1) {
20✔
44
            return null;
16✔
45
        }
46

47
        $department = substr($postcode, 0, 2);
4✔
48

49
        if (! in_array($department, self::DEPARTMENTS, true)) {
4✔
50
            return null;
1✔
51
        }
52

53
        return $postcode;
3✔
54
    }
55
}
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