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

BaseException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 21
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromGuzzle() 0 8 1
A getResponse() 0 9 2
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