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
9
 * through it.
10
 *
11
 * @see \Yoanm\JsonRpcServer\App\Serialization\JsonRpcResponseNormalizer
12
 */
13
class JsonRpcException extends \Exception implements JsonRpcExceptionInterface
14
{
15
    /** @var array */
16
    private $data;
17
18
    /**
19
     * @param int    $code
20
     * @param string $message
21
     * @param array  $data
22
     */
23 39
    public function __construct(int $code, string $message = '', array $data = [], ?\Throwable $previous = null)
24
    {
25 39
        $this->data = $data;
26
27 39
        parent::__construct($message, $code, $previous);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 35
    public function getErrorCode() : int
34
    {
35 35
        return parent::getCode();
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 35
    public function getErrorMessage() : string
42
    {
43 35
        return parent::getMessage();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 35
    public function getErrorData() : array
50
    {
51 35
        return $this->data;
52
    }
53
}
54