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

JsonRpcException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 36
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 7 1
A getJsonRpcError() 0 4 1
A setJsonRpcError() 0 4 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