ErrorResponseException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of JSON RPC Client.
4
 *
5
 * (c) Igor Lazarev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Strider2038\JsonRpcClient\Exception;
12
13
use Strider2038\JsonRpcClient\Response\ErrorObject;
14
15
/**
16
 * @author Igor Lazarev <[email protected]>
17
 */
18
class ErrorResponseException extends \Exception implements JsonRpcClientExceptionInterface
19
{
20
    private ErrorObject $error;
21
22
    public function __construct(ErrorObject $error)
23 9
    {
24
        $this->error = $error;
25 9
26
        parent::__construct(
27 9
            sprintf(
28 9
                'Server response has error: code %d, message "%s", data %s.',
29 9
                $error->getCode(),
30 9
                $error->getMessage(),
31 9
                json_encode($error->getData())
32 9
            )
33
        );
34
    }
35 9
36
    public function getError(): ErrorObject
37 1
    {
38
        return $this->error;
39 1
    }
40
}
41