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

GocketsException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 32
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 3 1
A __construct() 0 5 1
A makeResponse() 0 5 1
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