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

serviceRespondedWithAnError()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 2
nop 1
crap 12
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