Completed
Push — master ( 2a1eef...f81184 )
by Dmitry
02:53
created

RequestErrorException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 5
crap 2
1
<?php
2
/**
3
 * Tools to use API as ActiveRecord for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-hiart
6
 * @package   yii2-hiart
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, 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 array $errorInfo
29
     * @param int $code
30
     * @param \Exception|null $previous
31
     */
32 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
        $message,
34
        RequestInterface $request,
35
        array $errorInfo = [],
36
        $code = 0,
37
        \Exception $previous = null
38
    ) {
39
        $this->request = $request;
40
        $errorInfo = array_merge($this->getDetailsArray(), $errorInfo);
41
42
        parent::__construct($message, $errorInfo, $code, $previous);
43
    }
44
45
    /**
46
     * @return RequestInterface
47
     */
48
    public function getRequest()
49
    {
50
        return $this->errorInfo['request'];
51
    }
52
53
    /**
54
     * @return array
55
     */
56
    protected function getDetailsArray()
57
    {
58
        $request = $this->getRequest();
59
60
        return [
61
            'method' => $request->getMethod(),
62
            'uri' => $request->getFullUri(),
63
            'body' => $request->getBody(),
64
        ];
65
    }
66
}
67