Completed
Branch BUG-10489-non-trashed-regs-onl... (a7561f)
by
unknown
42:44 queued 32:08
created

RestException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
A getData() 0 4 1
A getStringCode() 0 4 1
1
<?php
2
namespace EventEspresso\core\libraries\rest_api;
3
4
/**
5
 * Class Exception
6
 * similar to EE's EE_Error, except has space to hold the "data" we
7
 * want to eventually pass to WP_Error
8
 *
9
 * @package               Event Espresso
10
 * @subpackage
11
 * @author                Mike Nelson
12
 * @since                 $VID:$
13
 */
14
if (! defined('EVENT_ESPRESSO_VERSION')) {
15
    exit('No direct script access allowed');
16
}
17
18
19
20
class RestException extends \EE_Error
21
{
22
23
    /**
24
     * @var array
25
     */
26
    protected $wp_error_data = array();
27
28
    protected $wp_error_code = '';
29
30
31
32
    public function __construct($string_code, $message, $wp_error_data = array(), $previous = null)
33
    {
34
        if (is_array($wp_error_data)
35
            && isset($wp_error_data['status'])
36
        ) {
37
            $http_status_number = $wp_error_data['status'];
38
        } else {
39
            $http_status_number = 500;
40
        }
41
        parent::__construct(
42
            $message,
43
            $http_status_number,
44
            $previous
45
        );
46
        $this->wp_error_data = $wp_error_data;
47
        $this->wp_error_code = $string_code;
48
    }
49
50
51
52
    /**
53
     * Array of data that may have been set during the constructor, intended for WP_Error's data
54
     *
55
     * @return array
56
     */
57
    public function getData()
58
    {
59
        return $this->wp_error_data;
60
    }
61
62
63
64
    /**
65
     * Gets the error string
66
     *
67
     * @return string
68
     */
69
    public function getStringCode()
70
    {
71
        return $this->wp_error_code;
72
    }
73
}
74