Passed
Push — master ( bba4c5...886ed1 )
by Remco
04:49 queued 02:31
created

Pronamic_WP_Pay_Mollie_LocaleHelper::transform()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 9.2
cc 2
eloc 11
nc 2
nop 1
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
4
5
/**
6
 * Title: Mollie locale helper
7
 * Description:
8
 * Copyright: Copyright (c) 2005 - 2018
9
 * Company: Pronamic
10
 *
11
 * @author  Remco Tolsma
12
 * @version 2.0.0
13
 * @since   1.0.0
14
 */
15
class LocaleHelper {
16
	/**
17
	 * Get Mollie locale by the specified WordPress locale.
18
	 *
19
	 * @return string|null
20
	 */
21
	public static function transform( $locale ) {
22
		// Supported locales
23
		$supported = array(
24
			Locales::DE,
25
			Locales::EN,
26
			Locales::FR,
27
			Locales::ES,
28
			Locales::NL,
29
		);
30
31
		// Sub string
32
		$locale = substr( $locale, 0, 2 );
33
34
		// Lower case
35
		$locale = strtolower( $locale );
36
37
		// Is supported?
38
		if ( in_array( $locale, $supported, true ) ) {
39
			return $locale;
40
		}
41
42
		return null;
43
	}
44
}
45