ServerException::with()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * Sandro Keil (https://sandro-keil.de)
4
 *
5
 * @link      http://github.com/sandrokeil/arangodb-php-client for the canonical source repository
6
 * @copyright Copyright (c) 2018-2020 Sandro Keil
7
 * @license   http://github.com/sandrokeil/arangodb-php-client/blob/master/LICENSE.md New BSD License
8
 */
9
10
namespace ArangoDb\Exception;
11
12
use ArangoDb\Type\Type;
13
use Psr\Http\Client\ClientExceptionInterface;
14
use Psr\Http\Message\ResponseInterface;
15
16
final class ServerException extends RuntimeException implements ClientExceptionInterface
17
{
18
    /**
19
     * @var ResponseInterface
20
     */
21
    private $response;
22
23
    /**
24
     * @var Type
25
     */
26
    private $type;
27
28
    public static function with(Type $type, ResponseInterface $response): self
29
    {
30
        $self = new self(
31
            sprintf('Response with status code "%s" was returned.', $response->getStatusCode()),
32
            $response->getStatusCode()
33
        );
34
        $self->type = $type;
35
        $self->response = $response;
36
        return $self;
37
    }
38
39
    public function getType(): Type
40
    {
41
        return $this->type;
42
    }
43
44
    public function getResponse(): ResponseInterface
45
    {
46
        return $this->response;
47
    }
48
}
49