Completed
Push — master ( a7ee47...bc94bf )
by Pavel
04:48
created

JsonRpcException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Bankiru\Api\JsonRpc\Exception;
4
5
use Exception;
6
use ScayTrase\Api\JsonRpc\JsonRpcError;
7
use ScayTrase\Api\JsonRpc\JsonRpcErrorInterface;
8
9
class JsonRpcException extends \Exception implements JsonRpcExceptionInterface
10
{
11
    /** @var  JsonRpcErrorInterface */
12
    private $jsonRpcError;
13
14 3
    public function __construct($message = '', $code = 0, Exception $previous = null)
15
    {
16 3
        $this->jsonRpcError = new JsonRpcError(JsonRpcError::INTERNAL_ERROR, $message, (object)['x-code' => $code]);
17
18 3
        parent::__construct($message, $code, $previous);
19 3
    }
20
21
22
    /**
23
     * @return JsonRpcErrorInterface
24
     */
25
    public function getJsonRpcError()
26
    {
27
        return $this->jsonRpcError;
28
    }
29
30
    /**
31
     * @param JsonRpcErrorInterface $jsonRpcError
32
     */
33
    protected function setJsonRpcError(JsonRpcErrorInterface $jsonRpcError)
34
    {
35
        $this->jsonRpcError = $jsonRpcError;
36
    }
37
38 3
    public static function create($code, $message, $data = null)
39
    {
40 3
        $ex               = new static($message);
41 3
        $ex->jsonRpcError = new JsonRpcError($code, $message, $data);
42
43 3
        return $ex;
44
    }
45
}
46