Lines
80.00%
4 / 5
Methods
66.66%
2 / 3
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| parse | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 2 | ||
| __toString | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| 11 | final readonly class ComponentInstance implements Stringable | |
| 12 | { | |
| 13 | private const string PATTERN = '/\A[a-z][a-z0-9_]{0,63}\z/'; | |
| 14 | ||
| 15 | private function __construct(public string $value) {} | |
| 16 | ||
| 17 | /** @throws HaClientException */ | |
| 18 | public static function parse(string $value): self | |
| 19 | { | |
| 20 | if (preg_match(self::PATTERN, $value) !== 1) { | |
| 21 | throw HaClientException::createForReason(HaClientError::ComponentInstanceInvalid, instance: $value); | |
| 22 | } | |
| 23 | ||
| 24 | return new self($value); | |
| 25 | } | |
| 26 | ||
| 27 | public function __toString(): string | |
| 28 | { | |
| 29 | return $this->value; | |
| 30 | } | |
| 31 | } |