Lines
100.00%
6 / 6
Methods
100.00%
4 / 4
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| markConnected | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| markReconnecting | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| markRestored | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| 13 | final class ConnectionTracker | |
| 14 | { | |
| 15 | public private(set) ConnectionState $state; | |
| 16 | ||
| 17 | public private(set) ?HaConnectionLost $lastLoss = null; | |
| 18 | ||
| 19 | public function __construct(private readonly Clock $clock) | |
| 20 | { | |
| 21 | $this->state = new ConnectionState(); | |
| 22 | } | |
| 23 | ||
| 24 | public function markConnected(): void | |
| 25 | { | |
| 26 | $this->state = new ConnectionState(ConnectionPhase::Connected, $this->clock->getNow()); | |
| 27 | } | |
| 28 | ||
| 29 | public function markReconnecting(HaConnectionLost $loss): void | |
| 30 | { | |
| 31 | $this->lastLoss = $loss; | |
| 32 | $this->state = new ConnectionState(ConnectionPhase::Reconnecting, $this->clock->getNow(), $this->state->reconnects, $this->state->lastOutage); | |
| 33 | } | |
| 34 | ||
| 35 | public function markRestored(Duration $outage): void | |
| 36 | { | |
| 37 | $this->lastLoss = null; | |
| 38 | $this->state = new ConnectionState(ConnectionPhase::Connected, $this->clock->getNow(), $this->state->reconnects + 1, $outage); | |
| 39 | } | |
| 40 | } |