Passed
Push — main ( 061772...28b955 )
by Remco
07:49 queued 12s
created

RedirectDetails   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A from_json() 0 23 3
1
<?php
2
/**
3
 * Redirect Details
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2020 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
/**
14
 * Redirect Details
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.0.0
18
 * @since   1.0.0
19
 */
20
class RedirectDetails {
21
	/**
22
	 * POST or GET (depends on brand used). The default value is POST.
23
	 *
24
	 * @var string|null
25
	 */
26
	public $method;
27
28
	/**
29
	 * URL including the query string to which your customer is redirected (depends on brand used).
30
	 *
31
	 * @var string|null
32
	 */
33
	public $url;
34
35
	/**
36
	 * From JSON.
37
	 *
38
	 * @link https://github.com/WordPress/wp-notify/blob/develop/includes/JsonUnserializable.php
39
	 * @param object $object Object.
40
	 * @return self
41
	 * @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid.
42
	 */
43 2
	public static function from_json( $object ) {
44 2
		$validator = new \JsonSchema\Validator();
45
46 2
		$validator->validate(
47 2
			$object,
48
			(object) array(
49 2
				'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/redirect.json' ),
50
			),
51 2
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
52
		);
53
54 2
		$redirect = new self();
55
56 2
		if ( \property_exists( $object, 'method' ) ) {
57 2
			$redirect->method = $object->method;
58
		}
59
60 2
		if ( \property_exists( $object, 'url' ) ) {
61 2
			$redirect->url = $object->url;
62
		}
63
64 2
		return $redirect;
65
	}
66
}
67