Completed
Push — master ( 71957b...519609 )
by Joshua
16:17
created

MappingFileProvider::getFileName()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 8.1426

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 17
ccs 5
cts 7
cp 0.7143
rs 8.2222
cc 7
eloc 8
nc 5
nop 4
crap 8.1426
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 252
    public function __construct($map)
18
    {
19 252
        $this->map = $map;
20 252
    }
21
22 7
    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
        if (strlen($language) == 0) {
25
            return "";
26
        }
27
28 7
        if ($language === 'zh' && ($region == 'TW' || $region == 'HK' || $region == 'MO')) {
29 1
            $language = 'zh_Hant';
30
        }
31
32
        if ($this->inMap($language, $countryCallingCode)) {
33 6
            return $language . DIRECTORY_SEPARATOR . $countryCallingCode . '.php';
34
        }
35
36
37 3
        return "";
38
    }
39
40
    protected function inMap($language, $countryCallingCode)
41
    {
42
        return (array_key_exists($language, $this->map) && in_array($countryCallingCode, $this->map[$language]));
43
    }
44
}
45