BaseException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 9
ccs 0
cts 8
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace TarfinLabs\Parasut\Exceptions;
4
5
use Exception;
6
use Illuminate\Http\Client\Response;
7
8
abstract class BaseException extends Exception
9
{
10
    public static int $statusCode;
11
12
    /**
13
     * Create an Exception.
14
     *
15
     * @param  \Illuminate\Http\Client\Response  $response
16
     */
17
    public function __construct(Response $response)
18
    {
19
        $message = array_key_exists('error', $response->json())
20
            ? "{$response->json()['error']}: {$response->json()['error_description']}"
21
            : "{$response->json()['errors'][0]['title']}: {$response->json()['errors'][0]['detail']}";
22
23
        parent::__construct(
24
            $message,
25
            $response->status()
26
        );
27
    }
28
}
29