JsonRpcException::getErrorCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
namespace Yoanm\JsonRpcServer\Domain\Exception;
3
4
/**
5
 * JsonRpcException represents an error which can be rendered as a JsonRpc response.
6
 * It allows the specification of the particular data to be displayed making error more verbose.
7
 *
8
 * > Note: be careful about the data you expose via this mechanism, make sure you do not expose any vital information through it.
9
 *
10
 * @see \Yoanm\JsonRpcServer\App\Serialization\JsonRpcResponseNormalizer
11
 */
12
class JsonRpcException extends \Exception implements JsonRpcExceptionInterface
13
{
14
    /** @var array */
15
    private $data;
16
17
    /**
18
     * @param int    $code
19
     * @param string $message
20
     * @param array  $data
21
     */
22 39
    public function __construct(int $code, string $message = '', array $data = [], ?\Throwable $previous = null)
23
    {
24 39
        $this->data = $data;
25
26 39
        parent::__construct($message, $code, $previous);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 35
    public function getErrorCode() : int
33
    {
34 35
        return parent::getCode();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 35
    public function getErrorMessage() : string
41
    {
42 35
        return parent::getMessage();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 35
    public function getErrorData() : array
49
    {
50 35
        return $this->data;
51
    }
52
}
53