Passed
Push — master ( daf9a5...29a35b )
by Igor
01:04 queued 11s
created

ResponseObject   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 17
c 1
b 0
f 0
dl 0
loc 55
ccs 20
cts 20
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setError() 0 3 1
A getResult() 0 3 1
A __construct() 0 5 1
A hasError() 0 3 1
A getError() 0 9 2
A getId() 0 3 1
A getProtocol() 0 3 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\Response;
12
13
use Strider2038\JsonRpcClient\Exception\JsonRpcClientException;
14
15
/**
16
 * @author Igor Lazarev <[email protected]>
17
 */
18
class ResponseObject implements ResponseObjectInterface
19
{
20
    /** @var string */
21
    private $jsonrpc;
22
23
    /** @var mixed */
24
    private $result;
25
26
    /** @var ErrorObject|null */
27
    private $error;
28
29
    /** @var string|int|null */
30
    private $id;
31
32 51
    public function __construct(string $protocol, $result, $id)
33
    {
34 51
        $this->jsonrpc = $protocol;
35 51
        $this->result = $result;
36 51
        $this->id = $id;
37 51
    }
38
39 40
    public function getProtocol(): string
40
    {
41 40
        return $this->jsonrpc;
42
    }
43
44 24
    public function getId()
45
    {
46 24
        return $this->id;
47
    }
48
49 40
    public function getResult()
50
    {
51 40
        return $this->result;
52
    }
53
54 44
    public function hasError(): bool
55
    {
56 44
        return null !== $this->error;
57
    }
58
59 17
    public function getError(): ErrorObject
60
    {
61 17
        if (null === $this->error) {
62 1
            throw new JsonRpcClientException(
63 1
                'There is no error in response. Please, use hasError() method to check response for errors.'
64
            );
65
        }
66
67 16
        return $this->error;
68
    }
69
70 16
    public function setError(ErrorObject $error): void
71
    {
72 16
        $this->error = $error;
73 16
    }
74
}
75