• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / PayWay / 5222637532

pending completion
5222637532

push

github

web-flow
Merge pull request #1 from mlocati/decode-country-alpha2

Add a way to find the ISO 3166-1 alpha-3 code from an alpha2 code

255 of 255 new or added lines in 3 files covered. (100.0%)

1565 of 2056 relevant lines covered (76.12%)

1.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/Dictionary/Country.php
1
<?php
2

3
namespace MLocati\PayWay\Dictionary;
4

5
use MLocati\PayWay\Service\Dictionary;
6
use RuntimeException;
7

8
class Country extends Dictionary
9
{
10
    const CODE_ITALY = 'ITA';
11

12
    /**
13
     * @var array|null
14
     */
15
    protected static $dictionary;
16

17
    /**
18
     * @var array|null
19
     */
20
    private static $codesFromIso3;
21

22
    /**
23
     * Get the ISO 3166-1 alpha-3 code to be used by PayWay starting from an ISO 3166-1 alpha-2 code.
24
     *
25
     * @param string|mixed $iso2
26
     *
27
     * @return string Empty string if $iso2 is invalid or can't be decoded
28
     *
29
     * @example returns 'ITA' from 'IT'
30
     */
31
    public static function getCodeFromIso2($iso2)
32
    {
33
        if (!is_string($iso2) || $iso2 === '') {
5✔
34
            return '';
3✔
35
        }
36
        $map = static::getCodesFromIso3();
2✔
37

38
        return isset($map[$iso2]) ? $map[$iso2] : '';
2✔
39
    }
40

41
    protected static function getDictionaryFile()
42
    {
43
        return 'country_names.php';
1✔
44
    }
45

46
    protected static function getCodesFromIso3()
47
    {
48
        if (self::$codesFromIso3 === null) {
2✔
49
            $codesFromIso3 = include static::getDataDir() . 'country_iso2.php';
1✔
50
            if (!is_array($codesFromIso3)) {
1✔
51
                throw new RuntimeException('Failed to retrieve the dictionary');
×
52
            }
53
            self::$codesFromIso3 = $codesFromIso3;
1✔
54
        }
55

56
        return self::$codesFromIso3;
2✔
57
    }
58
}
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