Failed Conditions
Push — develop ( 3861b4...1ec521 )
by Reüel
07:46
created

LocaleHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
eloc 31
dl 0
loc 51
c 0
b 0
f 0
ccs 9
cts 10
cp 0.9
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 43 3
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
4
5
/**
6
 * Title: Mollie locale helper
7
 * Description:
8
 * Copyright: 2005-2019 Pronamic
9
 * Company: Pronamic
10
 *
11
 * @author  Remco Tolsma
12
 * @version 2.1.0
13
 * @since   1.0.0
14
 */
15
class LocaleHelper {
16
	/**
17
	 * Get Mollie locale by the specified WordPress locale.
18
	 *
19
	 * @param string $locale Locale string (en_US) to transform to Mollie locale.
20
	 *
21
	 * @return string|null
22
	 */
23 11
	public static function transform( $locale ) {
24 11
		if ( ! is_string( $locale ) ) {
0 ignored issues
show
introduced by
The condition is_string($locale) is always true.
Loading history...
25
			return null;
26
		}
27
28
		// Supported locales.
29
		$supported = array(
30 11
			Locales::EN_US,
31
			Locales::NL_NL,
32
			Locales::NL_BE,
33
			Locales::FR_FR,
34
			Locales::FR_BE,
35
			Locales::DE_DE,
36
			Locales::DE_AT,
37
			Locales::DE_CH,
38
			Locales::ES_ES,
39
			Locales::CA_ES,
40
			Locales::PT_PT,
41
			Locales::IT_IT,
42
			Locales::NB_NO,
43
			Locales::SV_SE,
44
			Locales::FI_FI,
45
			Locales::DA_DK,
46
			Locales::IS_IS,
47
			Locales::HU_HU,
48
			Locales::PL_PL,
49
			Locales::LV_LV,
50
			Locales::LT_LT,
51
		);
52
53
		// Lower case.
54 11
		$locale = strtolower( $locale );
55
56
		// Is supported?
57 11
		$supported_lowercase = array_map( 'strtolower', $supported );
58
59 11
		$search = array_search( $locale, $supported_lowercase, true );
60
61 11
		if ( false !== $search ) {
62 3
			return $supported[ $search ];
63
		}
64
65 8
		return null;
66
	}
67
}
68