Request::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * T Request
4
 * User: moyo
5
 * Date: 22/09/2017
6
 * Time: 12:36 PM
7
 */
8
9
namespace Carno\RPC\Protocol;
10
11
use Carno\RPC\Chips\Protocol\Extras;
12
use Carno\RPC\Chips\Protocol\Jsonc;
13
use Carno\RPC\Chips\Protocol\Payload;
14
use Carno\RPC\Chips\Protocol\Tags;
15
use Google\Protobuf\Internal\Message;
16
17
class Request
18
{
19
    use Jsonc, Payload, Tags, Extras;
20
21
    /**
22
     * @var string
23
     */
24
    private $server = null;
25
26
    /**
27
     * @var string
28
     */
29
    private $service = null;
30
31
    /**
32
     * @var string
33
     */
34
    private $method = null;
35
36
    /**
37
     * Request constructor.
38
     * @param string $server
39
     * @param string $service
40
     * @param string $method
41
     */
42
    public function __construct(string $server, string $service, string $method)
43
    {
44
        $this->server = $server;
45
        $this->service = $service;
46
        $this->method = $method;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function identify() : string
53
    {
54
        return "{$this->server()}.{$this->service()}.{$this->method()}";
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function server() : string
61
    {
62
        return $this->server;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function service() : string
69
    {
70
        return $this->service;
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function method() : string
77
    {
78
        return $this->method;
79
    }
80
81
    /**
82
     * @param Message $input
83
     * @return Message
84
     */
85
    public function struct(Message $input) : Message
86
    {
87
        $this->isJsonc()
88
            ? $input->mergeFromJsonString($this->getPayload())
89
            : $input->mergeFromString($this->getPayload())
90
        ;
91
92
        return $input;
93
    }
94
}
95