| Total Complexity | 8 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 89.47% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | final class FixedWaitTimeToRetry implements AvailabilityStrategy |
||
| 9 | { |
||
| 10 | private $storage; |
||
| 11 | private $maxFailures; |
||
| 12 | private $waitTime; |
||
| 13 | |||
| 14 | 4 | public function __construct(Storage $storage, int $maxFailures, int $waitTime) |
|
| 15 | { |
||
| 16 | 4 | $this->storage = $storage; |
|
| 17 | 4 | $this->maxFailures = $maxFailures; |
|
| 18 | 4 | $this->waitTime = $waitTime; |
|
| 19 | 4 | } |
|
| 20 | 4 | public function isAvailable(string $serviceName): bool |
|
| 21 | { |
||
| 22 | try { |
||
| 23 | 4 | if ($this->storage->numberOfFailures($serviceName) < $this->maxFailures) { |
|
| 24 | 1 | return true; |
|
| 25 | } |
||
| 26 | |||
| 27 | 2 | $lastRetry = $this->getLastTryTime(); |
|
| 28 | 2 | if (time() - $lastRetry > $this->waitTime) { |
|
| 29 | 1 | return true; |
|
| 30 | } |
||
| 31 | |||
| 32 | 1 | return false; |
|
| 33 | 1 | } catch (StorageException $ex) { |
|
| 34 | 1 | return true; |
|
| 35 | } |
||
| 36 | } |
||
| 37 | |||
| 38 | public function getId(): string |
||
| 41 | } |
||
| 42 | |||
| 43 | 2 | private function getLastTryTime(): int |
|
| 47 | } |
||
| 48 | } |
||
| 49 |