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

ResponseHeader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A from_json() 14 14 1
A get_request_timestamp() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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