ApiException   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 139
ccs 21
cts 27
cp 0.7778
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 2
A getErrorCode() 0 4 1
A getStatusCode() 0 4 1
A setProperties() 0 5 1
A getProperties() 0 4 1
A setData() 0 5 1
A getData() 0 4 1
A getViolations() 0 4 1
A setViolations() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Maba\Bundle\RestBundle\Exception;
5
6
use Exception;
7
use Maba\Bundle\RestBundle\Entity\Violation;
8
9
class ApiException extends Exception
10
{
11
    const INVALID_REQUEST = 'invalid_request';
12
    const INVALID_PARAMETERS = 'invalid_parameters';
13
    const INVALID_STATE = 'invalid_state';
14
    const INVALID_GRANT = 'invalid_grant';
15
    const INVALID_CODE = 'invalid_code';
16
    const UNAUTHORIZED = 'unauthorized';
17
    const FORBIDDEN = 'forbidden';
18
    const NOT_FOUND = 'not_found';
19
    const RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded';
20
    const INTERNAL_SERVER_ERROR = 'internal_server_error';
21
    const NOT_ACCEPTABLE = 'not_acceptable';
22
23
    /**
24
     * @var string
25
     */
26
    private $errorCode;
27
28
    /**
29
     * @var int|null
30
     */
31
    private $statusCode;
32
33
    /**
34
     * @var array|null
35
     */
36
    private $properties;
37
38
    /**
39
     * @var array|null
40
     */
41
    private $data;
42
43
    /**
44
     * @var Violation[]
45
     */
46
    private $violations;
47
48
    /**
49
     * @param string $errorCode
50
     * @param string|null $message
51
     * @param int|null $statusCode
52
     * @param Exception|null $previous
53
     * @param array|null $properties
54
     * @param array|null $data
55
     * @param array $violations
56
     */
57 41
    public function __construct(
58
        $errorCode,
59
        $message = null,
60
        $statusCode = null,
61
        Exception $previous = null,
62
        $properties = null,
63
        $data = null,
64
        array $violations = []
65
    ) {
66 41
        parent::__construct($message ?: '', 0, $previous);
67
68 41
        $this->errorCode = $errorCode;
69 41
        $this->statusCode = $statusCode;
70 41
        $this->properties = $properties;
71 41
        $this->data = $data;
72 41
        $this->violations = $violations;
73 41
    }
74
75
    /**
76
     * @return string
77
     */
78 30
    public function getErrorCode()
79
    {
80 30
        return $this->errorCode;
81
    }
82
83
    /**
84
     * @return int|null
85
     */
86 30
    public function getStatusCode()
87
    {
88 30
        return $this->statusCode;
89
    }
90
91
    /**
92
     * @param array|null $properties
93
     *
94
     * @return $this
95
     */
96
    public function setProperties($properties)
97
    {
98
        $this->properties = $properties;
99
        return $this;
100
    }
101
102
    /**
103
     * @return array|null
104
     */
105 30
    public function getProperties()
106
    {
107 30
        return $this->properties;
108
    }
109
110
    /**
111
     * @param array|null $data
112
     *
113
     * @return $this
114
     */
115
    public function setData($data)
116
    {
117
        $this->data = $data;
118
        return $this;
119
    }
120
121
    /**
122
     * @return array|null
123
     */
124 30
    public function getData()
125
    {
126 30
        return $this->data;
127
    }
128
129
    /**
130
     * @return Violation[]
131
     */
132 30
    public function getViolations()
133
    {
134 30
        return $this->violations;
135
    }
136
137
    /**
138
     * @param Violation[] $violations
139
     *
140
     * @return $this
141
     */
142 19
    public function setViolations($violations)
143
    {
144 19
        $this->violations = $violations;
145 19
        return $this;
146
    }
147
}
148