CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
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 serviceRespondedWithAnError() 0 7 1
A getResponse() 0 4 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