BaseException::getResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay\Exceptions;
6
7
use Exception;
8
use Psr\Http\Message\ResponseInterface;
9
use GuzzleHttp\Exception\RequestException;
10
11
class BaseException extends Exception
12
{
13
    public static function fromGuzzle(RequestException $exception)
14
    {
15
        return new static(
16
            $exception->getMessage(),
17
            $exception->getCode(),
18
            $exception
19
        );
20
    }
21
22
    public function getResponse(): ?ResponseInterface
23
    {
24
        $previous = $this->getPrevious();
25
        if ($previous instanceof RequestException) {
26
            return $previous->getResponse();
27
        }
28
29
        return null;
30
    }
31
}
32