RedirectInformation   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Test Coverage

Coverage 80.65%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 118
ccs 25
cts 31
cp 0.8065
rs 10
c 3
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A set_data() 0 2 1
A get_url() 0 2 1
A __construct() 0 3 1
A get_method() 0 2 1
A get_data() 0 2 1
A from_object() 0 21 2
A get_json() 0 11 1
1
<?php
2
/**
3
 * Redirect 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
 * Redirect information
15
 *
16
 * @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments
17
 *
18
 * @author  Remco Tolsma
19
 * @version 1.0.0
20
 * @since   1.0.0
21
 */
22
class RedirectInformation extends ResponseObject {
23
	/**
24
	 * When the redirect URL must be accessed via POST, use this data to post to the redirect URL.
25
	 *
26
	 * @var object|null
27
	 */
28
	private $data;
29
30
	/**
31
	 * The web method that you must use to access the redirect URL.
32
	 *
33
	 * Possible values: GET, POST.
34
	 *
35
	 * @var string
36
	 */
37
	private $method;
38
39
	/**
40
	 * The URL, to which you must redirect a shopper to complete a payment
41
	 *
42
	 * @var string
43
	 */
44
	private $url;
45
46
	/**
47
	 * Construct redirect information.
48
	 *
49
	 * @param string $method Method.
50
	 * @param string $url    URL.
51
	 */
52 6
	public function __construct( $method, $url ) {
53 6
		$this->method = $method;
54 6
		$this->url    = $url;
55 6
	}
56
57
	/**
58
	 * Get data.
59
	 *
60
	 * @return object|null
61
	 */
62 2
	public function get_data() {
63 2
		return $this->data;
64
	}
65
66
	/**
67
	 * Set data.
68
	 *
69
	 * @param object|null $data Data.
70
	 * @return void
71
	 */
72 2
	public function set_data( $data ) {
73 2
		$this->data = $data;
74 2
	}
75
76
	/**
77
	 * Get method.
78
	 *
79
	 * @return string
80
	 */
81 5
	public function get_method() {
82 5
		return $this->method;
83
	}
84
85
	/**
86
	 * Get URL.
87
	 *
88
	 * @return string
89
	 */
90 4
	public function get_url() {
91 4
		return $this->url;
92
	}
93
94
	/**
95
	 * Create redirect information from object.
96
	 *
97
	 * @param object $object Object.
98
	 * @return RedirectInformation
99
	 * @throws \JsonSchema\Exception\ValidationException Throws validation exception when object does not contains the required properties.
100
	 */
101 4
	public static function from_object( $object ) {
102 4
		$validator = new \JsonSchema\Validator();
103
104 4
		$validator->validate(
105 4
			$object,
106
			(object) array(
107 4
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/redirect.json' ),
108
			),
109 4
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
110
		);
111
112 4
		$redirect = new self(
113 4
			$object->method,
114 4
			$object->url
115
		);
116
117 4
		if ( isset( $object->data ) ) {
118 1
			$redirect->set_data( $object->data );
119
		}
120
121 4
		return $redirect;
122
	}
123
124
	/**
125
	 * Get JSON.
126
	 *
127
	 * @return object
128
	 */
129
	public function get_json() {
130
		$properties = Util::filter_null(
131
			array(
132
				'method' => $this->get_method(),
133
				'url'    => $this->get_url(),
134
			)
135
		);
136
137
		$object = (object) $properties;
138
139
		return $object;
140
	}
141
}
142