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

ResponseHeader::from_json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 14
loc 14
ccs 7
cts 7
cp 1
crap 1
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * Response Header
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
 * Response Header
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.0.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 View Code Duplication
	public static function from_json( $object ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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