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

CloudApiBase::getLinkedResource()   D

Complexity

Conditions 21
Paths 21

Size

Total Lines 109
Code Lines 83

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 21
eloc 83
nc 21
nop 1
dl 0
loc 109
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
use AcquiaCloudApi\Exception\LinkedResourceNotImplementedException;
7
8
/**
9
 * Class CloudApiBase
10
 *
11
 * @package AcquiaCloudApi\CloudApi
12
 */
13
abstract class CloudApiBase implements CloudApiInterface
14
{
15
16
    /**
17
     * @var ClientInterface The API client.
18
     */
19
    protected $client;
20
21
    /**
22
     * Client constructor.
23
     *
24
     * @param ClientInterface $client
25
     */
26
    public function __construct(ClientInterface $client)
27
    {
28
        $this->client = $client;
29
    }
30
31
    /**
32
     * @param array{type:string, path:string} $link
33
     * @return mixed
34
     * @throws LinkedResourceNotImplementedException
35
     */
36
    public function getLinkedResource($link)
37
    {
38
        // Remove https://cloud.acquia.com/api from the path as this is already added by the Connector.
39
        $path = str_replace('https://cloud.acquia.com/api', '', $link['path']);
40
41
        switch ($link['type']) {
42
            case 'alerts':
43
                return new \AcquiaCloudApi\Response\InsightAlertsResponse(
44
                    $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

44
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
45
                );
46
            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...
47
            case 'applications':
48
                return new \AcquiaCloudApi\Response\ApplicationsResponse(
49
                    $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

49
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
50
                );
51
            break;
52
            case 'backups':
53
                return new \AcquiaCloudApi\Response\BackupsResponse(
54
                    $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

54
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
55
                );
56
            break;
57
            case 'code':
58
                return new \AcquiaCloudApi\Response\BranchesResponse(
59
                    $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

59
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
60
                );
61
            break;
62
            case 'crons':
63
                return new \AcquiaCloudApi\Response\CronsResponse(
64
                    $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

64
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
65
                );
66
            break;
67
            case 'databases':
68
                return new \AcquiaCloudApi\Response\DatabasesResponse(
69
                    $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

69
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
70
                );
71
            break;
72
            case 'domains':
73
                return new \AcquiaCloudApi\Response\DomainsResponse(
74
                    $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

74
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
75
                );
76
            break;
77
            case 'environments':
78
                return new \AcquiaCloudApi\Response\EnvironmentsResponse(
79
                    $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

79
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
80
                );
81
            break;
82
            case 'ides':
83
                return new \AcquiaCloudApi\Response\IdesResponse(
84
                    $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

84
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
85
                );
86
            break;
87
            case 'insight':
88
                return new \AcquiaCloudApi\Response\InsightsResponse(
89
                    $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

89
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
90
                );
91
            break;
92
            case 'logs':
93
                return new \AcquiaCloudApi\Response\LogsResponse(
94
                    $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

94
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
95
                );
96
            break;
97
            case 'members':
98
                return new \AcquiaCloudApi\Response\MembersResponse(
99
                    $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

99
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
100
                );
101
            break;
102
            case 'metrics':
103
                return new \AcquiaCloudApi\Response\MetricsResponse(
104
                    $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

104
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
105
                );
106
            break;
107
            case 'modules':
108
                return new \AcquiaCloudApi\Response\InsightModulesResponse(
109
                    $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

109
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
110
                );
111
            break;
112
            case 'notification':
113
                return new \AcquiaCloudApi\Response\NotificationResponse(
114
                    $this->client->request('get', $path)
115
                );
116
            break;
117
            case 'permissions':
118
                return new \AcquiaCloudApi\Response\PermissionsResponse(
119
                    $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

119
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
120
                );
121
            break;
122
            case 'servers':
123
                return new \AcquiaCloudApi\Response\ServersResponse(
124
                    $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

124
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
125
                );
126
            break;
127
            case 'ssl':
128
                return new \AcquiaCloudApi\Response\SslCertificatesResponse(
129
                    $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

129
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
130
                );
131
            break;
132
            case 'teams':
133
                return new \AcquiaCloudApi\Response\TeamsResponse(
134
                    $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

134
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
135
                );
136
            break;
137
            case 'variables':
138
                return new \AcquiaCloudApi\Response\VariablesResponse(
139
                    $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

139
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
140
                );
141
            break;
142
        }
143
144
        throw new LinkedResourceNotImplementedException($link['type'] . ' link not implemented in this SDK. Please file an issue here: https://github.com/typhonius/acquia-php-sdk-v2/issues');
145
    }
146
}
147