ApiException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 23
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromBadResponseException() 0 15 3
1
<?php
2
3
namespace TwitchAlerts\Exception;
4
5
use GuzzleHttp\Exception\BadResponseException;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Class ApiException
10
 *
11
 * @package TwitchAlerts\Exception
12
 */
13
class ApiException extends \Exception
14
{
15
    /**
16
     * @param BadResponseException $e
17
     *
18
     * @return ApiException
19
     */
20
    public static function fromBadResponseException(BadResponseException $e)
21
    {
22
        $message = 'An error has occurred during the API call';
23
24
        if ($e->getResponse() instanceof ResponseInterface) {
25
            $body = (string) $e->getResponse()->getBody();
26
            $json = json_decode($body, true);
27
28
            if (isset($json['message'])) {
29
                $message = $json['message'];
30
            }
31
        }
32
33
        return new self($message);
34
    }
35
}
36