Failed Conditions
Push — develop ( edecd9...03bf69 )
by Reüel
04:19
created

Integration::get_settings_fields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 73
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 49
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 73
ccs 0
cts 60
cp 0
crap 2
rs 9.1127

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\EMS\ECommerce;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: EMS e-Commerce integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author Reüel van der Steege
14
 * @version 2.0.3
15
 * @since 1.0.0
16
 */
17
class Integration extends AbstractIntegration {
18
	public function __construct() {
19
		$this->id            = 'ems-ecommerce';
20
		$this->name          = 'EMS e-Commerce';
21
		$this->product_url   = '';
22
		$this->dashboard_url = array(
23
			__( 'test', 'pronamic_ideal' ) => 'https://test.ipg-online.com/vt/login',
24
			__( 'live', 'pronamic_ideal' ) => 'https://www.ipg-online.com/vt/login',
25
		);
26
		$this->provider      = 'ems';
27
		$this->supports      = array(
28
			'webhook',
29
			'webhook_log',
30
			'webhook_no_config',
31
		);
32
33
		$this->set_manual_url( __( 'https://www.pronamic.eu/support/how-to-connect-ems-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) );
0 ignored issues
show
Bug introduced by
The method set_manual_url() does not exist on Pronamic\WordPress\Pay\G...S\ECommerce\Integration. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
		$this->/** @scrutinizer ignore-call */ 
34
         set_manual_url( __( 'https://www.pronamic.eu/support/how-to-connect-ems-with-wordpress-via-pronamic-pay/', 'pronamic_ideal' ) );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
35
		// Actions
36
		$function = array( __NAMESPACE__ . '\Listener', 'listen' );
37
38
		if ( ! has_action( 'wp_loaded', $function ) ) {
39
			add_action( 'wp_loaded', $function );
40
		}
41
	}
42
43
	public function get_settings_fields() {
44
		$fields = array();
45
46
		// Storename.
47
		$fields[] = array(
48
			'section'  => 'general',
49
			'filter'   => FILTER_UNSAFE_RAW,
50
			'meta_key' => '_pronamic_gateway_ems_ecommerce_storename',
51
			'title'    => _x( 'Storename', 'ems', 'pronamic_ideal' ),
52
			'type'     => 'text',
53
			'classes'  => array( 'code' ),
54
		);
55
56
		// Shared secret.
57
		$fields[] = array(
58
			'section'  => 'general',
59
			'filter'   => FILTER_UNSAFE_RAW,
60
			'meta_key' => '_pronamic_gateway_ems_ecommerce_secret',
61
			'title'    => _x( 'Shared Secret', 'ems', 'pronamic_ideal' ),
62
			'type'     => 'text',
63
			'classes'  => array( 'large-text', 'code' ),
64
		);
65
66
		// Purchase ID.
67
		$fields[] = array(
68
			'section'     => 'advanced',
69
			'filter'      => array(
70
				'filter' => FILTER_SANITIZE_STRING,
71
				'flags'  => FILTER_FLAG_NO_ENCODE_QUOTES,
72
			),
73
			'meta_key'    => '_pronamic_gateway_ems_ecommerce_order_id',
74
			'title'       => __( 'Order ID', 'pronamic_ideal' ),
75
			'type'        => 'text',
76
			'classes'     => array( 'regular-text', 'code' ),
77
			'tooltip'     => sprintf(
78
				/* translators: %s: <code>{orderId}</code> */
79
				__( 'The EMS e-Commerce %s parameter.', 'pronamic_ideal' ),
80
				sprintf( '<code>%s</code>', 'orderId' )
81
			),
82
			'description' => sprintf(
83
				'%s %s<br />%s',
84
				__( 'Available tags:', 'pronamic_ideal' ),
85
				sprintf(
86
					'<code>%s</code> <code>%s</code>',
87
					'{order_id}',
88
					'{payment_id}'
89
				),
90
				sprintf(
91
					/* translators: %s: {order_id} */
92
					__( 'Default: <code>%s</code>', 'pronamic_ideal' ),
93
					'{order_id}'
94
				)
95
			),
96
		);
97
98
		// Notification URL.
99
		$fields[] = array(
100
			'section'  => 'feedback',
101
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
102
			'title'    => _x( 'Notification URL', 'EMS e-Commerce', 'pronamic_ideal' ),
103
			'type'     => 'text',
104
			'classes'  => array( 'large-text', 'code' ),
105
			'value'    => home_url( '/' ),
106
			'readonly' => true,
107
			/* translators: Translate 'notification' the same as in the EMS e-Commerce dashboard. */
108
			'tooltip'  => _x(
109
				'The Notification URL as sent with each transaction to receive automatic payment status updates on.',
110
				'EMS e-Commerce',
111
				'pronamic_ideal'
112
			),
113
		);
114
115
		return $fields;
116
	}
117
118
	public function get_config( $post_id ) {
119
		$config = new Config();
120
121
		$config->storename = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_storename', true );
122
		$config->secret    = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_secret', true );
123
		$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...
124
		$config->order_id  = get_post_meta( $post_id, '_pronamic_gateway_ems_ecommerce_order_id', true );
125
126
		return $config;
127
	}
128
129
	/**
130
	 * Get gateway.
131
	 *
132
	 * @param int $post_id Post ID.
133
	 * @return Gateway
134
	 */
135
	public function get_gateway( $post_id ) {
136
		return new Gateway( $this->get_config( $post_id ) );
137
	}
138
}
139