AbstractTransport   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onPreRequest() 0 4 1
A request() 0 5 1
send() 0 1 ?
A preRequest() 0 10 2
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