Failed Conditions
Push — develop ( 90ad45...dcb3b6 )
by Reüel
03:54
created

Settings::fields()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 81
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 81
rs 8.9818
c 0
b 0
f 0
ccs 0
cts 68
cp 0
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa;
4
5
use Pronamic\WordPress\Pay\Core\GatewaySettings;
6
7
/**
8
 * Title: iDEAL gateway settings
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.0
15
 * @since   1.0.0
16
 */
17
class Settings extends GatewaySettings {
18
	/**
19
	 * Settings constructor.
20
	 */
21
	public function __construct() {
22
		add_filter( 'pronamic_pay_gateway_sections', array( $this, 'sections' ) );
23
		add_filter( 'pronamic_pay_gateway_fields', array( $this, 'fields' ) );
24
	}
25
26
	/**
27
	 * Sections.
28
	 *
29
	 * @param array $sections Settings sections.
30
	 *
31
	 * @return array
32
	 */
33
	public function sections( array $sections ) {
34
		// OmniKassa.
35
		$sections['omnikassa'] = array(
36
			'title'   => __( 'OmniKassa', 'pronamic_ideal' ),
37
			'methods' => array( 'omnikassa' ),
38
		);
39
40
		// Advanced.
41
		$sections['omnikassa_advanced'] = array(
42
			'title'   => __( 'Advanced', 'pronamic_ideal' ),
43
			'methods' => array( 'omnikassa' ),
44
		);
45
46
		return $sections;
47
	}
48
49
	/**
50
	 * Fields.
51
	 *
52
	 * @param array $fields Settings fields.
53
	 *
54
	 * @return array
55
	 */
56
	public function fields( array $fields ) {
57
		// Merchant ID.
58
		$fields[] = array(
59
			'filter'   => FILTER_SANITIZE_STRING,
60
			'section'  => 'omnikassa',
61
			'meta_key' => '_pronamic_gateway_omnikassa_merchant_id',
62
			'title'    => __( 'Merchant ID', 'pronamic_ideal' ),
63
			'type'     => 'text',
64
			'classes'  => array( 'code' ),
65
		);
66
67
		// Secret Key..
68
		$fields[] = array(
69
			'filter'   => FILTER_SANITIZE_STRING,
70
			'section'  => 'omnikassa',
71
			'meta_key' => '_pronamic_gateway_omnikassa_secret_key',
72
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
73
			'type'     => 'text',
74
			'classes'  => array( 'large-text', 'code' ),
75
		);
76
77
		// Key Version.
78
		$fields[] = array(
79
			'filter'      => FILTER_SANITIZE_STRING,
80
			'section'     => 'omnikassa',
81
			'meta_key'    => '_pronamic_gateway_omnikassa_key_version',
82
			'title'       => __( 'Key Version', 'pronamic_ideal' ),
83
			'type'        => 'text',
84
			'classes'     => array( 'code' ),
85
			'size'        => 5,
86
			'description' => sprintf(
87
				/* translators: %s: dashboard URL */
88
				__(
89
					'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.',
90
					'pronamic_ideal'
91
				),
92
				'https://download.omnikassa.rabobank.nl/'
93
			),
94
		);
95
96
		// Transaction feedback.
97
		$fields[] = array(
98
			'section' => 'omnikassa',
99
			'title'   => __( 'Transaction feedback', 'pronamic_ideal' ),
100
			'type'    => 'description',
101
			'html'    => sprintf(
102
				'<span class="dashicons dashicons-yes"></span> %s',
103
				__( 'Payment status updates will be processed without any additional configuration.', 'pronamic_ideal' )
104
			),
105
		);
106
107
		// Purchase ID.
108
		$fields[] = array(
109
			'filter'      => FILTER_SANITIZE_STRING,
110
			'section'     => 'omnikassa_advanced',
111
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
112
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
113
			'type'        => 'text',
114
			'classes'     => array( 'regular-text', 'code' ),
115
			'tooltip'     => sprintf(
116
				/* translators: %s: <code>orderId</code> */
117
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
118
				sprintf( '<code>%s</code>', 'orderId' )
119
			),
120
			'description' => sprintf(
121
				'%s %s<br />%s',
122
				__( 'Available tags:', 'pronamic_ideal' ),
123
				sprintf(
124
					'<code>%s</code> <code>%s</code>',
125
					'{order_id}',
126
					'{payment_id}'
127
				),
128
				sprintf(
129
					/* translators: %s: {payment_id} */
130
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
131
					'{payment_id}'
132
				)
133
			),
134
		);
135
136
		return $fields;
137
	}
138
}
139