Completed
Push — 7.7.4-changes ( 130305...3e87b4 )
by Joshua
10:55
created

MappingFileProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace libphonenumber\prefixmapper;
4
5
/**
6
 * A utility which knows the data files that are available for the phone prefix mappers to use.
7
 * The data files contain mappings from phone number prefixes to text descriptions, and are
8
 * organized by country calling code and language that the text descriptions are in.
9
 *
10
 * Class MappingFileProvider
11
 * @package libphonenumber\prefixmapper
12
 */
13
class MappingFileProvider
14
{
15
    protected $map;
16
17 253
    public function __construct($map)
18
    {
19 253
        $this->map = $map;
20 253
    }
21
22 25
    public function getFileName($countryCallingCode, $language, $script, $region)
0 ignored issues
show
Unused Code introduced by
The parameter $script is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24 25
        if (strlen($language) == 0) {
25
            return "";
26
        }
27
28 25
        if ($language === 'zh' && ($region == 'TW' || $region == 'HK' || $region == 'MO')) {
29 1
            $language = 'zh_Hant';
30
        }
31
32
        // Loop through the $countryCallingCode and load the prefix
33 25
        $prefixLength = strlen($countryCallingCode);
34
35 25
        for ($i = $prefixLength; $i > 0; $i--) {
36 25
            $prefix = substr($countryCallingCode, 0, $i);
37 25
            if ($this->inMap($language, $prefix)) {
38 21
                return $language . DIRECTORY_SEPARATOR . $prefix . '.php';
39
            }
40
        }
41
42 9
        return "";
43
    }
44
45 25
    protected function inMap($language, $countryCallingCode)
46
    {
47 25
        return (array_key_exists($language, $this->map) && in_array($countryCallingCode, $this->map[$language]));
48
    }
49
}
50