Completed
Push — master ( 221734...f96e3c )
by Casper
06:04
created

CouldNotSendNotification::serviceCommunicationError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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