Lines
100.00%
12 / 12
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| buildStoreHealth | 100.00% | 11 / 11 | 100.00% | 1 / 1 | 8 | ||
| 11 | final readonly class StoreHealthBuilder | |
| 12 | { | |
| 13 | public function __construct( | |
| 14 | private WorkerSlotRegistry $slots, | |
| 15 | private PersistenceConfig $persistenceConfig, | |
| 16 | ) {} | |
| 17 | ||
| 18 | public function buildStoreHealth(): ?StoreHealth | |
| 19 | { | |
| 20 | if (!$this->persistenceConfig->isStoreConfigured()) { | |
| 21 | return null; | |
| 22 | } | |
| 23 | ||
| 24 | $available = true; | |
| 25 | $newest = null; | |
| 26 | ||
| 27 | foreach ($this->slots->listLiveHandles() as $handle) { | |
| 28 | $reported = $handle->lastPong?->store; | |
| 29 | ||
| 30 | if ($reported === null) { | |
| 31 | continue; | |
| 32 | } | |
| 33 | ||
| 34 | $available = $available && $reported->available; | |
| 35 | ||
| 36 | if ($reported->lastFailureAt !== null && ($newest?->lastFailureAt === null || $newest->lastFailureAt->isBefore($reported->lastFailureAt))) { | |
| 37 | $newest = $reported; | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | return new StoreHealth($available, $newest?->lastFailure, $newest?->lastFailureAt); | |
| 42 | } | |
| 43 | } |