Completed
Push — master ( 358621...3c4e64 )
by Pavel
03:50
created

JsonRpcException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getJsonRpcError() 0 4 1
A setJsonRpcError() 0 4 1
A create() 0 7 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: batanov.pavel
5
 * Date: 11.02.2016
6
 * Time: 18:51
7
 */
8
9
namespace Bankiru\Api\JsonRpc\Exception;
10
11
use Exception;
12
use ScayTrase\Api\JsonRpc\JsonRpcError;
13
use ScayTrase\Api\JsonRpc\JsonRpcErrorInterface;
14
15
class JsonRpcException extends \Exception implements JsonRpcExceptionInterface
16
{
17
    /** @var  JsonRpcErrorInterface */
18
    private $jsonRpcError;
19
20
    public function __construct($message = '', $code = 0, Exception $previous = null)
21
    {
22
        $this->jsonRpcError = new JsonRpcError(JsonRpcError::INTERNAL_ERROR, $message, (object)['x-code' => $code]);
23
24
        parent::__construct($message, $code, $previous);
25
    }
26
27
28
    /**
29
     * @return JsonRpcErrorInterface
30
     */
31
    public function getJsonRpcError()
32
    {
33
        return $this->jsonRpcError;
34
    }
35
36
    /**
37
     * @param JsonRpcErrorInterface $jsonRpcError
38
     */
39
    protected function setJsonRpcError(JsonRpcErrorInterface $jsonRpcError)
40
    {
41
        $this->jsonRpcError = $jsonRpcError;
42
    }
43
44
    public static function create($code, $message, $data = null)
45
    {
46
        $ex               = new static();
47
        $ex->jsonRpcError = new JsonRpcError($code, $message, $data);
48
49
        return $ex;
50
    }
51
}
52