Failed Conditions
Push — develop ( b71aec...4a81b8 )
by Remco
07:45
created

Integration::get_settings_fields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 63
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
c 1
b 0
f 0
dl 0
loc 63
ccs 0
cts 54
cp 0
rs 9.2
cc 1
nc 1
nop 0
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\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: OmniKassa integration
9
 * Description:
10
 * Copyright: 2005-2020 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.3
15
 * @since   1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	public function __construct() {
19
		parent::__construct();
20
21
		$this->id            = 'rabobank-omnikassa';
22
		$this->name          = 'Rabobank - OmniKassa';
23
		$this->product_url   = 'https://www.rabobank.nl/bedrijven/betalen/geld-ontvangen/rabo-omnikassa/';
24
		$this->dashboard_url = array(
25
			__( 'admin', 'pronamic_ideal' )    => 'https://dashboard.omnikassa.rabobank.nl/',
26
			__( 'download', 'pronamic_ideal' ) => 'https://download.omnikassa.rabobank.nl/',
27
		);
28
		$this->provider      = 'rabobank';
29
		$this->deprecated    = true;
0 ignored issues
show
Bug Best Practice introduced by
The property deprecated does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30
31
		// Actions
32
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
33
34
		if ( ! has_action( 'wp_loaded', $function ) ) {
35
			add_action( 'wp_loaded', $function );
36
		}
37
	}
38
39
	/**
40
	 * Get settings fields.
41
	 *
42
	 * @return array
43
	 */
44
	public function get_settings_fields() {
45
		$fields = array();
46
47
		// Merchant ID
48
		$fields[] = array(
49
			'section'  => 'general',
50
			'filter'   => FILTER_SANITIZE_STRING,
51
			'meta_key' => '_pronamic_gateway_omnikassa_merchant_id',
52
			'title'    => __( 'Merchant ID', 'pronamic_ideal' ),
53
			'type'     => 'text',
54
			'classes'  => array( 'code' ),
55
		);
56
57
		// Secret Key
58
		$fields[] = array(
59
			'section'  => 'general',
60
			'filter'   => FILTER_SANITIZE_STRING,
61
			'meta_key' => '_pronamic_gateway_omnikassa_secret_key',
62
			'title'    => __( 'Secret Key', 'pronamic_ideal' ),
63
			'type'     => 'text',
64
			'classes'  => array( 'large-text', 'code' ),
65
		);
66
67
		// Key Version
68
		$fields[] = array(
69
			'section'  => 'general',
70
			'filter'      => FILTER_SANITIZE_STRING,
71
			'meta_key'    => '_pronamic_gateway_omnikassa_key_version',
72
			'title'       => __( 'Key Version', 'pronamic_ideal' ),
73
			'type'        => 'text',
74
			'classes'     => array( 'code' ),
75
			'size'        => 5,
76
			'description' => sprintf( __( 'You can find the key version in the <a href="%s" target="_blank">OmniKassa Download Dashboard</a>.', 'pronamic_ideal' ), 'https://download.omnikassa.rabobank.nl/' ),
77
		);
78
79
		// Purchase ID
80
		$fields[] = array(
81
			'section'     => 'advanced',
82
			'filter'      => FILTER_SANITIZE_STRING,
83
			'meta_key'    => '_pronamic_gateway_omnikassa_order_id',
84
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
85
			'type'        => 'text',
86
			'classes'     => array( 'regular-text', 'code' ),
87
			'tooltip'     => sprintf(
88
				__( 'The OmniKassa %s parameter.', 'pronamic_ideal' ),
89
				sprintf( '<code>%s</code>', 'orderId' )
90
			),
91
			'description' => sprintf(
92
				'%s %s<br />%s',
93
				__( 'Available tags:', 'pronamic_ideal' ),
94
				sprintf(
95
					'<code>%s</code> <code>%s</code>',
96
					'{order_id}',
97
					'{payment_id}'
98
				),
99
				sprintf(
100
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
101
					'{payment_id}'
102
				)
103
			),
104
		);
105
106
		return $fields;
107
	}
108
109
	public function get_config( $post_id ) {
110
		$config = new Config();
111
112
		$config->merchant_id = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_merchant_id', true );
113
		$config->secret_key  = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_secret_key', true );
114
		$config->key_version = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_key_version', true );
115
		$config->order_id    = get_post_meta( $post_id, '_pronamic_gateway_omnikassa_order_id', true );
116
		$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...
117
118
		return $config;
119
	}
120
121
	/**
122
	 * Get gateway.
123
	 *
124
	 * @param int $post_id Post ID.
125
	 * @return Gateway
126
	 */
127
	public function get_gateway( $post_id ) {
128
		return new Gateway( $this->get_config( $post_id ) );
129
	}
130
}
131