Completed
Pull Request — master (#11716)
by Claudio
08:25
created

WC_Data_Exception   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getErrorCode() 0 3 1
1
<?php
2
/**
3
 * WooCommerce Data Exception Class
4
 *
5
 * Extends Exception to provide additional data.
6
 *
7
 * @author      WooThemes
8
 * @category    Core
9
 * @package     WooCommerce
10
 * @since       2.7
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * WC_Data_Exception class
19
 */
20
class WC_Data_Exception extends Exception {
21
22
	/** @var string sanitized error code */
23
	protected $error_code;
24
25
	/**
26
	 * Setup exception.
27
	 *
28
	 * error code - machine-readable, e.g. `woocommerce_invalid_product_id`
29
	 * error message - friendly message, e.g. 'Product ID is invalid'
30
	 * http status code - proper HTTP status code to respond with, e.g. 400
31
	 *
32
	 * @param string $error_code
33
	 * @param string $error_message user-friendly translated error message
34
	 * @param int $http_status_code HTTP status code to respond with
35
	 */
36
	public function __construct( $error_code, $error_message, $http_status_code = 400 ) {
37
		$this->error_code = $error_code;
38
		parent::__construct( $error_message, $http_status_code );
39
	}
40
41
	/**
42
	 * Returns the error code
43
	 * @return string
44
	 */
45
	public function getErrorCode() {
46
		return $this->error_code;
47
	}
48
}
49