Completed
Push — master ( 1be44d...449b6f )
by Artem
02:21
created

GocketsException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Gockets\Exception;
4
5
use Gockets\Model\Response;
6
use Throwable;
7
8
/**
9
 * Basic library exception
10
 */
11
class GocketsException extends \Exception
12
{
13
    /**
14
     * @var Response
15
     */
16
    protected $response;
17
18
    /**
19
     * GocketsException constructor.
20
     *
21
     * @param $response string The original json response
22
     * @param string $message
23
     * @param int $code
24
     * @param Throwable|null $previous
25
     */
26
    public function __construct(string $response, string $message = '', $code = 0, Throwable $previous = null)
27
    {
28
        $this->makeResponse($response);
29
30
        parent::__construct($message, $code, $previous);
31
    }
32
33
    public function getResponse(): Response
34
    {
35
        return $this->response;
36
    }
37
38
    protected function makeResponse($content): void
39
    {
40
        $response = json_decode($content);
41
42
        $this->response = new Response($response->type, $response->message);
43
    }
44
}
45