Passed
Push — master ( b091a1...a43e6f )
by Pavel
03:13
created

JsonRpcError::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ScayTrase\Api\JsonRpc;
4
5
final class JsonRpcError implements JsonRpcErrorInterface
6
{
7
    /** @var int */
8
    private $code;
9
    /** @var string */
10
    private $message;
11
    /** @var null|\stdClass */
12
    private $data;
13
14
    /**
15
     * JsonRpcError constructor.
16
     * @param int $code
17
     * @param string $message
18
     * @param \stdClass|mixed|null $data
19
     */
20 4
    public function __construct($code, $message, $data = null)
21
    {
22 4
        $this->code = $code;
23 4
        $this->message = $message;
24 4
        $this->data = $data;
25 4
    }
26
27
    /** {@inheritdoc} */
28 4
    public function getCode()
29
    {
30 4
        return $this->code;
31
    }
32
33
    /** {@inheritdoc} */
34 4
    public function getMessage()
35
    {
36 4
        return $this->message;
37
    }
38
39
    /** {@inheritdoc} */
40 2
    public function getData()
41
    {
42 2
        return $this->data;
43
    }
44
45
    /** {@inheritdoc} */
46 2
    public function jsonSerialize()
47
    {
48
        $error = [
49 2
            self::ERROR_CODE_FIELD => $this->getCode(),
50 2
            self::ERROR_MESSAGE_FIELD => $this->getMessage(),
51 2
        ];
52
53 2
        if (null !== ($data = $this->getData())) {
54 1
            $error[self::ERROR_DATA_FIELD] = $data;
55 1
        }
56
57 2
        return $error;
58
    }
59
}
60