Passed
Push — master ( 401ce9...01f538 )
by Igor
01:14 queued 10s
created

SocketTransport::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 6
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 2
rs 10
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
 * @author Igor Lazarev <[email protected]>
21
 */
22
class SocketTransport implements TransportInterface
23
{
24
    /** @var SocketClient */
25
    private $client;
26
27
    /**
28
     * @throws InvalidConfigException
29
     */
30 13
    public function __construct(SocketClient $client)
31
    {
32 13
        $this->client = $client;
33 13
    }
34
35
    /**
36
     * @throws ConnectionFailedException
37
     * @throws ConnectionLostException
38
     * @throws RemoteProcedureCallFailedException
39
     */
40 9
    public function send(string $request): string
41
    {
42
        try {
43 9
            $response = $this->client->send($request);
44 4
        } catch (ConnectionLostException $exception) {
45 2
            $this->client->connect();
46
47 1
            $response = $this->client->send($request);
48
        }
49
50 6
        return $response;
51
    }
52
}
53