Exception::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
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