Exception   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 6 1
A __construct() 0 4 2
1
<?php
2
3
namespace veejay\jsonrpc\exception;
4
5
use veejay\jsonrpc\batch\Response;
6
7
class Exception extends \Exception
8
{
9
    /**
10
     * @param int $code
11
     * @param string $message
12
     */
13
    public function __construct(int $code, string $message = '')
14
    {
15
        $this->code = $code;
16
        $this->message = $message ?: Response::getErrorMessage($code);
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function __toString()
23
    {
24
        $response = new Response;
25
        $response->jsonrpc = Response::VERSION;
26
        $response->setError($this->code, $this->message);
27
        return json_encode($response->getData());
28
    }
29
}
30