Completed
Pull Request — master (#119)
by Joshua
36:02 queued 19:39
created

Locale   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 3 Features 2
Metric Value
wmc 5
c 6
b 3
f 2
lcom 0
cbo 0
dl 0
loc 29
ccs 0
cts 16
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B countryCodeToLocale() 0 18 5
1
<?php
2
3
namespace libphonenumber\geocoding;
4
5
6
class Locale extends \Locale
7
{
8
    /**
9
     * Returns a locale from a country code that is provided.
10
     * @link http://stackoverflow.com/a/10375234/403165
11
     * @param string $country_code ISO 3166-2-alpha 2 country code
12
     * @param string $language_code ISO 639-1-alpha 2 language code
13
     * @returns string a locale, formatted like en_US, or null if not found
14
     */
15
    public static function countryCodeToLocale($country_code, $language_code = '')
16
    {
17
        $locale = 'en-' . $country_code;
18
        $locale_region = locale_get_region($locale);
19
        $locale_language = locale_get_primary_language($locale);
20
        $locale_array = array(
21
            'language' => $locale_language,
22
            'region' => $locale_region
23
        );
24
25
        if (strtoupper($country_code) == $locale_region && $language_code == '') {
26
            return locale_compose($locale_array);
27
        } elseif (strtoupper($country_code) == $locale_region && strtolower($language_code) == $locale_language) {
28
            return locale_compose($locale_array);
29
        }
30
31
        return null;
32
    }
33
34
}
35