Test Failed
Push — develop ( ee5b51...397f1c )
by Reüel
05:20
created

DetailsInformation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 1
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Details information
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
/**
14
 * Details information
15
 *
16
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments
17
 *
18
 * @author  Reüel van der Steege
19
 * @version 1.1.0
20
 * @since   1.1.0
21
 */
22
class DetailsInformation extends ResponseObject {
23
	/**
24
	 * The value to provide in the result.
25
	 *
26
	 * @var string
27
	 */
28
	private $key;
29
30
	/**
31
	 * The type of the required input.
32
	 *
33
	 * @var string
34
	 */
35
	private $type;
36
37
	/**
38
	 * Construct action information.
39
	 */
40
	public function __construct() {
41
	}
42
43
	/**
44
	 * Get key.
45
	 *
46
	 * @return string
47
	 */
48
	public function get_key() {
49
		return $this->key;
50
	}
51
52
	/**
53
	 * Set key.
54
	 *
55
	 * @param string $key Key.
56
	 */
57
	public function set_key( $key ) {
58
		$this->key = $key;
59
	}
60
61
	/**
62
	 * Get type.
63
	 *
64
	 * @return mixed
65
	 */
66
	public function get_type() {
67
		return $this->type;
68
	}
69
70
	/**
71
	 * Set type.
72
	 *
73
	 * @param mixed $type Type.
74
	 */
75
	public function set_type( $type ) {
76
		$this->type = $type;
77
	}
78
79
	/**
80
	 * Create details information from object.
81
	 *
82
	 * @param object $object Object.
83
	 * @return DetailsInformation
84
	 * @throws \JsonSchema\Exception\ValidationException Throws validation exception when object does not contains the required properties.
85
	 */
86
	public static function from_object( $object ) {
87
		$validator = new \JsonSchema\Validator();
88
89
		$validator->validate(
90
			$object,
91
			(object) array(
92
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/details.json' ),
93
			),
94
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
95
		);
96
97
		$details = new self();
98
99
		if ( isset( $object->key ) ) {
100
			$details->set_key( $object->key );
101
		}
102
103
		if ( isset( $object->type ) ) {
104
			$details->set_type( $object->type );
105
		}
106
107
		return $details;
108
	}
109
110
	/**
111
	 * Get JSON.
112
	 *
113
	 * @return object
114
	 */
115
	public function get_json() {
116
		$properties = Util::filter_null(
117
			array(
118
				'key' => $this->get_key(),
119
				'type'    => $this->get_type(),
120
			)
121
		);
122
123
		$object = (object) $properties;
124
125
		return $object;
126
	}
127
}
128