ThrowableResponse::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
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