• 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

88.89
/src/Formatter/BHFormatter.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 preg_match;
10

11
/**
12
 * Validates and formats postcodes in Bahrain.
13
 *
14
 * Valid post code numbers are 101 to 1216 with gaps in the range. Known as block number formally.
15
 * The first 1 or 2 digits refer to one of the 12 municipalities of the country.
16
 *
17
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
18
 */
19
final class BHFormatter implements CountryPostcodeFormatter
20
{
21
    public function hint(): string
22
    {
NEW
23
        return 'Valid post code numbers are 101 to 1216 with gaps in the range. Known as block number formally.';
×
24
    }
25

26
    public function format(string $postcode): ?string
27
    {
28
        if (preg_match('/^(1?[0-9])([0-9]{2})$/', $postcode, $matches) !== 1) {
19✔
29
            return null;
12✔
30
        }
31

32
        $municipality = (int) $matches[1];
7✔
33

34
        if ($municipality < 1 || $municipality > 12) {
7✔
35
            return null;
3✔
36
        }
37

38
        if ($matches[2] === '00') {
4✔
39
            return null;
2✔
40
        }
41

42
        return $postcode;
2✔
43
    }
44
}
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