Response::getRpcErrorData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of Guzzle HTTP JSON-RPC
5
 *
6
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @see  http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE
12
 * @link http://github.com/graze/guzzle-jsonrpc
13
 */
14
15
namespace Graze\GuzzleHttp\JsonRpc\Message;
16
17
use Graze\GuzzleHttp\JsonRpc;
18
use GuzzleHttp\Psr7\Response as HttpResponse;
19
20
class Response extends HttpResponse implements ResponseInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 4
    public function getRpcErrorCode()
26
    {
27 4
        $error = $this->getFieldFromBody('error');
28
29 4
        return isset($error['code']) ? $error['code'] : null;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 4
    public function getRpcErrorMessage()
36
    {
37 4
        $error = $this->getFieldFromBody('error');
38
39 4
        return isset($error['message']) ? $error['message'] : null;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 2
    public function getRpcErrorData()
46
    {
47 2
        $error = $this->getFieldFromBody('error');
48
49 2
        return isset($error['data']) ? $error['data'] : null;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 4
    public function getRpcId()
56
    {
57 4
        return $this->getFieldFromBody('id');
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63 4
    public function getRpcResult()
64
    {
65 4
        return $this->getFieldFromBody('result');
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 4
    public function getRpcVersion()
72
    {
73 4
        return $this->getFieldFromBody('jsonrpc');
74
    }
75
76
    /**
77
     * @param  string $key
78
     *
79
     * @return mixed
80
     */
81 14
    protected function getFieldFromBody($key)
82
    {
83 14
        $rpc = JsonRpc\json_decode((string) $this->getBody(), true);
84
85 14
        return isset($rpc[$key]) ? $rpc[$key] : null;
86
    }
87
}
88