RequestErrorException::getRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * ActiveRecord for API
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\hiart;
12
13
/**
14
 * Class RequestErrorException represents an error occurred during the request sending.
15
 */
16
class RequestErrorException extends Exception
17
{
18
    /**
19
     * @var RequestInterface
20
     */
21
    protected $request;
22
23
    /**
24
     * RequestErrorException constructor.
25
     *
26
     * @param string $message
27
     * @param RequestInterface $request
28
     * @param int $code
29
     * @param \Exception|null $previous
30
     */
31
    public function __construct($message, RequestInterface $request, $code = 0, \Exception $previous = null)
32
    {
33
        $this->request = $request;
34
        parent::__construct($message, $this->getErrorInfo(), $code, $previous);
35
    }
36
37
    /**
38
     * @return RequestInterface
39
     */
40
    public function getRequest()
41
    {
42
        return $this->errorInfo['request'];
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    protected function getErrorInfo()
49
    {
50
        $request = $this->getRequest();
51
52
        return [
53
            'method' => $request->getMethod(),
54
            'uri' => $request->getFullUri(),
55
            'body' => $request->getBody(),
56
        ];
57
    }
58
}
59