Conditions | 3 |
Paths | 3 |
Total Lines | 29 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3.0123 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 24 | public static function transform( $language ) { |
|
24 | 24 | if ( ! is_string( $language ) ) { |
|
|
|||
25 | return null; |
||
26 | } |
||
27 | |||
28 | // Supported locales. |
||
29 | $supported = array( |
||
30 | 24 | Locales::CS, |
|
31 | Locales::CY, |
||
32 | Locales::DE, |
||
33 | Locales::EN, |
||
34 | Locales::ES, |
||
35 | Locales::FR, |
||
36 | Locales::NL, |
||
37 | Locales::SK, |
||
38 | ); |
||
39 | |||
40 | // Sub string. |
||
41 | 24 | $locale = substr( $language, 0, 2 ); |
|
42 | |||
43 | // Upper case. |
||
44 | 24 | $locale = strtoupper( $locale ); |
|
45 | |||
46 | // Is supported? |
||
47 | 24 | if ( in_array( $locale, $supported, true ) ) { |
|
48 | 23 | return $locale; |
|
49 | } |
||
50 | |||
51 | 1 | return null; |
|
52 | } |
||
54 |