Completed
Push — master ( d06bab...02e31a )
by Eugene
03:46
created

Retryable   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 43
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A open() 0 14 3
A close() 0 4 1
A isClosed() 0 4 1
A send() 0 4 1
1
<?php
2
3
namespace Tarantool\Client\Connection;
4
5
use Tarantool\Client\Exception\ConnectionException;
6
7
class Retryable implements Connection
8
{
9
    const DEFAULT_MAX_RETRIES = 3;
10
11
    private $connection;
12
    private $maxRetries;
13
14 8
    public function __construct(Connection $connection, $maxRetries = null)
15
    {
16 8
        $this->connection = $connection;
17 8
        $this->maxRetries = null === $maxRetries ? self::DEFAULT_MAX_RETRIES : $maxRetries;
18 8
    }
19
20 5
    public function open()
21
    {
22 5
        $retry = 0;
23
24
        do {
25
            try {
26 5
                return $this->connection->open();
27 4
            } catch (ConnectionException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
28
            }
29 3
            ++$retry;
30 3
        } while ($retry <= $this->maxRetries);
31
32 1
        throw $e;
33
    }
34
35 1
    public function close()
36
    {
37 1
        $this->connection->close();
38 1
    }
39
40 1
    public function isClosed()
41
    {
42 1
        return $this->connection->isClosed();
43
    }
44
45 1
    public function send($data)
46
    {
47 1
        return $this->connection->send($data);
48
    }
49
}
50