Passed
Pull Request — master (#1)
by
unknown
02:45
created

GooglePlayException::getUrl()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Nelexa\GPlay\Exception;
5
6
use GuzzleHttp\Exception\RequestException;
7
use Psr\Http\Message\ResponseInterface;
8
9
class GooglePlayException extends \Exception
10
{
11
    /**
12
     * @var string|null
13
     */
14
    private $url;
15
16
    /**
17
     * GooglePlayException constructor.
18
     *
19
     * @param string $message
20
     * @param int $code
21
     * @param \Throwable $previous
22
     */
23
    public function __construct($message = '', $code = 0, \Throwable $previous = null)
24
    {
25
        parent::__construct($message, $code, $previous);
26
        if (($previous instanceof RequestException) && $previous->getRequest() !== null) {
27
            $this->url = $previous->getRequest()->getUri()->__toString();
28
        }
29
    }
30
31
    /**
32
     * @param string $url
33
     * @return GooglePlayException
34
     */
35
    public function setUrl(string $url): self
36
    {
37
        $this->url = $url;
38
        return $this;
39
    }
40
41
    /**
42
     * @return string|null
43
     */
44
    public function getUrl(): ?string
45
    {
46
        return $this->url;
47
    }
48
49
    /**
50
     * @return ResponseInterface|null
51
     */
52
    public function getResponse(): ?ResponseInterface
53
    {
54
        $e = $this->getPrevious();
55
        if ($e instanceof RequestException && $e->getResponse() !== null) {
56
            return $e->getResponse();
57
        }
58
        return null;
59
    }
60
}
61