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

JsonRpcException::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 2
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