RawResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 11.49 %

Test Coverage

Coverage 68.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
dl 10
loc 87
ccs 11
cts 16
cp 0.6875
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 6 6 2
A getResponse() 0 3 1
A response() 0 3 1
A __construct() 0 6 1
A errors() 0 3 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
namespace Trucker\Responses;
4
5
/**
6
 * Result class returned from Trucker when
7
 * a raw request is initiated.
8
 *
9
 * @author Alessandro Manno <[email protected]>
10
 */
11
class RawResponse extends BaseResponse
12
{
13
    /**
14
     * Response object.
15
     *
16
     * @var Response
17
     */
18
    protected $response;
19
20
    /**
21
     * Var to hold any errors returned.
22
     *
23
     * @var array
24
     */
25
    private $errors;
26
27
    /**
28
     * Var to tell if the request was successful.
29
     *
30
     * @var bool
31
     */
32
    public $success = false;
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param bool     $successful
38
     * @param Response $response
39
     * @param array    $errors
40
     */
41 7
    public function __construct($successful = false, Response $response = null, array $errors = [])
42
    {
43 7
        $this->success = $successful;
44 7
        $this->errors = $errors;
45
46 7
        parent::__construct($response);
47 7
    }
48
49
    /**
50
     * Magic function to pass methods not found
51
     * on this class down to the Trucker\Responses\Response
52
     * object that is being wrapped.
53
     *
54
     * @param string $method name of called method
55
     * @param array  $args   arguments to the method
56
     *
57
     * @return mixed
58
     */
59 View Code Duplication
    public function __call($method, $args)
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...
60
    {
61
        if (!method_exists($this, $method)) {
62
            return call_user_func_array(
63
                [$this->response, $method],
64
                $args
65
            );
66
        }
67
        // @codeCoverageIgnoreStart
68
    }
69
70
    // @codeCoverageIgnoreEnd
71
72
    /**
73
     * Getter for errors.
74
     *
75
     * @return array
76
     */
77 1
    public function errors()
78
    {
79 1
        return $this->errors;
80
    }
81
82
    /**
83
     * Getter for response.
84
     *
85
     * @return mixed
86
     */
87 1
    public function response()
88
    {
89 1
        return $this->response->parseResponseStringToObject();
90
    }
91
92
    /**
93
     * @return Response
94
     */
95 1
    public function getResponse()
96
    {
97 1
        return $this->response;
98
    }
99
}
100