Issues (44)

src/prefixmapper/MappingFileProvider.php (1 issue)

Severity
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
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
        }
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 22
                return $language . DIRECTORY_SEPARATOR . $prefix . '.php';
40
            }
41
        }
42
43 8
        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