CouldNotSendNotification::__construct()   A
last analyzed

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\Exceptions;
4
5
use Exception;
6
use Psr\Http\Message\ResponseInterface;
7
8
class CouldNotSendNotification extends Exception
9
{
10
    private $response;
11
12
    /**
13
     * @param ResponseInterface $response
14
     * @param string $message
15
     * @param int|null $code
16
     */
17 1
    public function __construct(ResponseInterface $response, string $message, int $code = null)
18
    {
19 1
        $this->response = $response;
20 1
        $this->message = $message;
21 1
        $this->code = $code ?? $response->getStatusCode();
22
23 1
        parent::__construct($message, $code);
24 1
    }
25
26
    /**
27
     * @param ResponseInterface $response
28
     * @return self
29
     */
30 1
    public static function serviceRespondedWithAnError(ResponseInterface $response)
31
    {
32 1
        return new self(
33 1
            $response,
34 1
            sprintf('Google Hangouts Chat API responded with an error: `%s`', $response->getBody()->getContents())
35
        );
36
    }
37
38
    /**
39
     * @return ResponseInterface
40
     */
41
    public function getResponse()
42
    {
43
        return $this->response;
44
    }
45
}
46