ResponseHeader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 47
rs 10
ccs 12
cts 12
cp 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A from_json() 0 13 1
A get_request_timestamp() 0 2 1
A __construct() 0 2 1
1
<?php
2
/**
3
 * Response Header
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 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
 * Response Header
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.1.0
18
 * @since   1.0.0
19
 */
20
class ResponseHeader {
21
	/**
22
	 * The combined date and time in UTC (ISO8601).
23
	 *
24
	 * @var string
25
	 */
26
	private $request_timestamp;
27
28
	/**
29
	 * Construct and initialize request header.
30
	 *
31
	 * @param string $timestamp Request timestamp.
32
	 */
33 5
	public function __construct( $timestamp ) {
34 5
		$this->request_timestamp = $timestamp;
35 5
	}
36
37
	/**
38
	 * From JSON.
39
	 *
40
	 * @link https://github.com/WordPress/wp-notify/blob/develop/includes/JsonUnserializable.php
41
	 * @param object $object Object.
42
	 * @return self
43
	 * @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid.
44
	 */
45 3
	public static function from_json( $object ) {
46 3
		$validator = new \JsonSchema\Validator();
47
48 3
		$validator->validate(
49 3
			$object,
50
			(object) array(
51 3
				'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/response-header.json' ),
52
			),
53 3
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
54
		);
55
56
        /* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
57 3
		return new self( $object->requestTimestamp );
58
	}
59
60
	/**
61
	 * Get request timestamp.
62
	 *
63
	 * @return string
64
	 */
65 1
	public function get_request_timestamp() {
66 1
		return $this->request_timestamp;
67
	}
68
}
69