Passed
Pull Request — master (#11)
by Pavel
07:39
created

JsonRpcException::getJsonRpcError()   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 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 7
    public function __construct($message = '', $code = 0, Exception $previous = null)
15
    {
16 7
        $this->jsonRpcError = new JsonRpcError(JsonRpcError::INTERNAL_ERROR, $message, (object)['x-code' => $code]);
17
18 7
        parent::__construct($message, $code, $previous);
19 7
    }
20
21
    /**
22
     * @return JsonRpcErrorInterface
23
     */
24 1
    public function getJsonRpcError()
25
    {
26 1
        return $this->jsonRpcError;
27
    }
28
29
    /**
30
     * @param JsonRpcErrorInterface $jsonRpcError
31
     */
32
    protected function setJsonRpcError(JsonRpcErrorInterface $jsonRpcError)
33
    {
34
        $this->jsonRpcError = $jsonRpcError;
35
    }
36
37 7
    public static function create($code, $message, $data = null)
38
    {
39 7
        $ex               = new static($message);
40 7
        $ex->jsonRpcError = new JsonRpcError($code, $message, $data);
41
42 7
        return $ex;
43
    }
44
}
45