Lines 100.00% 10 / 10
Functions and Methods 100.00% 5 / 5
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ServiceCallException 100.00% 10 / 10 100.00% 5 / 5 6 100.00% 1 / 1
 rejected 100.00% 1 / 1 100.00% 1 / 1 1
 unreachable 100.00% 1 / 1 100.00% 1 / 1 1
 timedOut 100.00% 1 / 1 100.00% 1 / 1 1
 overloaded 100.00% 1 / 1 100.00% 1 / 1 1
 createForServiceCall 100.00% 6 / 6 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Exception;
6
7use Throwable;
8
9/** @extends StewartException<ServiceCallError> */
10final class ServiceCallException extends StewartException
11{
12    public static function rejected(
13        string $domain,
14        string $service,
15        string $detail,
16        ?string $errorCode = null,
17        ?Throwable $previous = null,
18    ): self {
19        return self::createForServiceCall(ServiceCallError::Rejected, $domain, $service, $detail, $errorCode, $previous);
20    }
21
22    public static function unreachable(string $domain, string $service, string $detail, ?Throwable $previous = null): self
23    {
24        return self::createForServiceCall(ServiceCallError::Unreachable, $domain, $service, $detail, null, $previous);
25    }
26
27    public static function timedOut(string $domain, string $service, string $detail, ?Throwable $previous = null): self
28    {
29        return self::createForServiceCall(ServiceCallError::TimedOut, $domain, $service, $detail, null, $previous);
30    }
31
32    public static function overloaded(string $domain, string $service, string $detail): self
33    {
34        return self::createForServiceCall(ServiceCallError::Overloaded, $domain, $service, $detail, null, null);
35    }
36
37    private static function createForServiceCall(
38        ServiceCallError $reason,
39        string $domain,
40        string $service,
41        string $detail,
42        ?string $errorCode,
43        ?Throwable $previous,
44    ): self {
45        return self::createForReasonWithAppendedText(
46            $reason,
47            ['domain' => $domain, 'service' => $service, 'detail' => $detail, 'errorCode' => $errorCode],
48            $errorCode === null ? null : '(' . $errorCode . ')',
49            $previous,
50        );
51    }
52}