Completed
Branch middlewares (26113e)
by Marcel
02:58
created

Request::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UMA\JsonRpc;
6
7
use UMA\JsonRpc\Internal\Input;
8
9
class Request implements \JsonSerializable
10
{
11
    /**
12
     * @var mixed
13
     */
14
    private $raw;
15
16
    /**
17
     * @var int|string|null
18
     */
19
    private $id;
20
21
    /**
22
     * @var string
23
     */
24
    private $method;
25
26
    /**
27
     * @var \stdClass|array|null
28
     */
29
    private $params;
30
31 13
    public function __construct(Input $input)
32
    {
33 13
        \assert($input->isRpcRequest());
34
35 13
        $this->raw = $input->data();
36
37 13
        $this->id = $this->raw->id ?? null;
38 13
        $this->method = $this->raw->method;
39 13
        $this->params = $this->raw->params ?? null;
40 13
    }
41
42
    /**
43
     * @return int|string|null
44
     */
45 13
    public function id()
46
    {
47 13
        return $this->id;
48
    }
49
50 13
    public function method(): string
51
    {
52 13
        return $this->method;
53
    }
54
55
    /**
56
     * @return \stdClass|array|null
57
     */
58 8
    public function params()
59
    {
60 8
        return $this->params;
61
    }
62
63 1
    public function jsonSerialize()
64
    {
65 1
        return $this->raw;
66
    }
67
}
68