ClientException::fromResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TechDeCo\ElasticApmAgent\Exception;
5
6
use Psr\Http\Message\ResponseInterface;
7
use RuntimeException;
8
use Throwable;
9
use function count;
10
use function sprintf;
11
12
final class ClientException extends RuntimeException implements Exception
13
{
14
    /**
15
     * @var Throwable[]
16
     */
17
    private $exceptionList = [];
18
19 3
    public static function fromResponse(string $message, ResponseInterface $response): self
20
    {
21 3
        return new self(sprintf('%s: %s', $message, $response->getBody()->getContents()));
22
    }
23
24 3
    public static function fromException(string $message, Throwable ...$exception): self
25
    {
26 3
        if (count($exception) === 1) {
27 2
            return new self($message, 0, $exception[0] ?? null);
28
        }
29
30 1
        $me                = new self($message);
31 1
        $me->exceptionList = $exception;
32
33 1
        return $me;
34
    }
35
36
    /**
37
     * @return Throwable[]
38
     */
39 1
    public function getExceptionList(): array
40
    {
41 1
        return $this->exceptionList;
42
    }
43
}
44