Lines
100.00%
7 / 7
Methods
100.00%
3 / 3
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromVersionResult | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 3 | ||
| isCompatible | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 9 | final readonly class ComponentVersion | |
| 10 | { | |
| 11 | public function __construct( | |
| 12 | public string $componentVersion, | |
| 13 | public int $protocol, | |
| 14 | ) {} | |
| 15 | ||
| 16 | /** | |
| 17 | * @param array<array-key, mixed> $result | |
| 18 | * @throws HaClientException | |
| 19 | */ | |
| 20 | public static function fromVersionResult(array $result): self | |
| 21 | { | |
| 22 | $componentVersion = $result['component_version'] ?? null; | |
| 23 | $protocol = $result['protocol'] ?? null; | |
| 24 | ||
| 25 | if (!\is_string($componentVersion) || !\is_int($protocol)) { | |
| 26 | throw HaClientException::protocolViolation('a stewart/version result without component_version and protocol'); | |
| 27 | } | |
| 28 | ||
| 29 | return new self($componentVersion, $protocol); | |
| 30 | } | |
| 31 | ||
| 32 | public function isCompatible(): bool | |
| 33 | { | |
| 34 | return $this->protocol === ComponentProtocol::VERSION; | |
| 35 | } | |
| 36 | } |