Completed
Push — master ( b98780...343123 )
by Vladimir
08:52 queued 02:02
created

BaseException::getResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AcquiroPay\Exceptions;
6
7
use Exception;
8
use GuzzleHttp\Exception\RequestException;
9
use Psr\Http\Message\ResponseInterface;
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