Completed
Pull Request — master (#11)
by Sandro
02:12
created

ServerException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A with() 0 9 1
A getResponse() 0 3 1
A getType() 0 3 1
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