SiftScienceRequestException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 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 12
    public function __construct(RequestException $exception)
34
    {
35 12
        $decode = json_decode($exception->getResponse()->getBody()->getContents());
36
37 12
        $this->status = $decode->status;
38 12
        $this->request = $decode->request;
39 12
        $this->time = (new DateTime())->setTimestamp($decode->time);
40
41 12
        parent::__construct($decode->error_message, $exception->getCode(), $exception->getPrevious());
42 12
    }
43
44
    /**
45
     * @return int
46
     */
47 1
    public function getStatus()
48
    {
49 1
        return $this->status;
50
    }
51
52
    /**
53
     * @return \DateTime
54
     */
55 1
    public function getTime()
56
    {
57 1
        return $this->time;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 1
    public function getRequest()
64
    {
65 1
        return $this->request;
66
    }
67
}
68