Passed
Pull Request — master (#7)
by Igor
04:31
created

ResponseObject::getJsonRpcVersion()   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 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
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
/**
14
 * @author Igor Lazarev <[email protected]>
15
 */
16
class ResponseObject implements ResponseObjectInterface
17
{
18
    /** @var string */
19
    private $jsonrpc;
20
21
    /** @var mixed */
22
    private $result;
23
24
    /** @var ErrorObject|null */
25
    private $error;
26
27
    /** @var string|int|null */
28
    private $id;
29
30 47
    public function __construct(string $protocol, $result, $id)
31
    {
32 47
        $this->jsonrpc = $protocol;
33 47
        $this->result = $result;
34 47
        $this->id = $id;
35 47
    }
36
37 37
    public function getProtocol(): string
38
    {
39 37
        return $this->jsonrpc;
40
    }
41
42 21
    public function getId()
43
    {
44 21
        return $this->id;
45
    }
46
47 37
    public function getResult()
48
    {
49 37
        return $this->result;
50
    }
51
52 41
    public function hasError(): bool
53
    {
54 41
        return null !== $this->error;
55
    }
56
57 13
    public function getError(): ErrorObject
58
    {
59 13
        return $this->error;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->error could return the type null which is incompatible with the type-hinted return Strider2038\JsonRpcClient\Response\ErrorObject. Consider adding an additional type-check to rule them out.
Loading history...
60
    }
61
62 13
    public function setError(ErrorObject $error): void
63
    {
64 13
        $this->error = $error;
65 13
    }
66
}
67