Completed
Push — master ( 8b8edb...ff94cb )
by
unknown
03:57
created

CouldNotSendNotification::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace NotificationChannels\Webhook\Exceptions;
4
5
use GuzzleHttp\Psr7\Response;
6
7
class CouldNotSendNotification extends \Exception
8
{
9
    private $response;
10
11
    /**
12
     * @param Response $response
13
     * @param string $message
14
     * @param int|null $code
15
     */
16 1
    public function __construct(Response $response, string $message, int $code = null)
17
    {
18 1
        $this->response = $response;
19 1
        $this->message = $message;
20 1
        $this->code = $code ?? $response->getStatusCode();
21
22 1
        parent::__construct($message, $code);
23 1
    }
24
25
    /**
26
     * @param Response $response
27
     * @return self
28
     */
29 1
    public static function serviceRespondedWithAnError(Response $response)
30
    {
31 1
        return new self(
32 1
            $response,
33 1
            sprintf('Webhook responded with an error: `%s`', $response->getBody()->getContents())
34
        );
35
    }
36
37
    /**
38
     * @return Response
39
     */
40
    public function getResponse()
41
    {
42
        return $this->response;
43
    }
44
}
45