1 | <?php |
||
7 | final class SyncResponse implements JsonRpcResponseInterface |
||
8 | { |
||
9 | /** @var \stdClass */ |
||
10 | private $response; |
||
11 | /** @var JsonRpcError */ |
||
12 | private $error; |
||
13 | |||
14 | /** |
||
15 | * SyncResponse constructor. |
||
16 | * @param \stdClass $response |
||
17 | * @throws ResponseParseException on creating response for notification |
||
18 | */ |
||
19 | 21 | public function __construct(\stdClass $response) |
|
27 | |||
28 | |||
29 | /** {@inheritdoc} */ |
||
30 | 5 | public function getError() |
|
31 | { |
||
32 | 5 | if ($this->isSuccessful()) { |
|
33 | 1 | return null; |
|
34 | } |
||
35 | |||
36 | 4 | if (null !== $this->error) { |
|
37 | 2 | return $this->error; |
|
38 | } |
||
39 | |||
40 | 4 | $rawError = $this->response->error; |
|
41 | |||
42 | 4 | $data = null; |
|
43 | 4 | if (property_exists($rawError, JsonRpcErrorInterface::ERROR_DATA_FIELD)) { |
|
44 | 1 | $data = $rawError->data; |
|
45 | 1 | } |
|
46 | |||
47 | 4 | $this->error = new JsonRpcError( |
|
48 | 4 | $rawError->{JsonRpcErrorInterface::ERROR_CODE_FIELD}, |
|
49 | 4 | $rawError->{JsonRpcErrorInterface::ERROR_MESSAGE_FIELD}, |
|
50 | $data |
||
51 | 4 | ); |
|
52 | |||
53 | 4 | return $this->error; |
|
54 | } |
||
55 | |||
56 | /** {@inheritdoc} */ |
||
57 | 7 | public function isSuccessful() |
|
61 | |||
62 | /** {@inheritdoc} */ |
||
63 | 5 | public function getBody() |
|
71 | |||
72 | /** {@inheritdoc} */ |
||
73 | 6 | public function getVersion() |
|
77 | |||
78 | /** {@inheritdoc} */ |
||
79 | 8 | public function getId() |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 4 | public function jsonSerialize() |
|
104 | } |
||
105 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.