Total Complexity | 6 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
7 | class CircuitBreaker |
||
8 | { |
||
9 | private $availabilityStrategy; |
||
10 | private $storage; |
||
11 | |||
12 | 6 | public function __construct( |
|
18 | 6 | } |
|
19 | |||
20 | 2 | public function isAvailable(string $serviceName): bool |
|
21 | { |
||
22 | 2 | return $this->availabilityStrategy->isAvailable($serviceName); |
|
23 | } |
||
24 | |||
25 | 3 | public function reportFailure(string $serviceName) |
|
26 | { |
||
27 | try { |
||
28 | 3 | $this->storage->incrementFailures($serviceName); |
|
29 | 1 | } catch (Throwable $ex) { |
|
30 | 1 | throw new StorageException( |
|
31 | 1 | "Error incrementing failures", |
|
32 | 1 | $ex->getCode(), |
|
33 | 1 | $ex |
|
34 | ); |
||
35 | } |
||
36 | 2 | } |
|
37 | |||
38 | 3 | public function reportSuccess(string $serviceName) |
|
47 | ); |
||
48 | } |
||
49 | 2 | } |
|
51 |