Completed
Push — upstream-8.3.0 ( 6d22b3...36447c )
by Joshua
29:18 queued 18:23
created

MappingFileProvider::getFileName()   C

Complexity

Conditions 8
Paths 7

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 8.0291

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
rs 6.6037
c 1
b 0
f 0
ccs 12
cts 13
cp 0.9231
cc 8
eloc 11
nc 7
nop 4
crap 8.0291
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
 * @internal
13
 */
14
class MappingFileProvider
15
{
16
    protected $map;
17
18 253
    public function __construct($map)
19
    {
20 253
        $this->map = $map;
21 253
    }
22
23 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...
24
    {
25 25
        if (strlen($language) == 0) {
26
            return "";
27
        }
28
29 25
        if ($language === 'zh' && ($region == 'TW' || $region == 'HK' || $region == 'MO')) {
30 1
            $language = 'zh_Hant';
31 1
        }
32
33
        // Loop through the $countryCallingCode and load the prefix
34 25
        $prefixLength = strlen($countryCallingCode);
35
36 25
        for ($i = $prefixLength; $i > 0; $i--) {
37 25
            $prefix = substr($countryCallingCode, 0, $i);
38 25
            if ($this->inMap($language, $prefix)) {
39 21
                return $language . DIRECTORY_SEPARATOR . $prefix . '.php';
40
            }
41 25
        }
42
43 9
        return "";
44
    }
45
46 25
    protected function inMap($language, $countryCallingCode)
47
    {
48 25
        return (array_key_exists($language, $this->map) && in_array($countryCallingCode, $this->map[$language]));
49
    }
50
}
51