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 ( ca8e01...1c7c8f )
by Yong
03:46
created

ClientTrait::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Request\Traits;
4
5
use AlibabaCloud\Client\AlibabaCloud;
6
use AlibabaCloud\Client\Clients\Client;
7
use AlibabaCloud\Client\Request\Request;
8
use AlibabaCloud\Client\Credentials\StsCredential;
9
use AlibabaCloud\Client\Exception\ClientException;
10
use AlibabaCloud\Client\Exception\ServerException;
11
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
12
use AlibabaCloud\Client\Credentials\Requests\AssumeRole;
13
use AlibabaCloud\Client\Credentials\CredentialsInterface;
14
use AlibabaCloud\Client\Credentials\BearerTokenCredential;
15
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
16
use AlibabaCloud\Client\Credentials\Requests\GenerateSessionAccessKey;
17
18
/**
19
 * Trait ClientTrait
20
 *
21
 * @package   AlibabaCloud\Client\Request\Traits
22
 *
23
 * @mixin     Request
24
 */
25
trait ClientTrait
26
{
27
    /**
28
     * @var array
29
     */
30
    private static $config = [];
31
32
    /**
33
     * @param array $config
34
     */
35
    public static function config(array $config)
36
    {
37
        self::$config = $config;
38
    }
39
40
    /**
41
     * Return credentials directly if it is an AssumeRole or GenerateSessionAccessKey.
42
     *
43
     * @return AccessKeyCredential|BearerTokenCredential|CredentialsInterface|StsCredential
44
     * @throws ClientException
45
     * @throws ServerException
46
     */
47 75
    public function credential()
48
    {
49 75
        if ($this instanceof AssumeRole || $this instanceof GenerateSessionAccessKey) {
50 13
            return $this->httpClient()->getCredential();
51
        }
52
53 64
        $timeout = isset($this->options['timeout'])
54 64
            ? $this->options['timeout']
55 64
            : Request::TIMEOUT;
56
57 64
        $connectTimeout = isset($this->options['connect_timeout'])
58 64
            ? $this->options['connect_timeout']
59 64
            : Request::CONNECT_TIMEOUT;
60
61 64
        return $this->httpClient()->getSessionCredential($timeout, $connectTimeout);
62
    }
63
64
    /**
65
     * Get the client based on the request's settings.
66
     *
67
     * @return Client
68
     * @throws ClientException
69
     */
70 88
    public function httpClient()
71
    {
72 88
        if (!AlibabaCloud::all()) {
73 4
            if (CredentialsProvider::hasCustomChain()) {
74 2
                CredentialsProvider::customProvider($this->client);
75 2
            } else {
76 2
                CredentialsProvider::defaultProvider($this->client);
77
            }
78 4
        }
79
80 88
        return AlibabaCloud::get($this->client);
81
    }
82
83
    /**
84
     * Merged with the client's options, the same name will be overwritten.
85
     *
86
     * @throws ClientException
87
     */
88 55
    public function mergeOptionsIntoClient()
89
    {
90 55
        $this->options = \AlibabaCloud\Client\arrayMerge(
0 ignored issues
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
91
            [
92 55
                $this->httpClient()->options,
93 55
                $this->options
94 55
            ]
95 55
        );
96 55
    }
97
}
98