NetgsmRespondedWithAnError()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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