ErrorParser   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 50
ccs 18
cts 20
cp 0.9
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 43 7
1
<?php
2
/**
3
 * Error parser.
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 Pronamic\WordPress\Pay\Core\XML\Security;
15
use SimpleXMLElement;
16
17
/**
18
 * Title: iDEAL Advanced v3 error parser
19
 * Description:
20
 * Copyright: 2005-2021 Pronamic
21
 * Company: Pronamic
22
 *
23
 * @author  Remco Tolsma
24
 * @version 2.0.0
25
 */
26
class ErrorParser {
27
	/**
28
	 * Parse the specified XML element into an acquirer error response
29
	 *
30
	 * @param SimpleXMLElement $xml XML.
31
	 * @return Error|null
32
	 */
33 1
	public function parse( SimpleXMLElement $xml ) {
34 1
		if ( 'Error' !== $xml->getName() ) {
35
			return null;
36
		}
37
38 1
		$error = new Error();
39
40
		// Error code.
41 1
		$code = Security::filter( $xml->errorCode );
42
43 1
		if ( null !== $code ) {
44 1
			$error->set_code( $code );
45
		}
46
47
		// Message.
48 1
		$message = Security::filter( $xml->errorMessage );
49
50 1
		if ( null !== $message ) {
51 1
			$error->set_message( $message );
52
		}
53
54
		// Detail.
55 1
		$detail = Security::filter( $xml->errorDetail );
56
57 1
		if ( null !== $detail ) {
58 1
			$error->set_detail( $detail );
59
		}
60
61
		// Suggested action.
62 1
		$suggested_action = Security::filter( $xml->suggestedAction );
63
64 1
		if ( null !== $suggested_action ) {
65
			$error->set_suggested_action( $suggested_action );
66
		}
67
68
		// Consumer message.
69 1
		$consumer_message = Security::filter( $xml->consumerMessage );
70
71 1
		if ( null !== $consumer_message ) {
72 1
			$error->set_consumer_message( $consumer_message );
73
		}
74
75 1
		return $error;
76
	}
77
}
78