Passed
Pull Request — master (#111)
by Adam
01:56
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
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 array{type:string, path:string} $link
32
     * @return mixed
33
     */
34
    public function getLinkedResource($link)
35
    {
36
        // Remove https://cloud.acquia.com/api from the path as this is already added by the Connector.
37
        $path = substr($link['path'], 28);
38
39
        switch ($link['type']) {
40
            case 'alerts':
41
                return new \AcquiaCloudApi\Response\InsightAlertsResponse(
42
                    $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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

137
                    /** @scrutinizer ignore-type */ $this->client->request('get', $path)
Loading history...
138
                );
139
            break;
140
        }
141
142
        throw new \Exception('Not found');
143
    }
144
}
145