Passed
Pull Request — master (#111)
by Adam
01:45
created

CloudApiBase::getLinkedResource()   D

Complexity

Conditions 25
Paths 19

Size

Total Lines 124
Code Lines 92

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 25
eloc 92
nc 19
nop 1
dl 0
loc 124
rs 4.1666
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AcquiaCloudApi\Endpoints;
4
5
use AcquiaCloudApi\Connector\ClientInterface;
6
7
/**
8
 * Class CloudApiBase
9
 *
10
 * @package AcquiaCloudApi\CloudApi
11
 */
12
abstract class CloudApiBase implements CloudApiInterface
13
{
14
15
    /**
16
     * @var ClientInterface The API client.
17
     */
18
    protected $client;
19
20
    /**
21
     * Client constructor.
22
     *
23
     * @param ClientInterface $client
24
     */
25
    public function __construct(ClientInterface $client)
26
    {
27
        $this->client = $client;
28
    }
29
30
    /**
31
     * @param string $link
32
     * @return mixed
33
     */
34
    public function getLinkedResource($link)
35
    {
36
        // Parse only the path part of the URL.
37
        $path = parse_url($link, PHP_URL_PATH);
38
        
39
        // Remove /api from the path as this is already added by the Connector.
40
        $path = substr($path, 4);
41
42
        // Convert the path into an array so we can work out how to handle the response.
43
        $segments = explode('/', rtrim($path));
44
45
        // Get the final array element which we use to determine the response type.
46
        $type = end($segments);
47
48
        switch($type) {
49
            case 'alerts':
50
                return new \AcquiaCloudApi\Response\InsightAlertsResponse(
51
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $alerts of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

51
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
52
                );
53
            break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
54
            case 'applications':
55
                return new \AcquiaCloudApi\Response\ApplicationsResponse(
56
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $applications of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

56
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
57
                );
58
            break;
59
            case 'backups':
60
                return new \AcquiaCloudApi\Response\BackupsResponse(
61
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $backups of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

61
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
62
                );
63
            break;
64
            case 'code':
65
                return new \AcquiaCloudApi\Response\BranchesResponse(
66
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $branches of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

66
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
67
                );
68
            break;
69
            case 'crons':
70
                return new \AcquiaCloudApi\Response\CronsResponse(
71
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $crons of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

71
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
72
                );
73
            break;
74
            case 'databases':
75
                return new \AcquiaCloudApi\Response\DatabasesResponse(
76
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $databases of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

76
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
77
                );
78
            break;
79
            case 'domains':
80
                return new \AcquiaCloudApi\Response\DomainsResponse(
81
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $domains of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

81
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
82
                );
83
            break;
84
            case 'download':
85
            break;
86
            case 'environments':
87
                return new \AcquiaCloudApi\Response\EnvironmentsResponse(
88
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $environments of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

88
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
89
                );
90
            break;
91
            case 'events':
92
            break;
93
            case 'features':
94
            break;
95
            case 'ides':
96
                return new \AcquiaCloudApi\Response\IdesResponse(
97
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $ides of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

97
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
98
                );
99
            break;
100
            case 'insight':
101
                return new \AcquiaCloudApi\Response\InsightsResponse(
102
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $insights of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

102
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
103
                );
104
            break;
105
            case 'logs':
106
                return new \AcquiaCloudApi\Response\LogsResponse(
107
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $logs of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

107
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
108
                );
109
            break;
110
            case 'members':
111
                return new \AcquiaCloudApi\Response\MembersResponse(
112
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $members of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

112
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
113
                );
114
            break;
115
            case 'metrics':
116
                return new \AcquiaCloudApi\Response\MetricsResponse(
117
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $metrics of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

117
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
118
                );
119
            break;
120
            case 'modules':
121
                return new \AcquiaCloudApi\Response\InsightModulesResponse(
122
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $modules of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

122
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
123
                );
124
            break;
125
            case 'permissions':
126
                return new \AcquiaCloudApi\Response\PermissionsResponse(
127
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $permissions of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

127
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
128
                );
129
            break;
130
            case 'servers':return new \AcquiaCloudApi\Response\ServersResponse(
131
                $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $servers of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

131
                /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
132
            );
133
            break;
134
            case 'settings':
135
            break;
136
            case 'ssl':
137
                return new \AcquiaCloudApi\Response\SslCertificatesResponse(
138
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $certificates of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

138
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
139
                );
140
            break;
141
            case 'tasks':
142
            break;
143
            case 'teams':
144
                return new \AcquiaCloudApi\Response\TeamsResponse(
145
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $teams of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

145
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
146
                );
147
            break;
148
            case 'variables':
149
                return new \AcquiaCloudApi\Response\VariablesResponse(
150
                    $this->client->request('get', $path)
0 ignored issues
show
Bug introduced by
It seems like $this->client->request('get', $path) can also be of type AcquiaCloudApi\Connector\StreamInterface; however, parameter $variables of AcquiaCloudApi\Response\...Response::__construct() does only seem to accept array<mixed,object>, maybe add an additional type check? ( Ignorable by Annotation )

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

150
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
151
                );
152
            break;
153
154
        }
155
156
        var_dump(get_defined_vars());
0 ignored issues
show
Security Debugging Code introduced by
var_dump(get_defined_vars()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
157
        throw new \Exception('Not found');
158
    }
159
}
160