Request   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 44
rs 10
c 0
b 0
f 0
ccs 11
cts 11
cp 1
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRpcMethod() 0 3 1
A getRpcVersion() 0 3 1
A getRpcParams() 0 3 1
A getRpcId() 0 3 1
A getFieldFromBody() 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\Request as HttpRequest;
19
20
class Request extends HttpRequest implements RequestInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function getRpcId()
26
    {
27 2
        return $this->getFieldFromBody('id');
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 3
    public function getRpcMethod()
34
    {
35 3
        return $this->getFieldFromBody('method');
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 2
    public function getRpcParams()
42
    {
43 2
        return $this->getFieldFromBody('params');
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function getRpcVersion()
50
    {
51 2
        return $this->getFieldFromBody('jsonrpc');
52
    }
53
54
    /**
55
     * @param  string $key
56
     *
57
     * @return mixed
58
     */
59 9
    protected function getFieldFromBody($key)
60
    {
61 9
        $rpc = JsonRpc\json_decode((string) $this->getBody(), true);
62
63 9
        return isset($rpc[$key]) ? $rpc[$key] : null;
64
    }
65
}
66