LanguageService::getLanguageByCountry()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lochmueller\LanguageDetection\Service;
6
7
use Locale;
8
use ResourceBundle;
9
10
class LanguageService
11
{
12
    public function getLanguageByCountry(string $country): string
13
    {
14
        /** @var ResourceBundle $subtags */
15
        $subtags = ResourceBundle::create('likelySubtags', 'ICUDATA', false);
16
        $dummy = 'und_' . strtoupper($country);
17
        $locale = $subtags->get($dummy) ?: $subtags->get('und');
18
19
        return Locale::getPrimaryLanguage($locale);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Locale::getPrimaryLanguage($locale) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
20
    }
21
}
22