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

ResponseObject::getResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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