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

CouldNotSendNotification   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 38
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getResponse() 0 4 1
A serviceRespondedWithAnError() 0 7 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