Completed
Pull Request — master (#20)
by Casper
06:41
created

CouldNotSendNotification   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A serviceRespondedWithAnError() 0 12 3
1
<?php
2
3
namespace NotificationChannels\Pushover\Exceptions;
4
5
use Exception;
6
use Psr\Http\Message\ResponseInterface;
7
8
class CouldNotSendNotification extends Exception
9
{
10
    public static function serviceRespondedWithAnError(ResponseInterface $response)
11
    {
12
        $statusCode = $response->getStatusCode();
13
14
        $result = json_decode($response->getBody());
15
16
        if ($result && isset($result->errors)) {
17
            return new static('Pushover responded with an error ('.$statusCode.'): '.implode(', ', $result->errors));
18
        }
19
20
        return new static('Pushover responded with an error ('.$statusCode.').');
21
    }
22
}
23