SocketTransport   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 1
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 11 2
1
<?php
2
/*
3
 * This file is part of JSON RPC Client.
4
 *
5
 * (c) Igor Lazarev <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Strider2038\JsonRpcClient\Transport;
12
13
use Strider2038\JsonRpcClient\Exception\ConnectionFailedException;
14
use Strider2038\JsonRpcClient\Exception\ConnectionLostException;
15
use Strider2038\JsonRpcClient\Exception\InvalidConfigException;
16
use Strider2038\JsonRpcClient\Exception\RemoteProcedureCallFailedException;
17
use Strider2038\JsonRpcClient\Transport\Socket\SocketClient;
18
19
/**
20
 * @internal
21
 *
22
 * @author Igor Lazarev <[email protected]>
23
 */
24
class SocketTransport implements TransportInterface
25
{
26
    private SocketClient $client;
27
28
    /**
29
     * @throws InvalidConfigException
30
     */
31
    public function __construct(SocketClient $client)
32 17
    {
33
        $this->client = $client;
34 17
    }
35 17
36
    /**
37
     * @throws ConnectionFailedException
38
     * @throws ConnectionLostException
39
     * @throws RemoteProcedureCallFailedException
40
     */
41
    public function send(string $request): string
42 9
    {
43
        try {
44
            $response = $this->client->send($request);
45 9
        } catch (ConnectionLostException $exception) {
46 4
            $this->client->connect();
47 2
48
            $response = $this->client->send($request);
49 1
        }
50
51
        return $response;
52 6
    }
53
}
54