BadResponseCode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createForResponse() 0 12 2
A getMessageForResponse() 0 4 1
1
<?php
2
3
namespace Facade\FlareClient\Http\Exceptions;
4
5
use Exception;
6
use Facade\FlareClient\Http\Response;
7
8
class BadResponseCode extends Exception
9
{
10
    /** @var \Facade\FlareClient\Http\Response */
11
    public $response;
12
13
    /** @var array */
14
    public $errors;
15
16
    public static function createForResponse(Response $response)
17
    {
18
        $exception = new static(static::getMessageForResponse($response));
19
20
        $exception->response = $response;
21
22
        $bodyErrors = isset($response->getBody()['errors']) ? $response->getBody()['errors'] : [];
23
24
        $exception->errors = $bodyErrors;
25
26
        return $exception;
27
    }
28
29
    public static function getMessageForResponse(Response $response)
30
    {
31
        return "Response code {$response->getHttpResponseCode()} returned";
32
    }
33
}
34