AcquirerErrorResMessage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 44
ccs 0
cts 12
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 15 2
A __construct() 0 2 1
1
<?php
2
/**
3
 * Acquirer error response message.
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3\XML;
12
13
use Pronamic\WordPress\Pay\Gateways\IDealAdvancedV3\Error;
14
use SimpleXMLElement;
15
16
/**
17
 * Title: iDEAL error response XML message
18
 * Description:
19
 * Copyright: 2005-2021 Pronamic
20
 * Company: Pronamic
21
 *
22
 * @author  Remco Tolsma
23
 * @version 2.0.0
24
 */
25
class AcquirerErrorResMessage extends ResponseMessage {
26
	/**
27
	 * The document element name
28
	 *
29
	 * @var string
30
	 */
31
	const NAME = 'AcquirerErrorRes';
32
33
	/**
34
	 * The error within this response message
35
	 *
36
	 * @var Error
37
	 */
38
	public $error;
39
40
	/**
41
	 * Constructs and initialize an error response message
42
	 */
43
	final public function __construct() {
44
		parent::__construct( self::NAME );
45
	}
46
47
	/**
48
	 * Parse the specified XML into an directory response message object
49
	 *
50
	 * @param SimpleXMLElement $xml XML.
51
	 * @return AcquirerErrorResMessage
52
	 * @throws \Exception Throws exception on failed error parsing.
53
	 */
54
	public static function parse( SimpleXMLElement $xml ) {
55
		$message = self::parse_create_date( $xml, new static() );
56
57
		// Parse error.
58
		$parser = new ErrorParser();
59
60
		$error = $parser->parse( $xml->Error );
61
62
		if ( null === $error ) {
63
			throw new \Exception( 'Failed to parse error response.' );
64
		}
65
66
		$message->error = $error;
67
68
		return $message;
69
	}
70
}
71