Test Failed
Push — develop ( e8b058...74f259 )
by Remco
05:06
created

Integration::get_settings_fields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 50
nc 1
nop 0
dl 0
loc 74
ccs 0
cts 51
cp 0
crap 2
rs 9.0909
c 0
b 0
f 0

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\Buckaroo;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: Buckaroo integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.0
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	public function __construct() {
19
		$this->id            = 'buckaroo';
20
		$this->name          = 'Buckaroo - HTML';
21
		$this->url           = 'https://plaza.buckaroo.nl/';
22
		$this->product_url   = __( 'http://www.buckaroo-payments.com', 'pronamic_ideal' );
23
		$this->dashboard_url = 'https://plaza.buckaroo.nl/';
24
		$this->provider      = 'buckaroo';
25
		$this->supports      = array(
0 ignored issues
show
Bug Best Practice introduced by
The property supports does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
			'webhook',
27
		);
28
29
		// Actions
30
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
31
32
		if ( ! has_action( 'wp_loaded', $function ) ) {
33
			add_action( 'wp_loaded', $function );
34
		}
35
	}
36
37
	public function get_settings_fields() {
38
		$fields = array();
39
40
		// Website Key.
41
		$fields[] = array(
42
			'section'  => 'general',
43
			'filter'   => FILTER_SANITIZE_STRING,
44
			'meta_key' => '_pronamic_gateway_buckaroo_website_key',
45
			'title'    => __( 'Website Key', 'pronamic_ideal' ),
46
			'type'     => 'text',
47
			'classes'  => array( 'code' ),
48
			'tooltip'  => __( 'Website key as mentioned in the Buckaroo dashboard on the page "Profile » Website".', 'pronamic_ideal' ),
49
		);
50
51
		// Secret Key.
52
		$fields[] = array(
53
			'section'  => 'general',
54
			'filter'   => FILTER_SANITIZE_STRING,
55
			'meta_key' => '_pronamic_gateway_buckaroo_secret_key',
56
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
57
			'type'     => 'text',
58
			'classes'  => array( 'regular-text', 'code' ),
59
			'tooltip'  => __( 'Secret key as mentioned in the Buckaroo dashboardb on the page "Configuration » Secret Key for Digital Signature".', 'pronamic_ideal' ),
60
		);
61
62
		// Excluded services.
63
		$fields[] = array(
64
			'section'  => 'advanced',
65
			'filter'   => FILTER_SANITIZE_STRING,
66
			'meta_key' => '_pronamic_gateway_buckaroo_excluded_services',
67
			'title'    => __( 'Excluded services', 'pronamic_ideal' ),
68
			'type'     => 'text',
69
			'classes'  => array( 'regular-text', 'code' ),
70
			'tooltip'  => sprintf(
71
				/* translators: %s: <code>brq_exludedservices</code> */
72
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
73
				sprintf( '<code>%s</code>', 'brq_exludedservices' )
74
			),
75
		);
76
77
		// Invoice number.
78
		$fields[] = array(
79
			'section'     => 'advanced',
80
			'filter'      => FILTER_SANITIZE_STRING,
81
			'meta_key'    => '_pronamic_gateway_buckaroo_invoice_number',
82
			'title'       => __( 'Invoice number', 'pronamic_ideal' ),
83
			'type'        => 'text',
84
			'classes'     => array( 'regular-text', 'code' ),
85
			'tooltip'     => sprintf(
86
				/* translators: %s: <code>brq_invoicenumber</code> */
87
				__( 'This controls the Buckaroo %s parameter.', 'pronamic_ideal' ),
88
				sprintf( '<code>%s</code>', 'brq_invoicenumber' )
89
			),
90
			'description' => sprintf(
91
				'%s<br />%s',
92
				/* translators: %s: <code>{order_id}</code> <code>{payment_id}</code> */
93
				sprintf( __( 'Available tags: %s', 'pronamic_ideal' ), sprintf( '<code>%s</code> <code>%s</code>', '{order_id}', '{payment_id}' ) ),
94
				/* translators: %s: <code>{payment_id}</code> */
95
				sprintf( __( 'Default: <code>%s</code>', 'pronamic_ideal' ), '{payment_id}' )
96
			),
97
		);
98
99
		// Push URL.
100
		$fields[] = array(
101
			'section'  => 'feedback',
102
			'title'    => __( 'Push URL', 'pronamic_ideal' ),
103
			'type'     => 'text',
104
			'classes'  => array( 'large-text', 'code' ),
105
			'value'    => add_query_arg( 'buckaroo_push', '', home_url( '/' ) ),
106
			'readonly' => true,
107
			'tooltip'  => __( 'The Push URL as sent with each transaction to receive automatic payment status updates on.', 'pronamic_ideal' ),
108
		);
109
110
		return $fields;
111
	}
112
113
	public function get_config( $post_id ) {
114
		$config = new Config();
115
116
		$config->website_key       = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_website_key', true );
117
		$config->secret_key        = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_secret_key', true );
118
		$config->excluded_services = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_excluded_services', true );
119
		$config->invoice_number    = get_post_meta( $post_id, '_pronamic_gateway_buckaroo_invoice_number', true );
120
		$config->mode              = get_post_meta( $post_id, '_pronamic_gateway_mode', true );
0 ignored issues
show
Documentation Bug introduced by
It seems like get_post_meta($post_id, ...ic_gateway_mode', true) can also be of type false. However, the property $mode is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
121
122
		return $config;
123
	}
124
125
	/**
126
	 * Get gateway.
127
	 *
128
	 * @param int $post_id Post ID.
129
	 * @return Gateway
130
	 */
131
	public function get_gateway( $post_id ) {
132
		return new Gateway( $this->get_config( $post_id ) );
133
	}
134
}
135