Passed
Push — master ( 55a972...5862ec )
by Brian
06:29
created

GetPaid_Payment_Exception   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getErrorData() 0 2 1
A getErrorCode() 0 2 1
1
<?php
2
/**
3
 * GetPaid Payment Exception Class
4
 *
5
 * Extends Exception to provide additional data.
6
 *
7
 * @since   2.2.2
8
 */
9
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Payment exception class.
14
 */
15
class GetPaid_Payment_Exception extends Exception {
16
17
	/**
18
	 * Sanitized error code.
19
	 *
20
	 * @var string
21
	 */
22
	protected $error_code;
23
24
	/**
25
	 * Error extra data.
26
	 *
27
	 * @var array
28
	 */
29
	protected $error_data;
30
31
	/**
32
	 * Setup exception.
33
	 *
34
	 * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
	 * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
	 * @param array  $data             Extra error data.
38
	 */
39
	public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
		$this->error_code = $code;
41
		$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
42
43
		parent::__construct( $message, $http_status_code );
44
	}
45
46
	/**
47
	 * Returns the error code.
48
	 *
49
	 * @return string
50
	 */
51
	public function getErrorCode() {
52
		return $this->error_code;
53
	}
54
55
	/**
56
	 * Returns error data.
57
	 *
58
	 * @return array
59
	 */
60
	public function getErrorData() {
61
		return $this->error_data;
62
	}
63
64
}
65