| Total Complexity | 6 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 8 | trait CircuitBreakerAwareTrait |
||
| 9 | { |
||
| 10 | private $circuitBreaker; |
||
| 11 | |||
| 12 | public function setCircuitBreaker(CircuitBreakerInterface $circuitBreaker): void |
||
| 13 | { |
||
| 14 | $this->circuitBreaker = $circuitBreaker; |
||
| 15 | } |
||
| 16 | |||
| 17 | public function getCircuitBreaker(): CircuitBreakerInterface |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @throws UnavailableServiceException |
||
| 24 | */ |
||
| 25 | public function throwExceptionIfServiceUnavailable(string $serviceName): void |
||
| 26 | { |
||
| 27 | if (false === $this->getCircuitBreaker()->isServiceAvailable($serviceName)) { |
||
| 28 | throw new UnavailableServiceException("Service {$serviceName} is not available right now."); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | public function reportServiceSuccess(string $serviceName): void |
||
| 33 | { |
||
| 34 | $this->getCircuitBreaker()->reportSuccess($serviceName); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function reportServiceFailure(string $serviceName): void |
||
| 40 | } |
||
| 41 | } |
||
| 42 |