ClientException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
ccs 10
cts 10
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromResponse() 0 4 1
A fromException() 0 11 2
A getExceptionList() 0 4 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