Test Failed
Push — develop ( 085e16...ff8d7c )
by Reüel
03:33
created

DirectTransactionRequestMessage::get_document()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 81
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 56
nc 2
nop 0
dl 0
loc 81
rs 8.9599
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\MultiSafepay\Connect\XML;
4
5
use Pronamic\WordPress\Pay\Core\XML\Util as XML_Util;
6
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\Customer;
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\GatewayInfo;
8
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\Merchant;
9
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Connect\Transaction;
10
11
/**
12
 * Title: MultiSafepay Connect XML direct transaction request message
13
 * Description:
14
 * Copyright: 2005-2019 Pronamic
15
 * Company: Pronamic
16
 *
17
 * @author  Remco Tolsma
18
 * @version 2.0.2
19
 * @since   1.2.0
20
 */
21
class DirectTransactionRequestMessage extends RequestMessage {
22
	/**
23
	 * The document element name
24
	 *
25
	 * @var string
26
	 */
27
	const NAME = 'directtransaction';
28
29
	/**
30
	 * Gateway info.
31
	 *
32
	 * @var GatewayInfo
33
	 */
34
	private $gateway_info;
35
36
	/**
37
	 * Constructs and initialize an directory response message
38
	 *
39
	 * @param Merchant    $merchant     Merchant.
40
	 * @param Customer    $customer     Customer.
41
	 * @param Transaction $transaction  Transaction.
42
	 * @param GatewayInfo $gateway_info Gateway info.
43
	 */
44
	public function __construct( Merchant $merchant, Customer $customer, Transaction $transaction, GatewayInfo $gateway_info = null ) {
45
		parent::__construct( self::NAME );
46
47
		$this->merchant     = $merchant;
0 ignored issues
show
Documentation Bug introduced by
It seems like $merchant of type Pronamic\WordPress\Pay\G...afepay\Connect\Merchant is incompatible with the declared type Pronamic\WordPress\Pay\G...ay\Connect\XML\Merchant of property $merchant.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
48
		$this->customer     = $customer;
0 ignored issues
show
Documentation Bug introduced by
It seems like $customer of type Pronamic\WordPress\Pay\G...afepay\Connect\Customer is incompatible with the declared type Pronamic\WordPress\Pay\G...ay\Connect\XML\Customer of property $customer.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
		$this->transaction  = $transaction;
0 ignored issues
show
Documentation Bug introduced by
It seems like $transaction of type Pronamic\WordPress\Pay\G...pay\Connect\Transaction is incompatible with the declared type Pronamic\WordPress\Pay\G...Connect\XML\Transaction of property $transaction.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
		$this->gateway_info = $gateway_info;
51
	}
52
53
	/**
54
	 * Get document
55
	 *
56
	 * @see Pronamic_Gateways_IDealAdvancedV3_XML_RequestMessage::get_document()
57
	 */
58
	public function get_document() {
59
		$document = parent::get_document();
60
61
		// Merchant.
62
		$merchant = XML_Util::add_element( $document, $document->documentElement, 'merchant' );
63
64
		XML_Util::add_elements(
65
			$document,
66
			$merchant,
67
			array(
68
				'account'          => $this->merchant->account,
69
				'site_id'          => $this->merchant->site_id,
70
				'site_secure_code' => $this->merchant->site_secure_code,
71
				'notification_url' => $this->merchant->notification_url,
72
				'redirect_url'     => $this->merchant->redirect_url,
73
				'cancel_url'       => $this->merchant->cancel_url,
74
				'close_window'     => $this->merchant->close_window,
75
			)
76
		);
77
78
		// Customer.
79
		$customer = XML_Util::add_element( $document, $document->documentElement, 'customer' );
80
81
		XML_Util::add_elements(
82
			$document,
83
			$customer,
84
			array(
85
				'locale'      => $this->customer->locale,
86
				'ipaddress'   => $this->customer->ip_address,
87
				'forwardedip' => $this->customer->forwarded_ip,
88
				'firstname'   => $this->customer->first_name,
89
				'lastname'    => $this->customer->last_name,
90
				'address1'    => $this->customer->address_1,
91
				'address2'    => $this->customer->address_2,
92
				'housenumber' => $this->customer->house_number,
93
				'zipcode'     => $this->customer->zip_code,
94
				'city'        => $this->customer->city,
95
				'country'     => $this->customer->country,
96
				'phone'       => $this->customer->phone,
97
				'email'       => $this->customer->email,
98
			)
99
		);
100
101
		// Transaction.
102
		$transaction = XML_Util::add_element( $document, $document->documentElement, 'transaction' );
103
104
		XML_Util::add_elements(
105
			$document,
106
			$transaction,
107
			array(
108
				'id'          => $this->transaction->id,
109
				'currency'    => $this->transaction->currency,
110
				'amount'      => $this->transaction->amount,
111
				'description' => $this->transaction->description,
112
				'var1'        => $this->transaction->var1,
113
				'var2'        => $this->transaction->var2,
114
				'var3'        => $this->transaction->var3,
115
				'items'       => $this->transaction->items,
116
				'manual'      => $this->transaction->manual,
117
				'gateway'     => $this->transaction->gateway,
118
				'daysactive'  => $this->transaction->days_active,
119
			)
120
		);
121
122
		// Gateway info.
123
		if ( $this->gateway_info ) {
124
			$gateway_info = XML_Util::add_element( $document, $document->documentElement, 'gatewayinfo' );
125
126
			XML_Util::add_elements(
127
				$document,
128
				$gateway_info,
129
				array(
130
					'issuerid' => $this->gateway_info->issuer_id,
131
				)
132
			);
133
		}
134
135
		// Signature.
136
		XML_Util::add_element( $document, $document->documentElement, 'signature', $this->signature );
0 ignored issues
show
Bug Best Practice introduced by
The property signature does not exist on Pronamic\WordPress\Pay\G...ansactionRequestMessage. Did you maybe forget to declare it?
Loading history...
137
138
		return $document;
139
	}
140
}
141