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

JsonRpcError   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 55
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCode() 0 4 1
A getMessage() 0 4 1
A getData() 0 4 1
A jsonSerialize() 0 13 2
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