ThrowableResponse   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A of() 0 3 1
A __construct() 0 8 1
A getResponse() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Voltage;
6
7
use Lit\Voltage\Interfaces\ThrowableResponseInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Throwable;
10
11
/**
12
 * Standard custom exception which contains a response.
13
 */
14
class ThrowableResponse extends \Exception implements ThrowableResponseInterface
15
{
16
    /**
17
     * @var ResponseInterface
18
     */
19
    protected $response;
20
21
    /**
22
     * @param ResponseInterface $response The response to include in the exception.
23
     * @param Throwable|null    $previous The previous throwable used for the exception chaining.
24
     * @param string            $message  The Exception message to throw.
25
     * @param integer           $code     The Exception code.
26
     */
27
    public function __construct(
28
        ResponseInterface $response,
29
        Throwable $previous = null,
30
        string $message = "",
31
        int $code = 0
32
    ) {
33
        parent::__construct($message, $code, $previous);
34
        $this->response = $response;
35
    }
36
37
    /**
38
     * Create a ThrowableResponse with no other exception information
39
     *
40
     * @param ResponseInterface $response The response.
41
     * @return ThrowableResponse
42
     */
43
    public static function of(ResponseInterface $response)
44
    {
45
        return new static($response);
46
    }
47
48
    public function getResponse(): ResponseInterface
49
    {
50
        return $this->response;
51
    }
52
}
53