PaymentDetails   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 17
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A from_json() 0 22 3
1
<?php
2
/**
3
 * Payment Details
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2022 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Mollie
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Mollie;
12
13
/**
14
 * Payment Details
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.1.0
18
 * @since   2.1.0
19
 */
20
class PaymentDetails {
21
	/**
22
	 * Create payment detailsfrom JSON.
23
	 *
24
	 * @link https://docs.mollie.com/reference/v2/payments-api/get-payment
25
	 * @param string      $method Payment method.
26
	 * @param object|null $json   JSON object.
27
	 * @return PaymentDetails|null
28
	 * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
29
	 */
30
	public static function from_json( $method, $json ) {
0 ignored issues
show
Unused Code introduced by
The parameter $method is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
	public static function from_json( /** @scrutinizer ignore-unused */ $method, $json ) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
		if ( null === $json ) {
32
			return null;
33
		}
34
35
		$validator = new \JsonSchema\Validator();
36
37
		$validator->validate(
38
			$json,
39
			(object) array(
40
				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/payment-details.json' ),
41
			),
42
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
43
		);
44
45
		$details = new PaymentDetails();
46
47
		foreach ( $json as $key => $value ) {
48
			$details->{$key} = $value;
49
		}
50
51
		return $details;
52
	}
53
}
54