Passed
Push — master ( 99a753...df0863 )
by Remco
19:34 queued 09:07
created

PaymentBrands::transform()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Payment brands.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
use Pronamic\WordPress\Pay\Core\PaymentMethods;
14
15
/**
16
 * Payment brands.
17
 *
18
 * @author  Remco Tolsma
19
 * @version 2.1.0
20
 * @since   1.0.0
21
 */
22
class PaymentBrands {
23
	/**
24
	 * Payment brand 'IDEAL'.
25
	 *
26
	 * @var string
27
	 */
28
	const IDEAL = 'IDEAL';
29
30
	/**
31
	 * Payment brand 'AFTERPAY'.
32
	 *
33
	 * @var string
34
	 */
35
	const AFTERPAY = 'AFTERPAY';
36
37
	/**
38
	 * Payment brand 'PAYPAL'.
39
	 *
40
	 * @var string
41
	 */
42
	const PAYPAL = 'PAYPAL';
43
44
	/**
45
	 * Payment brand 'MASTERCARD'.
46
	 *
47
	 * @var string
48
	 */
49
	const MASTERCARD = 'MASTERCARD';
50
51
	/**
52
	 * Payment brand 'VISA'.
53
	 *
54
	 * @var string
55
	 */
56
	const VISA = 'VISA';
57
58
	/**
59
	 * Payment brand 'BANCONTACT'.
60
	 *
61
	 * @var string
62
	 */
63
	const BANCONTACT = 'BANCONTACT';
64
65
	/**
66
	 * Payment brand 'MAESTRO'.
67
	 *
68
	 * @var string
69
	 */
70
	const MAESTRO = 'MAESTRO';
71
72
	/**
73
	 * Payment brand 'V_PAY'.
74
	 *
75
	 * @var string
76
	 */
77
	const V_PAY = 'V_PAY';
78
79
	/**
80
	 * Payment brand 'CARDS'.
81
	 *
82
	 * The CARDS value ensures that the consumer can choose between payment methods:
83
	 * MASTERCARD, VISA, BANCONTACT, MAESTRO and V_PAY.
84
	 *
85
	 * Dutch: De waarde CARDS zorgt ervoor dat de consument kan kiezen uit de betaalmethoden:
86
	 * MASTERCARD, VISA, BANCONTACT, MAESTRO en V_PAY.
87
	 *
88
	 * @var string
89
	 */
90
	const CARDS = 'CARDS';
91
92
	/**
93
	 * Map payment methods to payment brands.
94
	 *
95
	 * @var array
96
	 */
97
	private static $map = array(
98
		PaymentMethods::AFTERPAY    => self::AFTERPAY,
99
		PaymentMethods::BANCONTACT  => self::BANCONTACT,
100
		PaymentMethods::CREDIT_CARD => self::CARDS,
101
		PaymentMethods::IDEAL       => self::IDEAL,
102
		PaymentMethods::MAESTRO     => self::MAESTRO,
103
		PaymentMethods::PAYPAL      => self::PAYPAL,
104
	);
105
106
	/**
107
	 * Transform WordPress payment method to OmniKassa method.
108
	 *
109
	 * @since 1.0.0
110
	 *
111
	 * @param string|null $payment_method Payment method.
112
	 * @param mixed       $default        Default payment method.
113
	 *
114
	 * @return string|null
115
	 */
116 5
	public static function transform( $payment_method, $default = null ) {
117 5
		if ( ! is_scalar( $payment_method ) ) {
118
			return null;
119
		}
120
121 5
		if ( isset( self::$map[ $payment_method ] ) ) {
122 4
			return self::$map[ $payment_method ];
123
		}
124
125 1
		return $default;
126
	}
127
}
128