CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A NetgsmRespondedWithAnError() 0 9 3
1
<?php
2
3
namespace TarfinLabs\Netgsm\Exceptions;
4
5
use GuzzleHttp\Exception\ClientException;
6
7
class CouldNotSendNotification extends AbstractNetgsmException
8
{
9
    /**
10
     * Thrown when there's a bad request and an error is responded.
11
     *
12
     * @param ClientException $exception
13
     *
14
     * @return static
15
     */
16
    public static function NetgsmRespondedWithAnError(ClientException $exception)
17
    {
18
        $statusCode = $exception->getResponse()->getStatusCode();
19
        $description = 'no description given';
20
        if ($result = json_decode($exception->getResponse()->getBody())) {
21
            $description = $result->description ?: $description;
22
        }
23
24
        return new static("Netgsm responded with an error `{$statusCode} - {$description}`");
25
    }
26
}
27