Response   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 66
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRpcResult() 0 3 1
A getRpcId() 0 3 1
A getRpcVersion() 0 3 1
A getFieldFromBody() 0 5 2
A getRpcErrorMessage() 0 5 2
A getRpcErrorData() 0 5 2
A getRpcErrorCode() 0 5 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