Response   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 101
Duplicated Lines 9.9 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
dl 10
loc 101
ccs 19
cts 19
cp 1
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A newInstance() 0 6 1
A __construct() 0 5 1
A getApp() 0 3 1
A parseResponseStringToObject() 0 5 1
A __call() 6 6 2
A parseResponseToData() 0 5 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
use Guzzle\Http\Message\Response as GuzzleResponse;
6
use Illuminate\Container\Container;
7
use Trucker\Facades\TransporterFactory;
8
9
class Response extends BaseResponse
10
{
11
    /**
12
     * The IoC Container.
13
     *
14
     * @var Container
15
     */
16
    protected $app;
17
18
    /**
19
     * Response object managed by this
20
     * class.
21
     *
22
     * @var GuzzleResponse
23
     */
24
    protected $response;
25
26
    /**
27
     * Response constructor.
28
     *
29
     * @param Container           $app
30
     * @param GuzzleResponse|null $response
31
     */
32 32
    public function __construct(Container $app, GuzzleResponse $response = null)
33
    {
34 32
        $this->app = $app;
35
36 32
        parent::__construct($response);
37 32
    }
38
39
    /**
40
     * Getter to access the IoC Container.
41
     *
42
     * @return Container
43
     */
44 1
    public function getApp()
45
    {
46 1
        return $this->app;
47
    }
48
49
    /**
50
     * Magic function to pass methods not found
51
     * on this class down to the guzzle 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 25 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 25
        if (!method_exists($this, $method)) {
62 25
            return call_user_func_array(
63 25
                [$this->response, $method],
64 25
                $args
65
            );
66
        }
67
        // @codeCoverageIgnoreStart
68
    }
69
70
    // @codeCoverageIgnoreEnd
71
72
    /**
73
     * @param Container      $app
74
     * @param GuzzleResponse $response
75
     *
76
     * @return Response
77
     */
78 25
    public function newInstance(Container $app, GuzzleResponse $response)
79
    {
80
        // This method just provides a convenient way for us to generate fresh model
81
        // instances of this current model. It is particularly useful during the
82
        // hydration of new objects via the Eloquent query builder instances.
83 25
        return new static($app, $response);
84
    }
85
86
    /**
87
     * Function to take a response object and convert it
88
     * into an array of data that is ready for use.
89
     *
90
     * @return array Parsed array of data
91
     */
92 11
    public function parseResponseToData()
93
    {
94 11
        $transporter = TransporterFactory::build();
0 ignored issues
show
Bug introduced by
The method build() does not exist on Trucker\Facades\TransporterFactory. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        /** @scrutinizer ignore-call */ 
95
        $transporter = TransporterFactory::build();
Loading history...
95
96 11
        return $transporter->parseResponseToData($this->response);
97
    }
98
99
    /**
100
     * Function to take a response string (as a string) and depending on
101
     * the type of string it is, parse it into an object.
102
     *
103
     * @return mixed
104
     */
105 7
    public function parseResponseStringToObject()
106
    {
107 7
        $transporter = TransporterFactory::build();
108
109 7
        return $transporter->parseResponseStringToObject($this->response);
110
    }
111
}
112