SocketTransport::send()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 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