• 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

93.33
/src/Formatter/LTFormatter.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
use function str_starts_with;
11
use function strlen;
12
use function substr;
13

14
/**
15
 * Validates and formats postcodes in Lithuania.
16
 *
17
 * Postal codes in Lithuania since 2005 are 5 digit numeric.
18
 * ISO 3166-1 alpha-2 prefix is allowed, with that the format is LT-NNNNN.
19
 *
20
 * This formatter accepts inputs both with and without the LT prefix,
21
 * and outputs the prefix only if present in the input.
22
 *
23
 * @see https://en.wikipedia.org/wiki/List_of_postal_codes
24
 * @see https://en.wikipedia.org/wiki/Postal_codes_in_Lithuania
25
 */
26
final class LTFormatter implements CountryPostcodeFormatter
27
{
28
    public function hint(): string
29
    {
NEW
30
        return 'Postal codes in Lithuania since 2005 are 5 digit numeric.';
×
31
    }
32

33
    public function format(string $postcode): ?string
34
    {
35
        $length = strlen($postcode);
22✔
36
        $prefix = false;
22✔
37

38
        if ($length === 7) {
22✔
39
            if (! str_starts_with($postcode, 'LT')) {
5✔
40
                return null;
3✔
41
            }
42

43
            $postcode = substr($postcode, 2);
2✔
44
            $prefix = true;
2✔
45
        } elseif (strlen($postcode) !== 5) {
17✔
46
            return null;
15✔
47
        }
48

49
        if (preg_match('/^[0-9]+$/', $postcode) !== 1) {
4✔
50
            return null;
2✔
51
        }
52

53
        if ($prefix) {
2✔
54
            return 'LT-' . $postcode;
1✔
55
        }
56

57
        return $postcode;
1✔
58
    }
59
}
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