Passed
Push — upstream-8.11.0 ( 4431ea )
by Joshua
03:25
created

MappingFileProvider::getFileName()   B

Complexity

Conditions 8
Paths 7

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 8.0291

Importance

Changes 0
Metric Value
cc 8
eloc 10
nc 7
nop 4
dl 0
loc 21
ccs 12
cts 13
cp 0.9231
crap 8.0291
rs 8.4444
c 0
b 0
f 0
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. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function getFileName($countryCallingCode, $language, /** @scrutinizer ignore-unused */ $script, $region)

This check looks for 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