Issues (9)

src/LocaleHelper.php (1 issue)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa;
4
5
/**
6
 * Title: OmniKassa locale helper
7
 * Description:
8
 * Copyright: 2005-2020 Pronamic
9
 * Company: Pronamic
10
 *
11
 * @author  Remco Tolsma
12
 * @version 2.0.3
13
 * @since   1.1.3
14
 */
15
class LocaleHelper {
16
	/**
17
	 * Get OmniKassa locale for the specified language.
18
	 *
19
	 * @param string $language Language to transform to OmniKassa locale.
20
	 *
21
	 * @return string|null
22
	 */
23 24
	public static function transform( $language ) {
24 24
		if ( ! is_string( $language ) ) {
0 ignored issues
show
The condition is_string($language) is always true.
Loading history...
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
	}
53
}
54