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

MappingFileProvider   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 37
ccs 15
cts 16
cp 0.9375
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A inMap() 0 4 2
C getFileName() 0 22 8
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