Completed
Push — master ( 39b3fc...3ebb26 )
by Sergey
12:04 queued 07:06
created

RpcErrorDefinition   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Test Coverage

Coverage 68.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 150
ccs 24
cts 35
cp 0.6857
rs 10
wmc 13

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A setDescription() 0 5 1
A setMessage() 0 5 1
A getCode() 0 3 1
A setData() 0 5 1
A getLogLevel() 0 3 1
A __construct() 0 12 3
A setLogLevel() 0 5 1
A getData() 0 3 1
A setCode() 0 5 1
A getMessage() 0 3 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * Project: json-rpc-server
6
 * User: sv
7
 * Date: 06.02.2021
8
 * Time: 10:45
9
 */
10
11
declare(strict_types=1);
12
13
namespace Onnov\JsonRpcServer\Definition;
14
15
use stdClass;
16
17
/**
18
 * Class RpcErrorDefinition
19
 * @package Onnov\JsonRpcServer\Definition
20
 */
21
class RpcErrorDefinition
22
{
23 1
    use CastableToArray;
24
25
    /**
26
     * Description of what went wrong.
27
     *
28
     * @var string|null
29
     */
30
    private $description = null;
31
32
    /**
33
     * Unique error code.
34
     *
35
     * @var int
36
     */
37
    private $code;
38
39
    /**
40
     * Unique error message.
41
     *
42
     * @var string
43
     */
44
    private $message;
45
46
    /**
47
     * SON-Schema of the additional error data.
48
     *
49
     * @var stdClass|null
50
     */
51
    private $data = null;
52
53
    /**
54
     * Set the logLevel when using the Psr\Log
55
     *
56
     * @var string|null
57
     */
58
    private $logLevel;
59
60
    /**
61
     * RpcErrorDefinition constructor.
62
     * @param mixed[] $data
63
     */
64 9
    public function __construct(array $data = [])
65
    {
66 9
        if (isset($data['code'])) {
67 9
            $this->code = $data['code'];
68
        }
69 9
        if (isset($data['message'])) {
70 9
            $this->message = $data['message'];
71
        }
72
73 9
        $this->description = $data['description'] ?? null;
74 9
        $this->data = $data['data'] ?? null;
75 9
        $this->logLevel = $data['logLevel'] ?? null;
76 9
    }
77
78
    /**
79
     * @return string|null
80
     */
81
    public function getDescription(): ?string
82
    {
83
        return $this->description;
84
    }
85
86
    /**
87
     * @param string|null $description
88
     * @return RpcErrorDefinition
89
     */
90
    public function setDescription(?string $description): self
91
    {
92
        $this->description = $description;
93
94
        return $this;
95
    }
96
97
    /**
98
     * @return int
99
     */
100 4
    public function getCode(): int
101
    {
102 4
        return $this->code;
103
    }
104
105
    /**
106
     * @param int $code
107
     * @return RpcErrorDefinition
108
     */
109
    public function setCode(int $code): self
110
    {
111
        $this->code = $code;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return string
118
     */
119 4
    public function getMessage(): string
120
    {
121 4
        return $this->message;
122
    }
123
124
    /**
125
     * @param string $message
126
     * @return RpcErrorDefinition
127
     */
128 1
    public function setMessage(string $message): self
129
    {
130 1
        $this->message = $message;
131
132 1
        return $this;
133
    }
134
135
    /**
136
     * @return stdClass|null
137
     */
138 4
    public function getData(): ?stdClass
139
    {
140 4
        return $this->data;
141
    }
142
143
    /**
144
     * @param stdClass|null $data
145
     * @return RpcErrorDefinition
146
     */
147 2
    public function setData(?stdClass $data): self
148
    {
149 2
        $this->data = $data;
150
151 2
        return $this;
152
    }
153
154
    /**
155
     * @return string|null
156
     */
157 4
    public function getLogLevel(): ?string
158
    {
159 4
        return $this->logLevel;
160
    }
161
162
    /**
163
     * @param string|null $logLevel
164
     * @return RpcErrorDefinition
165
     */
166
    public function setLogLevel(?string $logLevel): self
167
    {
168
        $this->logLevel = $logLevel;
169
170
        return $this;
171
    }
172
}
173