Test Failed
Push — develop ( fd928b...40893b )
by Remco
04:14
created

RequestMessage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A get_document() 0 14 1
1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\MultiSafepay\XML;
4
5
use DOMDocument;
6
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Customer;
7
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Merchant;
8
use Pronamic\WordPress\Pay\Gateways\MultiSafepay\Transaction;
9
10
/**
11
 * Title: MultiSafepay Connect XML request message
12
 * Description:
13
 * Copyright: 2005-2019 Pronamic
14
 * Company: Pronamic
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.0.2
18
 * @since   1.0.0
19
 */
20
abstract class RequestMessage extends Message {
21
	/**
22
	 * Merchant.
23
	 *
24
	 * @var Merchant
25
	 */
26
	protected $merchant;
27
28
	/**
29
	 * Customer.
30
	 *
31
	 * @var Customer
32
	 */
33
	protected $customer;
34
35
	/**
36
	 * Transaction.
37
	 *
38
	 * @var Transaction
39
	 */
40
	protected $transaction;
41
42
	/**
43
	 * Get the DOM document
44
	 *
45
	 * @return DOMDocument
46
	 */
47
	protected function get_document() {
48
		$document = new DOMDocument( parent::XML_VERSION, parent::XML_ENCODING );
49
50
		// We can't disable preserve white space and format the output
51
		// this is causing 'Invalid electronic signature' errors.
52
		$document->preserveWhiteSpace = true;
53
		$document->formatOutput       = true;
54
55
		// Root.
56
		$root = $document->createElement( $this->get_name() );
57
58
		$document->appendChild( $root );
59
60
		return $document;
61
	}
62
63
	/**
64
	 * Create a string representation
65
	 *
66
	 * @return string
67
	 */
68
	public function __toString() {
69
		$document = $this->get_document();
70
71
		return $document->saveXML();
72
	}
73
}
74