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.
Completed
Pull Request — master (#71)
by Yong
06:21
created

ManageTrait::asDefaultClient()   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 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client\Clients;
4
5
use AlibabaCloud\Client\AlibabaCloud;
6
use AlibabaCloud\Client\Credentials\AccessKeyCredential;
7
use AlibabaCloud\Client\Credentials\CredentialsInterface;
8
use AlibabaCloud\Client\Credentials\EcsRamRoleCredential;
9
use AlibabaCloud\Client\Credentials\Providers\CredentialsProvider;
10
use AlibabaCloud\Client\Credentials\Providers\EcsRamRoleProvider;
11
use AlibabaCloud\Client\Credentials\Providers\RamRoleArnProvider;
12
use AlibabaCloud\Client\Credentials\Providers\RsaKeyPairProvider;
13
use AlibabaCloud\Client\Credentials\RamRoleArnCredential;
14
use AlibabaCloud\Client\Credentials\RsaKeyPairCredential;
15
use AlibabaCloud\Client\Credentials\StsCredential;
16
use AlibabaCloud\Client\Exception\ClientException;
17
use AlibabaCloud\Client\Exception\ServerException;
18
19
/**
20
 * Trait ManageTrait.
21
 *
22
 * @mixin     Client
23
 */
24
trait ManageTrait
25
{
26
    /**
27
     * @param int $timeout
28
     *
29
     * @return AccessKeyCredential|CredentialsInterface|StsCredential
30
     *
31
     * @throws ClientException
32
     * @throws ServerException
33 73
     */
34
    public function getSessionCredential($timeout = \ALIBABA_CLOUD_TIMEOUT)
35 73
    {
36 73
        switch (\get_class($this->credential)) {
37 8
            case EcsRamRoleCredential::class:
38 65
                return (new EcsRamRoleProvider($this))->get();
39 7
            case RamRoleArnCredential::class:
40 58
                return (new RamRoleArnProvider($this))->get($timeout);
41 8
            case RsaKeyPairCredential::class:
42 50
                return (new RsaKeyPairProvider($this))->get($timeout);
43 50
            default:
44 50
                return $this->credential;
45
        }
46
    }
47
48
    /**
49
     * Naming clients.
50
     *
51
     * @param string $name
52
     *
53
     * @return static
54 117
     * @throws ClientException
55
     */
56 117
    public function name($name)
57
    {
58
        if (!$name) {
59
            throw new ClientException(
60
                'The argument $name cannot be empty',
61
                \ALIBABA_CLOUD_INVALID_ARGUMENT
62
            );
63
        }
64 31
65
        return AlibabaCloud::set($name, $this);
66 31
    }
67
68
    /**
69
     * @deprecated
70
     * @codeCoverageIgnore
71
     * Set the current client as the global client.
72 29
     *
73
     * @return static
74 29
     * @throws ClientException
75 2
     */
76
    public function asGlobalClient()
77
    {
78 28
        return $this->asDefaultClient();
79
    }
80
81
    /**
82
     * Set the current client as the default client.
83
     *
84
     * @return static
85
     * @throws ClientException
86
     */
87
    public function asDefaultClient()
88
    {
89
        return $this->name(CredentialsProvider::getDefaultName());
90
    }
91
92
    /**
93
     * @return bool
94
     */
95
    public function isDebug()
96
    {
97
        if (isset($this->options['debug'])) {
98
            return true === $this->options['debug'] && PHP_SAPI === 'cli';
99
        }
100
101
        return false;
102
    }
103
}
104