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

Error::get_detailed_message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Error
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
 * Error
15
 *
16
 * @link    https://developers.acehubpaymentservices.com/v3.3/reference#payment-3-1
17
 * @author  Remco Tolsma
18
 * @version 1.0.0
19
 * @since   1.0.0
20
 */
21
class Error extends \Exception {
22
	/**
23
	 * Detailed message.
24
	 *
25
	 * A more detailed error message when available. If not available, contains the same as error.message.
26
	 *
27
	 * @var string
28
	 */
29
	private $detailed_message;
30
31
	/**
32
	 * Construct and initialize payment response
33
	 *
34
	 * @param int    $code             Code.
35
	 * @param string $message          Message.
36
	 * @param string $detailed_message Detailed message.
37
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
38
	 */
39 2
	public function __construct( $code, $message, $detailed_message ) {
40 2
		parent::__construct( $message, $code );
41
42 2
		$this->detailed_message = $detailed_message;
43 2
	}
44
45
	/**
46
	 * From JSON.
47
	 *
48
	 * @param object $object Object.
49
	 * @return self
50
	 * @throws \JsonSchema\Exception\ValidationException Throws exception when JSON is not valid.
51
	 */
52 1 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...
53 1
		$validator = new \JsonSchema\Validator();
54
55 1
		$validator->validate(
56 1
			$object,
57
			(object) array(
58 1
				'$ref' => 'file://' . \realpath( __DIR__ . '/../json-schemas/error.json' ),
59
			),
60 1
			\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS
61
		);
62
63
        /* phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase */
64 1
		return new self( $object->code, $object->message, $object->detailedMessage );
65
	}
66
67
	/**
68
	 * Get code.
69
	 *
70
	 * @return int|string
71
	 */
72 1
	public function get_code() {
73 1
		return $this->getCode();
74
	}
75
76
	/**
77
	 * Get message.
78
	 *
79
	 * @return string
80
	 */
81 1
	public function get_message() {
82 1
		return $this->getMessage();
83
	}
84
85
	/**
86
	 * Get detailed message.
87
	 *
88
	 * @return string
89
	 */
90
	public function get_detailed_message() {
91
		return $this->detailed_message;
92
	}
93
}
94