Lines 0.00% 0 / 5
Functions and Methods 0.00% 0 / 5
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
HaClientException 0.00% 0 / 5 0.00% 0 / 5 30 0.00% 0 / 1
 connectionDropped 0.00% 0 / 1 0.00% 0 / 1 2
 protocolViolation 0.00% 0 / 1 0.00% 0 / 1 2
 commandUnencodable 0.00% 0 / 1 0.00% 0 / 1 2
 findDetail 0.00% 0 / 1 0.00% 0 / 1 2
 findErrorCode 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Client\Exception;
6
7use Stewart\Contracts\Exception\StewartException;
8use Throwable;
9
10/** @extends StewartException<HaClientError> */
11final class HaClientException extends StewartException
12{
13    public static function connectionDropped(string $detail, ?Throwable $previous = null): self
14    {
15        return self::createForReason(HaClientError::ConnectionDropped, $previous, detail: $detail);
16    }
17
18    public static function protocolViolation(string $detail, ?Throwable $previous = null): self
19    {
20        return self::createForReason(HaClientError::ProtocolViolation, $previous, detail: $detail);
21    }
22
23    public static function commandUnencodable(string $command, Throwable $previous): self
24    {
25        return self::createForReason(HaClientError::CommandUnencodable, $previous, command: $command, detail: 'could not be encoded: ' . $previous->getMessage());
26    }
27
28    public function findDetail(): ?string
29    {
30        return $this->findContextString('detail');
31    }
32
33    public function findErrorCode(): ?string
34    {
35        return $this->findContextString('errorCode');
36    }
37}