Completed
Push — master ( f743de...f8a04a )
by Daniel
03:18
created

JsonRpcRequest::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Cmobi\RabbitmqBundle\Rpc\Request;
4
5
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
6
7
class JsonRpcRequest implements RpcRequestInterface
8
{
9
    const VERSION = '2.0';
10
11
    public $id;
12
    public $method;
13
    public $attributes;
14
15
    public function __construct(array $attributes = [])
16
    {
17
        $this->attributes = new ParameterBag($attributes);
18
    }
19
20
    /**
21
     * @return int|string
22
     */
23
    public function getId()
24
    {
25
        return $this->id;
26
    }
27
28
    /**
29
     * @param int|string $id
30
     */
31
    public function setId($id)
32
    {
33
        $this->id = $id;
34
    }
35
36
37
    /**
38
     * @return string
39
     */
40
    public function getMethod()
41
    {
42
        return $this->method;
43
    }
44
45
    /**
46
     * @param string $method
47
     */
48
    public function setMethod($method)
49
    {
50
        $this->method = $method;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getVersion()
57
    {
58
        return self::VERSION;
59
    }
60
61
    /**
62
     * @param $key
63
     * @return mixed
64
     */
65
    public function get($key)
66
    {
67
        return $this->attributes->get($key);
68
    }
69
70
    public function __toString()
71
    {
72
        $jsonRpc = [
73
            'id' => $this->id,
74
            'jsonrpc' => self::VERSION,
75
            'method' => $this->method,
76
            'params' => $this->attributes->all()
77
        ];
78
79
        return json_encode($jsonRpc);
80
    }
81
}