Test Failed
Push — develop ( a475dd...4649db )
by Remco
04:18
created

Integration::get_gateway()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay;
4
5
use Pronamic\WordPress\Pay\Gateways\Common\AbstractIntegration;
6
7
/**
8
 * Title: MultiSafepay Connect integration
9
 * Description:
10
 * Copyright: 2005-2019 Pronamic
11
 * Company: Pronamic
12
 *
13
 * @author  Remco Tolsma
14
 * @version 2.0.2
15
 * @since   1.2.6
16
 */
17
class Integration extends AbstractIntegration {
18
	/**
19
	 * Integration constructor.
20
	 */
21
	public function __construct() {
22
		$this->id            = 'multisafepay-connect';
23
		$this->name          = 'MultiSafepay - Connect';
24
		$this->url           = 'http://www.multisafepay.com/';
25
		$this->product_url   = __( 'http://www.multisafepay.com/', 'pronamic_ideal' );
26
		$this->dashboard_url = 'https://merchant.multisafepay.com/';
27
		$this->provider      = 'multisafepay';
28
		$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...
29
			'payment_status_request',
30
			'webhook',
31
			'webhook_no_config',
32
		);
33
	}
34
35
	public function get_settings_fields() {
36
		$fields = array();
37
38
		// Account ID
39
		$fields[] = array(
40
			'section'  => 'general',
41
			'filter'   => FILTER_SANITIZE_STRING,
42
			'meta_key' => '_pronamic_gateway_multisafepay_account_id',
43
			'title'    => __( 'Account ID', 'pronamic_ideal' ),
44
			'type'     => 'text',
45
			'classes'  => array( 'code' ),
46
			'tooltip'  => sprintf(
47
				'%s %s.',
48
				__( 'Account ID', 'pronamic_ideal' ),
49
				/* translators: %s: MultiSafepay */
50
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
51
			),
52
		);
53
54
		// Site ID
55
		$fields[] = array(
56
			'section'  => 'general',
57
			'filter'   => FILTER_SANITIZE_STRING,
58
			'meta_key' => '_pronamic_gateway_multisafepay_site_id',
59
			'title'    => __( 'Site ID', 'pronamic_ideal' ),
60
			'type'     => 'text',
61
			'classes'  => array( 'code' ),
62
			'tooltip'  => sprintf(
63
				'%s %s.',
64
				__( 'Site ID', 'pronamic_ideal' ),
65
				/* translators: %s: MultiSafepay */
66
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
67
			),
68
		);
69
70
		// Site Security Code
71
		$fields[] = array(
72
			'section'  => 'general',
73
			'filter'   => FILTER_SANITIZE_STRING,
74
			'meta_key' => '_pronamic_gateway_multisafepay_site_code',
75
			'title'    => __( 'Site Security Code', 'pronamic_ideal' ),
76
			'type'     => 'text',
77
			'classes'  => array( 'code' ),
78
			'tooltip'  => sprintf(
79
				'%s %s.',
80
				__( 'Site Security Code', 'pronamic_ideal' ),
81
				/* translators: %s: MultiSafepay */
82
				sprintf( __( 'as mentioned in the %s dashboard', 'pronamic_ideal' ), __( 'MultiSafepay', 'pronamic_ideal' ) )
83
			),
84
		);
85
86
		return $fields;
87
	}
88
89
	/**
90
	 * Get config.
91
	 *
92
	 * @param $post_id
93
	 *
94
	 * @return Config
95
	 */
96
	public function get_config( $post_id ) {
97
		$config = new Config();
98
99
		$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...
100
		$config->account_id = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_account_id', true );
101
		$config->site_id    = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_site_id', true );
102
		$config->site_code  = get_post_meta( $post_id, '_pronamic_gateway_multisafepay_site_code', true );
103
104
		if ( Gateway::MODE_TEST === $config->mode ) {
105
			$config->api_url = MultiSafepay::API_TEST_URL;
106
		} else {
107
			$config->api_url = MultiSafepay::API_PRODUCTION_URL;
108
		}
109
110
		return $config;
111
	}
112
113
	/**
114
	 * Get gateway.
115
	 *
116
	 * @param int $post_id Post ID.
117
	 * @return Gateway
118
	 */
119
	public function get_gateway( $post_id ) {
120
		return new Gateway( $this->get_config( $post_id ) );
121
	}
122
}
123