Completed
Push — master ( d3870a...2c6c1e )
by Loban
06:16
created

LocaleHelperTrait::getPrimaryLanguage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: loal
5
 * Date: 04.07.16
6
 * Time: 15:10
7
 */
8
9
namespace lav45\translate;
10
11
use Locale;
12
13
trait LocaleHelperTrait
14
{
15
    /**
16
     * @param string $locale `en-EN`, `ru-RU`
17
     * @return string en or ru
18
     */
19 15
    public function getPrimaryLanguage($locale)
20
    {
21 15
        return extension_loaded('intl') ?
22 15
            Locale::getPrimaryLanguage($locale) : substr($locale, 0, 2);
23
    }
24
}