GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a561c9...ca8e01 )
by Yong
03:36
created

ClientTrait::getDefaultClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Traits;
4
5
use RuntimeException;
6
use AlibabaCloud\Client\SDK;
7
use AlibabaCloud\Client\AlibabaCloud;
8
use AlibabaCloud\Client\Clients\Client;
9
use AlibabaCloud\Client\Clients\StsClient;
10
use AlibabaCloud\Client\Filter\ClientFilter;
11
use AlibabaCloud\Client\Clients\AccessKeyClient;
12
use AlibabaCloud\Client\Clients\EcsRamRoleClient;
13
use AlibabaCloud\Client\Clients\RamRoleArnClient;
14
use AlibabaCloud\Client\Clients\RsaKeyPairClient;
15
use AlibabaCloud\Client\Clients\BearerTokenClient;
16
use AlibabaCloud\Client\Exception\ClientException;
17
use AlibabaCloud\Client\Signature\SignatureInterface;
18
use AlibabaCloud\Client\Credentials\Ini\IniCredential;
19
use AlibabaCloud\Client\Credentials\CredentialsInterface;
20
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
21
22
/**
23
 * Trait of the manage clients.
24
 *
25
 * @package   AlibabaCloud\Client\Traits
26
 *
27
 * @mixin     AlibabaCloud
28
 */
29
trait ClientTrait
30
{
31
    /**
32
     * @var array Containers of Clients
33
     */
34
    protected static $clients = [];
35
36
    /**
37
     * @param string $clientName
38
     * @param Client $client
39
     *
40
     * @return Client
41
     * @throws ClientException
42
     */
43 117
    public static function set($clientName, Client $client)
44
    {
45 117
        ClientFilter::clientName($clientName);
46
47 115
        return self::$clients[\strtolower($clientName)] = $client;
48
    }
49
50
    /**
51
     * Get all clients.
52
     *
53
     * @return array
54
     */
55 96
    public static function all()
56
    {
57 96
        return self::$clients;
58
    }
59
60
    /**
61
     * Delete the client by specifying name.
62
     *
63
     * @param string $clientName
64
     *
65
     * @throws ClientException
66
     */
67 40
    public static function del($clientName)
68
    {
69 40
        ClientFilter::clientName($clientName);
70
71 38
        unset(self::$clients[\strtolower($clientName)]);
72 38
    }
73
74
    /**
75
     * Delete all clients.
76
     *
77
     * @return void
78
     */
79 25
    public static function flush()
80
    {
81 25
        self::$clients         = [];
82 25
        self::$defaultRegionId = null;
0 ignored issues
show
Bug Best Practice introduced by
The property defaultRegionId does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
83 25
    }
84
85
    /**
86
     * @codeCoverageIgnore
87
     * @deprecated
88
     */
89
    public static function getGlobalClient()
90
    {
91
        throw new RuntimeException('deprecated since 2.0, Use getDefaultClient() instead.');
92
    }
93
94
    /**
95
     * Get the default client.
96
     *
97
     * @return Client
98
     * @throws ClientException
99
     */
100 6
    public static function getDefaultClient()
101
    {
102 6
        return self::get(CredentialsProvider::getDefaultName());
103
    }
104
105
    /**
106
     * Get the Client instance by name.
107
     *
108
     * @param string $clientName
109
     *
110
     * @return Client
111
     * @throws ClientException
112
     */
113 105
    public static function get($clientName)
114
    {
115 105
        ClientFilter::clientName($clientName);
116
117 103
        if (self::has($clientName)) {
118 98
            return self::$clients[\strtolower($clientName)];
119
        }
120
121 6
        throw new ClientException(
122 6
            "Client '$clientName' not found",
123
            SDK::CLIENT_NOT_FOUND
124 6
        );
125
    }
126
127
    /**
128
     * Determine whether there is a client.
129
     *
130
     * @param string $clientName
131
     *
132
     * @return bool
133
     * @throws ClientException
134
     */
135 120
    public static function has($clientName)
136
    {
137 120
        ClientFilter::clientName($clientName);
138
139 118
        return isset(self::$clients[\strtolower($clientName)]);
140
    }
141
142
    /**
143
     * A list of additional files to load.
144
     *
145
     * @return array
146
     * @throws ClientException when a file has a syntax error or does not exist or is not readable
147
     */
148 31
    public static function load()
149
    {
150 31
        if (\func_get_args() === []) {
151 1
            return (new IniCredential())->load();
152
        }
153 30
        $list = [];
154 30
        foreach (\func_get_args() as $filename) {
155 30
            $list[$filename] = (new IniCredential($filename))->load();
156 14
        }
157
158 14
        return $list;
159
    }
160
161
    /**
162
     * Custom Client.
163
     *
164
     * @param CredentialsInterface $credentials
165
     * @param SignatureInterface   $signature
166
     *
167
     * @return Client
168
     */
169 6
    public static function client(CredentialsInterface $credentials, SignatureInterface $signature)
170
    {
171 6
        return new Client($credentials, $signature);
172
    }
173
174
    /**
175
     * Use the AccessKey to complete the authentication.
176
     *
177
     * @param string $accessKeyId
178
     * @param string $accessKeySecret
179
     *
180
     * @return AccessKeyClient
181
     * @throws ClientException
182
     */
183 79
    public static function accessKeyClient($accessKeyId, $accessKeySecret)
184
    {
185 79
        return new AccessKeyClient($accessKeyId, $accessKeySecret);
186
    }
187
188
    /**
189
     * Use the AssumeRole of the RAM account to complete  the authentication.
190
     *
191
     * @param string       $accessKeyId
192
     * @param string       $accessKeySecret
193
     * @param string       $roleArn
194
     * @param string       $roleSessionName
195
     * @param string|array $policy
196
     *
197
     * @return RamRoleArnClient
198
     * @throws ClientException
199
     */
200 9
    public static function ramRoleArnClient($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy = '')
201
    {
202 9
        return new RamRoleArnClient($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName, $policy);
203
    }
204
205
    /**
206
     * Use the RAM role of an ECS instance to complete the authentication.
207
     *
208
     * @param string $roleName
209
     *
210
     * @return EcsRamRoleClient
211
     * @throws ClientException
212
     */
213 13
    public static function ecsRamRoleClient($roleName)
214
    {
215 13
        return new EcsRamRoleClient($roleName);
216
    }
217
218
    /**
219
     * Use the Bearer Token to complete the authentication.
220
     *
221
     * @param string $bearerToken
222
     *
223
     * @return BearerTokenClient
224
     * @throws ClientException
225
     */
226 17
    public static function bearerTokenClient($bearerToken)
227
    {
228 17
        return new BearerTokenClient($bearerToken);
229
    }
230
231
    /**
232
     * Use the STS Token to complete the authentication.
233
     *
234
     * @param string $accessKeyId     Access key ID
235
     * @param string $accessKeySecret Access Key Secret
236
     * @param string $securityToken   Security Token
237
     *
238
     * @return StsClient
239
     * @throws ClientException
240
     */
241 5
    public static function stsClient($accessKeyId, $accessKeySecret, $securityToken = '')
242
    {
243 5
        return new StsClient($accessKeyId, $accessKeySecret, $securityToken);
244
    }
245
246
    /**
247
     * Use the RSA key pair to complete the authentication (supported only on Japanese site)
248
     *
249
     * @param string $publicKeyId
250
     * @param string $privateKeyFile
251
     *
252
     * @return RsaKeyPairClient
253
     * @throws ClientException
254
     */
255 11
    public static function rsaKeyPairClient($publicKeyId, $privateKeyFile)
256
    {
257 11
        return new RsaKeyPairClient($publicKeyId, $privateKeyFile);
258
    }
259
}
260