Methods   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 179
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 46
c 6
b 0
f 0
dl 0
loc 179
ccs 15
cts 15
cp 1
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform_gateway_method() 0 12 3
A transform() 0 14 4
1
<?php
2
/**
3
 * Mollie methods.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
use Pronamic\WordPress\Pay\Core\PaymentMethods;
14
15
/**
16
 * Title: Mollie methods
17
 * Description:
18
 * Copyright: 2005-2022 Pronamic
19
 * Company: Pronamic
20
 *
21
 * @author  Remco Tolsma
22
 * @version 2.0.9
23
 * @since   1.0.0
24
 */
25
class Methods {
26
	/**
27
	 * Constant for the Apple Pay method.
28
	 *
29
	 * @var string
30
	 */
31
	const APPLE_PAY = 'applepay';
32
33
	/**
34
	 * Constant for the Bancontact method.
35
	 *
36
	 * @var string
37
	 */
38
	const BANCONTACT = 'bancontact';
39
40
	/**
41
	 * Constant for the iDEAL method.
42
	 *
43
	 * @var string
44
	 */
45
	const IDEAL = 'ideal';
46
47
	/**
48
	 * Constant for the Credit Card method.
49
	 *
50
	 * @var string
51
	 */
52
	const CREDITCARD = 'creditcard';
53
54
	/**
55
	 * Constant for the Direct Debit method.
56
	 *
57
	 * @var string
58
	 */
59
	const DIRECT_DEBIT = 'directdebit';
60
61
	/**
62
	 * Constant for the Sofort method.
63
	 *
64
	 * @var string
65
	 */
66
	const SOFORT = 'sofort';
67
68
	/**
69
	 * Constant for the Bank transfer method.
70
	 *
71
	 * @var string
72
	 */
73
	const BANKTRANSFER = 'banktransfer';
74
75
	/**
76
	 * Constant for the EPS method.
77
	 *
78
	 * @var string
79
	 */
80
	const EPS = 'eps';
81
82
	/**
83
	 * Constant for the Giropay method.
84
	 *
85
	 * @var string
86
	 */
87
	const GIROPAY = 'giropay';
88
89
	/**
90
	 * Constant for the PayPal method.
91
	 *
92
	 * @var string
93
	 */
94
	const PAYPAL = 'paypal';
95
96
	/**
97
	 * Constant for the Paysafecard method.
98
	 *
99
	 * @var string
100
	 */
101
	const PAYSAFECARD = 'paysafecard';
102
103
	/**
104
	 * Constant for the Gift cards method.
105
	 *
106
	 * @link https://www.mollie.com/en/giftcards
107
	 * @since 1.1.10
108
	 * @var string
109
	 */
110
	const PODIUMCADEAUKAART = 'podiumcadeaukaart';
111
112
	/**
113
	 * Constant for the Przelewy24 method.
114
	 *
115
	 * @var string
116
	 */
117
	const PRZELEWY24 = 'przelewy24';
118
119
	/**
120
	 * Constant for the KBC/CBC Payment Button method.
121
	 *
122
	 * @link https://www.mollie.com/en/kbccbc
123
	 * @since 1.1.10
124
	 * @var string
125
	 */
126
	const KBC = 'kbc';
127
128
	/**
129
	 * Constant for the Belfius Direct Net method.
130
	 *
131
	 * @link https://www.mollie.com/en/belfiusdirectnet
132
	 * @since 1.1.10
133
	 * @var string
134
	 */
135
	const BELFIUS = 'belfius';
136
137
	/**
138
	 * Payments methods map.
139
	 *
140
	 * @var array<string>
141
	 */
142
	private static $map = array(
143
		PaymentMethods::APPLE_PAY               => self::APPLE_PAY,
144
		PaymentMethods::BANCONTACT              => self::BANCONTACT,
145
		PaymentMethods::BANK_TRANSFER           => self::BANKTRANSFER,
146
		PaymentMethods::CREDIT_CARD             => self::CREDITCARD,
147
		PaymentMethods::DIRECT_DEBIT            => self::DIRECT_DEBIT,
148
		PaymentMethods::DIRECT_DEBIT_BANCONTACT => self::DIRECT_DEBIT,
149
		PaymentMethods::DIRECT_DEBIT_IDEAL      => self::DIRECT_DEBIT,
150
		PaymentMethods::DIRECT_DEBIT_SOFORT     => self::DIRECT_DEBIT,
151
		PaymentMethods::EPS                     => self::EPS,
152
		PaymentMethods::GIROPAY                 => self::GIROPAY,
153
		PaymentMethods::PAYPAL                  => self::PAYPAL,
154
		PaymentMethods::PRZELEWY24              => self::PRZELEWY24,
155
		PaymentMethods::SOFORT                  => self::SOFORT,
156
		PaymentMethods::IDEAL                   => self::IDEAL,
157
		PaymentMethods::KBC                     => self::KBC,
158
		PaymentMethods::BELFIUS                 => self::BELFIUS,
159
	);
160
161
	/**
162
	 * Transform WordPress payment method to Mollie method.
163
	 *
164
	 * @since 1.1.6
165
	 *
166
	 * @param string|null $payment_method Payment method.
167
	 * @param mixed       $default        Default payment method.
168
	 * @return string|null
169
	 */
170 15
	public static function transform( $payment_method, $default = null ) {
171 15
		if ( ! \is_scalar( $payment_method ) ) {
172 2
			return null;
173
		}
174
175 13
		if ( isset( self::$map[ $payment_method ] ) ) {
176 9
			return self::$map[ $payment_method ];
177
		}
178
179 4
		if ( ! empty( $default ) ) {
180 1
			return $default;
181
		}
182
183 3
		return null;
184
	}
185
186
	/**
187
	 * Transform Mollie method to WordPress payment method.
188
	 *
189
	 * @param string|null $method Mollie method.
190
	 * @return string|null
191
	 */
192 16
	public static function transform_gateway_method( $method ) {
193 16
		if ( ! \is_scalar( $method ) ) {
194 2
			return null;
195
		}
196
197 14
		$payment_method = \array_search( $method, self::$map, true );
198
199 14
		if ( false === $payment_method ) {
200 5
			return null;
201
		}
202
203 11
		return \strval( $payment_method );
204
	}
205
}
206