Passed
Push — master ( 989399...355206 )
by Julien
03:02
created

RestException::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\Exception;
6
7
use Exception;
8
use GuzzleHttp\Exception\RequestException;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * Class RestException
14
 *
15
 * @author Julien Deniau <[email protected]>
16
 */
17
class RestException extends \RuntimeException
18
{
19
    /**
20
     * @var string
21
     */
22
    private $path;
23
24
    /**
25
     * @var array
26
     */
27
    private $params;
28
29
    /**
30
     * @var ResponseInterface|null
31
     */
32
    private $response;
33
34
    /**
35
     * @var RequestInterface|null
36
     */
37
    private $request;
38
39
    public function __construct(
40
        string $message,
41
        string $path,
42
        array $params = [],
43
        int $code = 0,
44
        ?Exception $previous = null
45
    ) {
46
        parent::__construct($message, $code, $previous);
47
        $this->path = $path;
48
        $this->params = $params;
49
        if ($previous instanceof RequestException) {
50
            $this->response = $previous->getResponse();
51
            $this->request = $previous->getRequest();
52
        }
53
    }
54
55
    public function getPath(): string
56
    {
57
        return $this->path;
58
    }
59
60
    public function getParams(): array
61
    {
62
        return $this->params;
63
    }
64
65
    public function getResponse(): ?ResponseInterface
66
    {
67
        return $this->response;
68
    }
69
70
    public function getRequest(): ?RequestInterface
71
    {
72
        return $this->request;
73
    }
74
}
75