Lines
100.00%
2 / 2
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ComponentErrorCode | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | 100.00% | 1 / 1 | |||
| tryFromException | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 3 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Client\Component; | |
| 6 | ||
| 7 | use Stewart\Client\Exception\HaClientError; | |
| 8 | use Stewart\Client\Exception\HaClientException; | |
| 9 | ||
| 10 | enum ComponentErrorCode: string | |
| 11 | { | |
| 12 | case ProtocolMismatch = 'protocol_mismatch'; | |
| 13 | case NoSession = 'no_session'; | |
| 14 | case NotFound = 'not_found'; | |
| 15 | case InvalidConfig = 'invalid_config'; | |
| 16 | case InvalidState = 'invalid_state'; | |
| 17 | case ActionTaken = 'action_taken'; | |
| 18 | ||
| 19 | public static function tryFromException(HaClientException $exception): ?self | |
| 20 | { | |
| 21 | $code = $exception->reason === HaClientError::CommandRejected ? $exception->findErrorCode() : null; | |
| 22 | ||
| 23 | return $code === null ? null : self::tryFrom($code); | |
| 24 | } | |
| 25 | } |