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

ResponseErrorException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 37.5 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 27
loc 72
ccs 0
cts 37
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A getResponse() 0 4 1
A getRequest() 0 4 1
A getResponseData() 0 4 1
A getDetailsArray() 15 15 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 ResponseErrorException represent exception occurred during the response processing.
15
 */
16
class ResponseErrorException extends Exception
17
{
18
    /**
19
     * @var ResponseInterface
20
     */
21
    protected $response;
22
23
    /**
24
     * ResponseErrorException constructor
25
     *
26
     * @param string $message the error message
27
     * @param ResponseInterface $response
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
        ResponseInterface $response,
35
        array $errorInfo = [],
36
        $code = 0,
37
        \Exception $previous = null
38
    ) {
39
        $this->response = $response;
40
        $errorInfo = array_merge($this->getDetailsArray(), $errorInfo);
41
42
        parent::__construct($message, $errorInfo, $code, $previous);
43
    }
44
45
    /**
46
     * @return ResponseInterface
47
     */
48
    public function getResponse()
49
    {
50
        return $this->response;
51
    }
52
53
    /**
54
     * @return RequestInterface
55
     */
56
    public function getRequest()
57
    {
58
        return $this->response->getRequest();
59
    }
60
61
    /**
62
     * @return mixed
63
     */
64
    public function getResponseData()
65
    {
66
        return $this->getResponse()->getData();
67
    }
68
69
    /**
70
     * @return array
71
     */
72 View Code Duplication
    protected function getDetailsArray()
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...
73
    {
74
        $request = $this->getRequest();
75
        $response = $this->getResponse();
76
77
        return [
78
            'statusCode' => $response->getStatusCode(),
79
            'responseData' => $response->getData(),
80
            'request' => [
81
                'method' => $request->getMethod(),
82
                'uri' => $request->getFullUri(),
83
                'body' => $request->getBody(),
84
            ],
85
        ];
86
    }
87
}
88