CallAndRetry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A callAndRetry() 0 13 4
1
<?php
2
3
namespace Ez\DbLinker\Driver\Connection;
4
5
use Exception;
6
use Ez\DbLinker\RetryStrategy;
7
8
trait CallAndRetry
9
{
10
    /**
11
     * call $callable and retry if necessary
12
     * @param callable $callable
13
     * @param RetryStrategy $strategy
14
     * @param RetryConnection $connection
15
     * @return
16
     * @throws Exception
17
     */
18
    private function callAndRetry(callable $callable, RetryStrategy $strategy, RetryConnection $connection)
19
    {
20
        do {
21
            try {
22
                return @$callable();
23
            } catch (Exception $exception) {
24
                if (!$strategy->shouldRetry($exception, $connection)) {
25
                    // stop trying
26
                    throw $exception;
27
                }
28
            }
29
        } while (true);
30
    }
31
}
32