AbstractTransport::request()   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
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace PhpJsonRpc\Client;
4
5
use PhpJsonRpc\Client\Transport\TransportContainer;
6
use PhpJsonRpc\Common\Interceptor\Interceptor;
7
8
abstract class AbstractTransport implements TransportInterface
9
{
10
    /**
11
     * @var Interceptor
12
     */
13
    protected $preRequest;
14
15
    /**
16
     * AbstractTransport constructor.
17
     */
18
    public function __construct()
19
    {
20
        $this->preRequest  = Interceptor::createBase();
21
    }
22
23
    /**
24
     * @return Interceptor
25
     */
26
    public function onPreRequest(): Interceptor
27
    {
28
        return $this->preRequest;
29
    }
30
31
    /**
32
     * Execute request
33
     *
34
     * @param string $request
35
     *
36
     * @return string
37
     */
38
    public function request(string $request): string
39
    {
40
        $request  = $this->preRequest($request);
41
        return $this->send($request);
42
    }
43
44
    abstract public function send(string $request): string;
45
46
    /**
47
     * @param string $request
48
     *
49
     * @return string
50
     */
51
    private function preRequest(string $request): string
52
    {
53
        $result = $this->preRequest->handle(new TransportContainer($this, $request));
54
55
        if ($result instanceof TransportContainer) {
56
            return $result->getRequest();
57
        }
58
59
        throw new \RuntimeException();
60
    }
61
}
62