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

Methods   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 156
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform_gateway_method() 0 12 3
A transform() 0 10 3
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
4
5
use Pronamic\WordPress\Pay\Core\PaymentMethods;
6
7
/**
8
 * Title: Mollie methods
9
 * Description:
10
 * Copyright: Copyright (c) 2005 - 2018
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.0
15
 * @since   1.0.0
16
 */
17
class Methods {
18
	/**
19
	 * Constant for the iDEAL method.
20
	 *
21
	 * @var string
22
	 */
23
	const IDEAL = 'ideal';
24
25
	/**
26
	 * Constant for the Credit Card method.
27
	 *
28
	 * @var string
29
	 */
30
	const CREDITCARD = 'creditcard';
31
32
	/**
33
	 * Constant for the Direct Debit method.
34
	 *
35
	 * @var string
36
	 */
37
	const DIRECT_DEBIT = 'directdebit';
38
39
	/**
40
	 * Constant for the Mister Cash method.
41
	 *
42
	 * @var string
43
	 */
44
	const MISTERCASH = 'mistercash';
45
46
	/**
47
	 * Constant for the Sofort method.
48
	 *
49
	 * @var string
50
	 */
51
	const SOFORT = 'sofort';
52
53
	/**
54
	 * Constant for the Bank transfer method.
55
	 *
56
	 * @var string
57
	 */
58
	const BANKTRANSFER = 'banktransfer';
59
60
	/**
61
	 * Constant for the Bitcoin method.
62
	 *
63
	 * @var string
64
	 */
65
	const BITCOIN = 'bitcoin';
66
67
	/**
68
	 * Constant for the PayPal method.
69
	 *
70
	 * @var string
71
	 */
72
	const PAYPAL = 'paypal';
73
74
	/**
75
	 * Constant for the Paysafecard method.
76
	 *
77
	 * @var string
78
	 */
79
	const PAYSAFECARD = 'paysafecard';
80
81
	/**
82
	 * Constant for the Gift cards method.
83
	 *
84
	 * @see https://www.mollie.com/en/giftcards
85
	 * @since 1.1.10
86
	 * @var string
87
	 */
88
	const PODIUMCADEAUKAART = 'podiumcadeaukaart';
89
90
	/**
91
	 * Constant for the KBC/CBC Payment Button method.
92
	 *
93
	 * @see https://www.mollie.com/en/kbccbc
94
	 * @since 1.1.10
95
	 * @var string
96
	 */
97
	const KBC = 'kbc';
98
99
	/**
100
	 * Constant for the Belfius Direct Net method.
101
	 *
102
	 * @see https://www.mollie.com/en/belfiusdirectnet
103
	 * @since 1.1.10
104
	 * @var string
105
	 */
106
	const BELFIUS = 'belfius';
107
108
	/**
109
	 * Payments methods map.
110
	 *
111
	 * @var array
112
	 */
113
	private static $map = array(
114
		PaymentMethods::BANK_TRANSFER           => self::BANKTRANSFER,
115
		PaymentMethods::BITCOIN                 => self::BITCOIN,
116
		PaymentMethods::CREDIT_CARD             => self::CREDITCARD,
117
		PaymentMethods::DIRECT_DEBIT            => self::DIRECT_DEBIT,
118
		PaymentMethods::DIRECT_DEBIT_BANCONTACT => self::DIRECT_DEBIT,
119
		PaymentMethods::DIRECT_DEBIT_IDEAL      => self::DIRECT_DEBIT,
120
		PaymentMethods::DIRECT_DEBIT_SOFORT     => self::DIRECT_DEBIT,
121
		PaymentMethods::BANCONTACT              => self::MISTERCASH,
122
		PaymentMethods::MISTER_CASH             => self::MISTERCASH,
123
		PaymentMethods::PAYPAL                  => self::PAYPAL,
124
		PaymentMethods::SOFORT                  => self::SOFORT,
125
		PaymentMethods::IDEAL                   => self::IDEAL,
126
		PaymentMethods::KBC                     => self::KBC,
127
		PaymentMethods::BELFIUS                 => self::BELFIUS,
128
	);
129
130
	/**
131
	 * Transform WordPress payment method to Mollie method.
132
	 *
133
	 * @since 1.1.6
134
	 *
135
	 * @param string $payment_method Payment method.
136
	 * @param mixed  $default        Default payment method.
137
	 *
138
	 * @return string
139
	 */
140
	public static function transform( $payment_method, $default = null ) {
141
		if ( ! is_scalar( $payment_method ) ) {
0 ignored issues
show
introduced by
The condition is_scalar($payment_method) is always true.
Loading history...
142
			return null;
143
		}
144
145
		if ( isset( self::$map[ $payment_method ] ) ) {
146
			return self::$map[ $payment_method ];
147
		}
148
149
		return $default;
150
	}
151
152
	/**
153
	 * Transform Mollie method to WordPress payment method.
154
	 *
155
	 * @since unreleased
156
	 *
157
	 * @param string $method Mollie method.
158
	 *
159
	 * @return string
160
	 */
161
	public static function transform_gateway_method( $method ) {
162
		if ( ! is_scalar( $method ) ) {
0 ignored issues
show
introduced by
The condition is_scalar($method) is always true.
Loading history...
163
			return null;
164
		}
165
166
		$payment_method = array_search( $method, self::$map, true );
167
168
		if ( ! $payment_method ) {
169
			return null;
170
		}
171
172
		return $payment_method;
173
	}
174
}
175