PaymentMethod   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 84
ccs 23
cts 23
cp 1
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A set_details() 0 2 1
A get_details() 0 2 1
A from_object() 0 20 2
A get_type() 0 2 1
1
<?php
2
/**
3
 * Payment method
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use JsonSchema\Constraints\Constraint;
14
use JsonSchema\Exception\ValidationException;
15
use JsonSchema\Validator;
16
17
/**
18
 * Payment method
19
 *
20
 * @author  Remco Tolsma
21
 * @version 1.0.5
22
 * @since   1.0.0
23
 */
24
class PaymentMethod extends ResponseObject {
25
	/**
26
	 * Type.
27
	 *
28
	 * @var string|null
29
	 */
30
	private $type;
31
32
	/**
33
	 * Details.
34
	 *
35
	 * @var array<int, object>|null
36
	 */
37
	private $details;
38
39
	/**
40
	 * Construct a payment method.
41
	 *
42
	 * @param object $payment_method_object Original object.
43
	 */
44 7
	public function __construct( $payment_method_object ) {
45
		// Set type.
46 7
		if ( isset( $payment_method_object->type ) ) {
47 7
			$this->type = $payment_method_object->type;
48
		}
49
50 7
		$this->set_original_object( $payment_method_object );
51 7
	}
52
53
	/**
54
	 * Get type.
55
	 *
56
	 * @return string|null
57
	 */
58 2
	public function get_type() {
59 2
		return $this->type;
60
	}
61
62
	/**
63
	 * Get details.
64
	 *
65
	 * @return array<int, object>|null
66
	 */
67 1
	public function get_details() {
68 1
		return $this->details;
69
	}
70
71
	/**
72
	 * Set details.
73
	 *
74
	 * @param array<int, object> $details Details.
75
	 * @return void
76
	 */
77 3
	public function set_details( $details ) {
78 3
		$this->details = $details;
79 3
	}
80
81
	/**
82
	 * Create payment method from object.
83
	 *
84
	 * @param object $object Object.
85
	 * @return PaymentMethod
86
	 * @throws ValidationException Throws JSON schema validation exception when JSON is invalid.
87
	 */
88 2
	public static function from_object( $object ) {
89 2
		$validator = new Validator();
90
91 2
		$validator->validate(
92 2
			$object,
93
			(object) array(
94 2
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-method.json' ),
95
			),
96 2
			Constraint::CHECK_MODE_EXCEPTIONS
97
		);
98
99 2
		$payment_method = new self( $object );
100
101 2
		if ( isset( $object->details ) ) {
102 2
			$payment_method->set_details( $object->details );
103
		}
104
105 2
		$payment_method->set_original_object( $object );
106
107 2
		return $payment_method;
108
	}
109
}
110