Completed
Push — master ( fb0370...84a128 )
by Ronaldo
03:03
created

SiftScienceRequestException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 52
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getStatus() 0 4 1
A getTime() 0 4 1
A getRequest() 0 4 1
1
<?php
2
3
namespace WSW\SiftScience\Exceptions;
4
5
use DateTime;
6
use GuzzleHttp\Exception\RequestException;
7
use RuntimeException;
8
use Throwable;
9
10
/**
11
 * Class SiftScienceRequestException
12
 *
13
 * @package WSW\SiftScience\Exceptions
14
 * @author Ronaldo Matos Rodrigues <[email protected]>
15
 */
16
class SiftScienceRequestException extends RuntimeException
17
{
18
    /**
19
     * @var int
20
     */
21
    private $status;
22
23
    /**
24
     * @var \DateTime
25
     */
26
    private $time;
27
28
    /**
29
     * @var string
30
     */
31
    private $request;
32
33
    public function __construct(RequestException $exception)
34
    {
35
        $decode = json_decode($exception->getResponse()->getBody()->getContents());
36
37
        $this->status = $decode->status;
38
        $this->request = $decode->request;
39
        $this->time = (new DateTime())->setTimestamp($decode->time);
40
41
        parent::__construct($decode->error_message, $exception->getCode(), $exception->getPrevious());
42
    }
43
44
    /**
45
     * @return int
46
     */
47
    public function getStatus()
48
    {
49
        return $this->status;
50
    }
51
52
    /**
53
     * @return \DateTime
54
     */
55
    public function getTime()
56
    {
57
        return $this->time;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getRequest()
64
    {
65
        return $this->request;
66
    }
67
}
68