serviceRespondedWithAnError()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 2
nop 1
crap 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 2
    public static function serviceRespondedWithAnError(ResponseInterface $response)
11
    {
12 2
        $statusCode = $response->getStatusCode();
13
14 2
        $result = json_decode($response->getBody());
15
16 2
        if ($result && isset($result->errors)) {
17 1
            return new static('Pushover responded with an error ('.$statusCode.'): '.implode(', ', $result->errors));
18
        }
19
20 1
        return new static('Pushover responded with an error ('.$statusCode.').');
21
    }
22
}
23