Failed Conditions
Push — master ( cc3467...84f509 )
by Reüel
09:31 queued 01:25
created

Util   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 3
b 0
f 0
dl 0
loc 37
ccs 4
cts 10
cp 0.4
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A filter_null() 0 2 1
A is_not_null() 0 2 1
A get_payment_locale() 0 10 2
1
<?php
2
/**
3
 * Util
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use Pronamic\WordPress\Pay\Payments\Payment;
14
15
/**
16
 * Util
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.0.5
20
 * @since   1.0.0
21
 */
22
class Util {
23
	/**
24
	 * Filter null.
25
	 *
26
	 * @param array<int|string, mixed> $array Array to filter null values from.
27
	 * @return array<int|string, mixed>
28
	 */
29 16
	public static function filter_null( $array ) {
30 16
		return array_filter( $array, array( __CLASS__, 'is_not_null' ) );
31
	}
32
33
	/**
34
	 * Check if value is not null.
35
	 *
36
	 * @param mixed $value Value.
37
	 * @return boolean True if value is not null, false otherwise.
38
	 */
39 16
	private static function is_not_null( $value ) {
40 16
		return ( null !== $value );
41
	}
42
43
	/**
44
	 * Get payment country code.
45
	 *
46
	 * @param Payment $payment Payment.
47
	 * @return string
48
	 */
49
	public static function get_payment_locale( Payment $payment ) {
50
		$locale = get_locale();
51
52
		$customer = $payment->get_customer();
53
54
		if ( null !== $customer ) {
55
			$locale = $customer->get_locale();
56
		}
57
58
		return strval( $locale );
59
	}
60
}
61